Code

parser: Let the TIMESERIES command accept optional data-source names.
[sysdb.git] / src / include / parser / parser.h
index 9235ef5820267789cdb77005a6db04dafd602334..a820bbef30a426cceb595224aca547e86ba3643e 100644 (file)
@@ -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"
 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,65 @@ 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:
+ * Semantical analysis of a parse-tree.
+ *
+ * Returns:
+ *  - 0 on success
+ *  - a negative value else; an error message will be written to the provided
+ *    error buffer
+ */
+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.