/* Set value. */
value_init (&value, width);
- if (!parse_value (lexer, &value, width))
+ if (!parse_value (lexer, &value, vars[0]))
{
value_destroy (&value, width);
return 0;
else
c = case_unshare_and_resize (c, dict_get_proto (d));
- if (!parse_value (lexer, case_data_rw (c, v), var_get_width (v)))
+ if (!parse_value (lexer, case_data_rw (c, v), v))
NOT_REACHED ();
if (!lex_force_match (lexer, T_RPAREN))
}
}
-/* Parses the current token from LEXER into value V, which must
- already have been initialized with the specified WIDTH.
- Returns true if successful, false otherwise. */
+/* Parses the current token from LEXER into value V, which must already have
+ been initialized with the specified VAR's WIDTH. Returns true if
+ successful, false otherwise. */
bool
-parse_value (struct lexer *lexer, union value *v, int width)
+parse_value (struct lexer *lexer, union value *v, const struct variable *var)
{
+ int width = var_get_width (var);
if (width == 0)
- {
- if (!lex_force_num (lexer))
- return false;
- v->f = lex_tokval (lexer);
- }
+ return parse_number (lexer, &v->f, &var_get_print_format (var)->type);
else if (lex_force_string (lexer))
{
const char *s = lex_tokcstr (lexer);
/* PSPP - a program for statistical analysis.
- Copyright (C) 2005, 2009 Free Software Foundation, Inc.
+ Copyright (C) 2005, 2009, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
struct lexer;
enum fmt_type;
+struct variable;
union value;
bool parse_num_range (struct lexer *,
double *x, double *y, const enum fmt_type *fmt);
-bool parse_value (struct lexer *, union value *, int width);
+bool parse_value (struct lexer *, union value *, const struct variable *);
#endif /* value-parser.h */
return false;
value_init (&nst->val1, var_get_width (nst->indep_var));
- if ( ! parse_value (lexer, &nst->val1, var_get_width (nst->indep_var)))
+ if ( ! parse_value (lexer, &nst->val1, nst->indep_var))
{
value_destroy (&nst->val1, var_get_width (nst->indep_var));
return false;
lex_match (lexer, T_COMMA);
value_init (&nst->val2, var_get_width (nst->indep_var));
- if ( ! parse_value (lexer, &nst->val2, var_get_width (nst->indep_var)))
+ if ( ! parse_value (lexer, &nst->val2, nst->indep_var))
{
value_destroy (&nst->val2, var_get_width (nst->indep_var));
return false;
}
value_init (&roc.state_value, var_get_width (roc.state_var));
- parse_value (lexer, &roc.state_value, var_get_width (roc.state_var));
+ parse_value (lexer, &roc.state_value, roc.state_var);
if ( !lex_force_match (lexer, T_RPAREN))
n_values = 0;
else
{
- if (!parse_value (lexer, &proc->g_value[0], width))
+ if (!parse_value (lexer, &proc->g_value[0], proc->indep_var))
return 0;
lex_match (lexer, T_COMMA);
if (lex_match (lexer, T_RPAREN))
n_values = 1;
else
{
- if (!parse_value (lexer, &proc->g_value[1], width)
+ if (!parse_value (lexer, &proc->g_value[1], proc->indep_var)
|| !lex_force_match (lexer, T_RPAREN))
return 0;
n_values = 2;
AT_BANNER([VALUE LABELS])
+AT_SETUP([VALUE LABELS date formats])
+AT_DATA([value-labels.sps], [dnl
+DATA LIST LIST NOTABLE /ad (adate10) dt (datetime20).
+VALUE LABELS ad 'july 10, 1982' 'label 1'
+ '1-2-93' 'label 2'
+ '5-4-2003' 'label 3'
+ /dt '12 Apr 2011 06:09:56' 'label 4'.
+DISPLAY DICTIONARY.
+])
+AT_CHECK([pspp -O format=csv value-labels.sps], [0], [dnl
+Variable,Description,,Position
+ad,Format: ADATE10,,1
+,Measure: Scale,,
+,Display Alignment: Right,,
+,Display Width: 8,,
+,07/10/1982,label 1,
+,01/02/1993,label 2,
+,05/04/2003,label 3,
+dt,Format: DATETIME20.0,,2
+,Measure: Scale,,
+,Display Alignment: Right,,
+,Display Width: 8,,
+,12-APR-2011 06:09:56,label 4,
+])
+AT_CLEANUP
+
dnl Tests for a bug which caused VALUE LABELS to
dnl crash when given invalid syntax.
AT_SETUP([VALUE LABELS invalid syntax bug])