summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: bf9a824)
raw | patch | inline | side by side (parent: bf9a824)
author | Sebastian Harl <sh@tokkee.org> | |
Sat, 2 Aug 2014 19:51:13 +0000 (21:51 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Sat, 2 Aug 2014 19:51:13 +0000 (21:51 +0200) |
Make LOOKUP MATCHING clauses optional.
src/frontend/grammar.y | patch | blob | history | |
t/unit/frontend/parser_test.c | patch | blob | history |
diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y
index 08d194deeac438290b55dd570356e31d6099a449..a444423b409ce6854190b5d9e9ef7812fe702a5a 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
* 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
index dade011bd31cd2b505382df27fe57903b8f94b6f..1b5cb242e9c94b3bc4c45eb3e4e638f6f5702d44 100644 (file)
{ "LIST;", -1, 1, CONNECTION_LIST },
{ "LIST; INVALID", 5, 1, CONNECTION_LIST },
+ { "LOOKUP hosts", -1, 1, CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
"host = 'host'", -1, 1, CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING NOT "
{ "LIST; INVALID", 8, -1, 0 },
{ "/* some incomplete", -1, -1, 0 },
- { "LOOKUP hosts", -1, -1, 0 },
+ { "LOOKUP foo", -1, -1, 0 },
{ "LOOKUP foo MATCHING "
"host = 'host'", -1, -1, 0 },
+ { "LOOKUP foo FILTER "
+ "host = 'host'", -1, -1, 0 },
+ { "LOOKUP foo MATCHING "
+ "host = 'host' FILTER "
+ "host = 'host'", -1, -1, 0 },
};
size_t i;