diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y
index 92bfd1f5c60d2ab24d5e0b6f82b90e7e4ce73c71..a2ae448cc744166875afd8e0f4904b5a186ad5cf 100644 (file)
--- a/src/frontend/grammar.y
+++ b/src/frontend/grammar.y
fetch_statement
list_statement
lookup_statement
+ matching_clause
+ filter_clause
condition
%type <m> matcher
* Retrieve detailed information about a single host.
*/
fetch_statement:
- FETCH STRING
+ FETCH STRING filter_clause
{
$$ = SDB_CONN_NODE(sdb_object_create_dT(/* name = */ NULL,
conn_fetch_t, conn_fetch_destroy));
CONN_FETCH($$)->name = strdup($2);
+ CONN_FETCH($$)->filter = CONN_MATCHER($3);
$$->cmd = CONNECTION_FETCH;
free($2); $2 = NULL;
}
* Returns a list of all hosts in the store.
*/
list_statement:
- LIST
+ LIST filter_clause
{
- $$ = SDB_CONN_NODE(sdb_object_create_T(/* name = */ NULL,
- sdb_conn_node_t));
+ $$ = SDB_CONN_NODE(sdb_object_create_dT(/* name = */ NULL,
+ conn_list_t, conn_list_destroy));
+ CONN_LIST($$)->filter = CONN_MATCHER($2);
$$->cmd = CONNECTION_LIST;
}
;
* Returns detailed information about <type> matching condition.
*/
lookup_statement:
- LOOKUP IDENTIFIER MATCHING condition
+ LOOKUP IDENTIFIER matching_clause filter_clause
{
/* TODO: support other types as well */
if (strcasecmp($2, "hosts")) {
char errmsg[strlen($2) + 32];
snprintf(errmsg, sizeof(errmsg),
- YY_("unknown table %s"), $2);
+ YY_("unknown data-source %s"), $2);
sdb_fe_yyerror(&yylloc, scanner, errmsg);
free($2); $2 = NULL;
+ sdb_object_deref(SDB_OBJ($3));
sdb_object_deref(SDB_OBJ($4));
YYABORT;
}
$$ = SDB_CONN_NODE(sdb_object_create_dT(/* name = */ NULL,
conn_lookup_t, conn_lookup_destroy));
- CONN_LOOKUP($$)->matcher = CONN_MATCHER($4);
+ CONN_LOOKUP($$)->matcher = CONN_MATCHER($3);
+ CONN_LOOKUP($$)->filter = CONN_MATCHER($4);
$$->cmd = CONNECTION_LOOKUP;
free($2); $2 = NULL;
}
+ ;
+
+matching_clause:
+ MATCHING condition { $$ = $2; }
|
- LOOKUP IDENTIFIER MATCHING condition FILTER condition
- {
- /* TODO: support other types as well */
- if (strcasecmp($2, "hosts")) {
- char errmsg[strlen($2) + 32];
- snprintf(errmsg, sizeof(errmsg),
- YY_("unknown table %s"), $2);
- sdb_fe_yyerror(&yylloc, scanner, errmsg);
- free($2); $2 = NULL;
- sdb_object_deref(SDB_OBJ($4));
- YYABORT;
- }
+ /* empty */ { $$ = NULL; }
- $$ = SDB_CONN_NODE(sdb_object_create_dT(/* name = */ NULL,
- conn_lookup_t, conn_lookup_destroy));
- CONN_LOOKUP($$)->matcher = CONN_MATCHER($4);
- CONN_LOOKUP($$)->filter = CONN_MATCHER($6);
- $$->cmd = CONNECTION_LOOKUP;
- free($2); $2 = NULL;
- }
- ;
+filter_clause:
+ FILTER condition { $$ = $2; }
+ |
+ /* empty */ { $$ = NULL; }
+
+/*
+ * Basic expressions.
+ */
condition:
matcher
sdb_object_deref(SDB_OBJ($3)); $3 = NULL;
}
|
+ ':' IDENTIFIER
+ {
+ int field = sdb_store_parse_field_name($2);
+ free($2); $2 = NULL;
+ $$ = sdb_store_expr_fieldvalue(field);
+ }
+ |
data
{
$$ = sdb_store_expr_constvalue(&$1);