X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=blobdiff_plain;f=src%2Fparser%2Fgrammar.y;h=61891888d18423823141f4086bdb70e80ac55cfa;hp=801462617755d305739e4ef28ac237dd8ce4d5cd;hb=HEAD;hpb=85fa98410c3ef44c2b4ce4e5b2902a70b5932689 diff --git a/src/parser/grammar.y b/src/parser/grammar.y index 8014626..6189188 100644 --- a/src/parser/grammar.y +++ b/src/parser/grammar.y @@ -104,7 +104,7 @@ sdb_parser_yyerrorf(YYLTYPE *lval, sdb_parser_yyscan_t scanner, const char *fmt, sdb_llist_t *list; sdb_ast_node_t *node; - struct { char *type; char *id; } metric_store; + struct { char *type; char *id; sdb_time_t last_update; } metric_store; } %start statements @@ -127,6 +127,8 @@ sdb_parser_yyerrorf(YYLTYPE *lval, sdb_parser_yyscan_t scanner, const char *fmt, /* NULL token */ %token NULL_T +%token TRUE FALSE + %token FETCH LIST LOOKUP STORE TIMESERIES %token IDENTIFIER STRING @@ -279,13 +281,13 @@ statement: fetch_statement: FETCH object_type STRING filter_clause { - $$ = sdb_ast_fetch_create($2, NULL, $3, $4); + $$ = sdb_ast_fetch_create($2, NULL, -1, NULL, $3, 1, $4); CK_OOM($$); } | FETCH object_type STRING '.' STRING filter_clause { - $$ = sdb_ast_fetch_create($2, $3, $5, $6); + $$ = sdb_ast_fetch_create($2, $3, -1, NULL, $5, 1, $6); CK_OOM($$); } ; @@ -337,42 +339,42 @@ store_statement: STORE HOST_T STRING last_update_clause { $$ = sdb_ast_store_create(SDB_HOST, NULL, 0, NULL, - $3, $4, NULL, NULL, SDB_DATA_NULL); + $3, $4, NULL, NULL, 0, SDB_DATA_NULL); CK_OOM($$); } | STORE SERVICE_T STRING '.' STRING last_update_clause { $$ = sdb_ast_store_create(SDB_SERVICE, $3, 0, NULL, - $5, $6, NULL, NULL, SDB_DATA_NULL); + $5, $6, NULL, NULL, 0, SDB_DATA_NULL); CK_OOM($$); } | STORE METRIC_T STRING '.' STRING metric_store_clause last_update_clause { $$ = sdb_ast_store_create(SDB_METRIC, $3, 0, NULL, - $5, $7, $6.type, $6.id, SDB_DATA_NULL); + $5, $7, $6.type, $6.id, $6.last_update, SDB_DATA_NULL); CK_OOM($$); } | STORE HOST_T ATTRIBUTE_T STRING '.' STRING data last_update_clause { $$ = sdb_ast_store_create(SDB_ATTRIBUTE, $4, 0, NULL, - $6, $8, NULL, NULL, $7); + $6, $8, NULL, NULL, 0, $7); CK_OOM($$); } | STORE SERVICE_T ATTRIBUTE_T STRING '.' STRING '.' STRING data last_update_clause { $$ = sdb_ast_store_create(SDB_ATTRIBUTE, $4, SDB_SERVICE, $6, - $8, $10, NULL, NULL, $9); + $8, $10, NULL, NULL, 0, $9); CK_OOM($$); } | STORE METRIC_T ATTRIBUTE_T STRING '.' STRING '.' STRING data last_update_clause { $$ = sdb_ast_store_create(SDB_ATTRIBUTE, $4, SDB_METRIC, $6, - $8, $10, NULL, NULL, $9); + $8, $10, NULL, NULL, 0, $9); CK_OOM($$); } ; @@ -383,19 +385,43 @@ last_update_clause: /* empty */ { $$ = sdb_gettime(); } metric_store_clause: - STORE STRING STRING { $$.type = $2; $$.id = $3; } + STORE STRING STRING datetime { $$.type = $2; $$.id = $3; $$.last_update = $4; } + | + STORE STRING STRING { $$.type = $2; $$.id = $3; $$.last_update = 0; } | - /* empty */ { $$.type = $$.id = NULL; } + /* empty */ { $$.type = $$.id = NULL; $$.last_update = 0; } /* - * TIMESERIES . [START ] [END ]; + * TIMESERIES .[...] [START ] [END ]; * * Returns a time-series for the specified host's metric. */ timeseries_statement: TIMESERIES STRING '.' STRING start_clause end_clause { - $$ = sdb_ast_timeseries_create($2, $4, $5, $6); + $$ = sdb_ast_timeseries_create($2, $4, NULL, 0, $5, $6); + CK_OOM($$); + } + | + TIMESERIES STRING '.' STRING array start_clause end_clause + { + char **ds; + size_t ds_num; + + if ($5.type != (SDB_TYPE_ARRAY | SDB_TYPE_STRING)) { + sdb_parser_yyerrorf(&yylloc, scanner, YY_("syntax error, " + "unexpected array of type %s; expected STRING"), + SDB_TYPE_TO_STRING($5.type)); + sdb_data_free_datum(&$5); + free($2); + free($4); + YYABORT; + } + + ds = $5.data.array.values; + ds_num = $5.data.array.length; + + $$ = sdb_ast_timeseries_create($2, $4, ds, ds_num, $6, $7); CK_OOM($$); } ; @@ -481,6 +507,34 @@ comparison: CK_OOM($$); } | + expression IS TRUE + { + $$ = sdb_ast_op_create(SDB_AST_ISTRUE, NULL, $1); + CK_OOM($$); + } + | + expression IS NOT TRUE + { + $$ = sdb_ast_op_create(SDB_AST_ISTRUE, NULL, $1); + CK_OOM($$); + $$ = sdb_ast_op_create(SDB_AST_NOT, NULL, $$); + CK_OOM($$); + } + | + expression IS FALSE + { + $$ = sdb_ast_op_create(SDB_AST_ISFALSE, NULL, $1); + CK_OOM($$); + } + | + expression IS NOT FALSE + { + $$ = sdb_ast_op_create(SDB_AST_ISFALSE, NULL, $1); + CK_OOM($$); + $$ = sdb_ast_op_create(SDB_AST_NOT, NULL, $$); + CK_OOM($$); + } + | expression IN expression { $$ = sdb_ast_op_create(SDB_AST_IN, $1, $3); @@ -604,6 +658,8 @@ field: BACKEND_T { $$ = SDB_FIELD_BACKEND; } | VALUE_T { $$ = SDB_FIELD_VALUE; } + | + TIMESERIES { $$ = SDB_FIELD_TIMESERIES; } ; cmp: