diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y
index c3ee0af37886d3391d37f0d8fd425a586d0257c1..50bb00e7f632fa35abb283ca7025b0c02a80a908 100644 (file)
--- a/src/frontend/grammar.y
+++ b/src/frontend/grammar.y
%token SCANNER_ERROR
+%token WHERE
+
%token <str> IDENTIFIER STRING
-%token <node> FETCH LIST
+%token <node> FETCH LIST LOOKUP
%type <list> statements
%type <node> statement
fetch_statement
list_statement
+ lookup_statement
expression
%%
|
list_statement
|
+ lookup_statement
+ |
/* empty */
{
$$ = NULL;
}
;
+/*
+ * FETCH <hostname>;
+ *
+ * Retrieve detailed information about a single host.
+ */
fetch_statement:
- FETCH IDENTIFIER
- {
- $$ = SDB_CONN_NODE(sdb_object_create_dT(/* name = */ NULL,
- conn_fetch_t, conn_fetch_destroy));
- CONN_FETCH($$)->name = strdup($2);
- $$->cmd = CONNECTION_FETCH;
- free($2);
- $2 = NULL;
- }
- |
FETCH STRING
{
$$ = SDB_CONN_NODE(sdb_object_create_dT(/* name = */ NULL,
}
;
+/*
+ * LIST;
+ *
+ * Returns a list of all hosts in the store.
+ */
list_statement:
LIST
{
}
;
+/*
+ * LOOKUP <type> WHERE <expression>;
+ *
+ * Returns detailed information about <type> matching expression.
+ */
+lookup_statement:
+ LOOKUP IDENTIFIER WHERE expression
+ {
+ /* 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);
+ YYABORT;
+ }
+
+ $$ = SDB_CONN_NODE(sdb_object_create_dT(/* name = */ NULL,
+ conn_lookup_t, conn_lookup_destroy));
+ CONN_LOOKUP($$)->matcher = CONN_MATCHER($4);
+ $$->cmd = CONNECTION_LOOKUP;
+ free($2);
+ $2 = NULL;
+ }
+ ;
+
expression:
- IDENTIFIER
+ STRING
{
$$ = SDB_CONN_NODE(sdb_object_create_T(/* name = */ NULL,
conn_node_matcher_t));