Code

frontend: Let sdb_fe_parse() return a list of parsed node objects.
[sysdb.git] / src / frontend / grammar.y
index ef88272d6b237f9885ca30761891ca3e00ab9437..876f48a04a2d718864020473304e30d34ca0848a 100644 (file)
 
 %{
 
+#include "frontend/connection.h"
 #include "frontend/parser.h"
 #include "frontend/grammar.h"
+
 #include "utils/error.h"
+#include "utils/llist.h"
 
 #include <stdio.h>
 
+sdb_fe_yyextra_t *
+sdb_fe_yyget_extra(sdb_fe_yyscan_t scanner);
+
 void
 sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg);
 
+/* quick access to the current parse tree */
+#define pt sdb_fe_yyget_extra(scanner)->parsetree
+
 %}
 
 %pure-parser
@@ -46,35 +55,57 @@ sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg);
 %expect 0
 %name-prefix="sdb_fe_yy"
 
+%union {
+       sdb_llist_t     *list;
+       sdb_conn_node_t *node;
+}
+
 %start statements
 
 %token SCANNER_ERROR
 
 %token IDENTIFIER
-%token LIST
+%token <node> LIST
+
+%type <list> statements
+%type <node> statement
+       list_statement
 
 %%
 
 statements:
        statements ';' statement
                {
+                       if ($3) {
+                               sdb_llist_append(pt, SDB_OBJ($3));
+                               sdb_object_deref(SDB_OBJ($3));
+                       }
                }
        |
        statement
                {
+                       if ($1) {
+                               sdb_llist_append(pt, SDB_OBJ($1));
+                               sdb_object_deref(SDB_OBJ($1));
+                       }
                }
        ;
 
 statement:
        list_statement
-               {
-               }
        |
        /* empty */
+               {
+                       $$ = NULL;
+               }
        ;
 
 list_statement:
        LIST
+               {
+                       $$ = sdb_object_create_T(/* name = */ NULL, sdb_conn_node_t);
+                       ((sdb_conn_node_t *)$$)->cmd = CONNECTION_LIST;
+               }
        ;
 
 %%