#include "libpspp/str.h"
#include "libpspp/stringi-set.h"
+#include "math/interaction.h"
+
#include "gl/c-ctype.h"
#include "gl/xalloc.h"
return vs;
}
+
+/* Match a variable.
+ If the match succeeds, the variable will be placed in VAR.
+ Returns true if successful */
+bool
+lex_match_variable (struct lexer *lexer, const struct dictionary *dict, const struct variable **var)
+{
+ if (lex_token (lexer) != T_ID)
+ return false;
+
+ *var = parse_variable_const (lexer, dict);
+
+ if ( *var == NULL)
+ return false;
+ return true;
+}
+
+/* An interaction is a variable followed by {*, BY} followed by an interaction */
+bool
+parse_design_interaction (struct lexer *lexer, const struct dictionary *dict, struct interaction **iact)
+{
+ const struct variable *v = NULL;
+ assert (iact);
+
+ switch (lex_next_token (lexer, 1))
+ {
+ case T_ENDCMD:
+ case T_SLASH:
+ case T_COMMA:
+ case T_ID:
+ case T_BY:
+ case T_ASTERISK:
+ break;
+ default:
+ return false;
+ break;
+ }
+
+ if (! lex_match_variable (lexer, dict, &v))
+ {
+ interaction_destroy (*iact);
+ *iact = NULL;
+ return false;
+ }
+
+ assert (v);
+
+ if ( *iact == NULL)
+ *iact = interaction_create (v);
+ else
+ interaction_add_variable (*iact, v);
+
+ if ( lex_match (lexer, T_ASTERISK) || lex_match (lexer, T_BY))
+ {
+ return parse_design_interaction (lexer, dict, iact);
+ }
+
+ return true;
+}
+
var_set_destroy ( (struct var_set *) vs);
}
+/* Match a variable.
+ If the match succeeds, the variable will be placed in VAR.
+ Returns true if successful */
+bool
+lex_match_variable (struct lexer *lexer, const struct dictionary *dict, const struct variable **var);
+
+struct interaction;
+
+/* Parse an interaction.
+ If not successfull return false.
+ Otherwise, a newly created interaction will be placed in IACT.
+ It is the caller's responsibility to destroy this interaction.
+ */
+bool
+parse_design_interaction (struct lexer *lexer, const struct dictionary *dict, struct interaction **iact);
+
+
#endif /* variable-parser.h */
tab_submit (t);
}
-
-/* Match a variable.
- If the match succeeds, the variable will be placed in VAR.
- Returns true if successful */
-static bool
-lex_match_variable (struct lexer *lexer,
- const struct dictionary *dict, const struct variable **var)
-{
- if (lex_token (lexer) != T_ID)
-
- return false;
-
- *var = parse_variable_const (lexer, dict);
-
- if ( *var == NULL)
- return false;
- return true;
-}
-
/* Attempt to parse an interaction from LEXER */
static struct interaction *
parse_interaction (struct lexer *lexer, struct examine *ex)
\f
-
-/* Match a variable.
- If the match succeeds, the variable will be placed in VAR.
- Returns true if successful */
-static bool
-lex_match_variable (struct lexer *lexer, const struct dictionary *dict, const struct variable **var)
-{
- if (lex_token (lexer) != T_ID)
- return false;
-
- *var = parse_variable_const (lexer, dict);
-
- if ( *var == NULL)
- return false;
- return true;
-}
-
-/* An interaction is a variable followed by {*, BY} followed by an interaction */
-static bool
-parse_design_interaction (struct lexer *lexer, const struct dictionary *dict, struct interaction **iact)
-{
- const struct variable *v = NULL;
- assert (iact);
-
- switch (lex_next_token (lexer, 1))
- {
- case T_ENDCMD:
- case T_SLASH:
- case T_COMMA:
- case T_ID:
- case T_BY:
- case T_ASTERISK:
- break;
- default:
- return false;
- break;
- }
-
- if (! lex_match_variable (lexer, dict, &v))
- {
- interaction_destroy (*iact);
- *iact = NULL;
- return false;
- }
-
- assert (v);
-
- if ( *iact == NULL)
- *iact = interaction_create (v);
- else
- interaction_add_variable (*iact, v);
-
- if ( lex_match (lexer, T_ASTERISK) || lex_match (lexer, T_BY))
- {
- return parse_design_interaction (lexer, dict, iact);
- }
-
- return true;
-}
-
static bool
parse_nested_variable (struct lexer *lexer, struct glm_spec *glm)
{