X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=blobdiff_plain;f=src%2Finclude%2Fparser%2Fparser.h;h=a820bbef30a426cceb595224aca547e86ba3643e;hp=0a7c7206d24a156bb1706003641fadc217076f84;hb=HEAD;hpb=1ea57919cda96d83e7625999019269dffefdb329 diff --git a/src/include/parser/parser.h b/src/include/parser/parser.h index 0a7c720..a820bbe 100644 --- a/src/include/parser/parser.h +++ b/src/include/parser/parser.h @@ -28,9 +28,6 @@ #ifndef SDB_PARSER_PARSER_H #define SDB_PARSER_PARSER_H 1 -/* TODO: move SDB_PARSE_* constants here as well */ -#include "frontend/parser.h" - #include "core/store.h" #include "parser/ast.h" #include "utils/llist.h" @@ -40,6 +37,18 @@ extern "C" { #endif +/* parser modes */ +enum { + /* parser accepts any command statement */ + SDB_PARSE_DEFAULT = 0, + + /* parser accepts any conditional statement */ + SDB_PARSE_COND = 1 << 1, + + /* parser accepts any arithmetic expression */ + SDB_PARSE_ARITH = 1 << 2, +}; + /* * sdb_parser_parse: * Parse the specified query of the specified length. If len is a negative @@ -56,21 +65,25 @@ sdb_parser_parse(const char *query, int len, sdb_strbuf_t *errbuf); /* * sdb_parser_parse_conditional: - * Parse a single conditional expression. This function is similar to - * sdb_parse_parse but will only accept a single conditional expression. The - * return value is guaranteed to satisfy SDB_AST_IS_LOGICAL(). + * Parse a single conditional expression which can be evaluated in the + * specified context (any valid store object type). This function is similar + * to sdb_parse_parse but will only accept a single conditional expression. + * The return value is guaranteed to satisfy SDB_AST_IS_LOGICAL(). */ sdb_ast_node_t * -sdb_parser_parse_conditional(const char *cond, int len, sdb_strbuf_t *errbuf); +sdb_parser_parse_conditional(int context, + const char *cond, int len, sdb_strbuf_t *errbuf); /* * sdb_parser_parse_arith: - * Parse a single arithmetic expression. This function is similar to - * sdb_parse_parse but will only accept a single arithmetic expression. The + * Parse a single arithmetic expression which can be evaluated in the + * specified context (any valid store object type). This function is similar + * to sdb_parse_parse but will only accept a single arithmetic expression. The * return value is guaranteed to satisfy SDB_AST_IS_ARITHMETIC(). */ sdb_ast_node_t * -sdb_parser_parse_arith(const char *expr, int len, sdb_strbuf_t *errbuf); +sdb_parser_parse_arith(int context, + const char *expr, int len, sdb_strbuf_t *errbuf); /* * sdb_parser_analyze: @@ -84,6 +97,34 @@ sdb_parser_parse_arith(const char *expr, int len, sdb_strbuf_t *errbuf); int sdb_parser_analyze(sdb_ast_node_t *node, sdb_strbuf_t *errbuf); +/* + * sdb_parser_analyze_conditional: + * Semantical analysis of a conditional node in the specified context (any + * valid store object type). + * + * Returns: + * - 0 on success + * - a negative value else; an error message will be written to the provided + * error buffer + */ +int +sdb_parser_analyze_conditional(int context, + sdb_ast_node_t *node, sdb_strbuf_t *errbuf); + +/* + * sdb_parser_analyze_arith: + * Semantical analysis of an arithmetic node in the specified context (any + * valid store object type). + * + * Returns: + * - 0 on success + * - a negative value else; an error message will be written to the provided + * error buffer + */ +int +sdb_parser_analyze_arith(int context, + sdb_ast_node_t *node, sdb_strbuf_t *errbuf); + /* * Low-level interface. */