]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: parser: remove startnode & sentence_root 6/head
authorDavid Lamparter <equinox@opensourcerouting.org>
Wed, 23 Nov 2016 18:20:15 +0000 (19:20 +0100)
committerDavid Lamparter <equinox@opensourcerouting.org>
Fri, 16 Dec 2016 19:48:31 +0000 (20:48 +0100)
This removes an artificial restriction for the first token in a
command's graph to be a WORD_TKN.  The intention seems to be to prohibit
empty paths through a command, and to restrict "explosion" of choices in
the root node.

The better approach to the former is to check for an empty path after
the definition is parsed.  The latter will happen anyway, by duplication
of the command, which just makes it worse...

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
lib/command_parse.y

index 43062eb5da97781cab79d05715e39bf1c112975d..c920e11380cdfa0bf118d7ed15aa975d8f3ebfb6 100644 (file)
@@ -73,7 +73,7 @@
     struct cmd_element *el;
 
     struct graph *graph;
-    struct graph_node *currnode, *startnode;
+    struct graph_node *currnode;
 
     /* pointers to copy of command docstring */
     char *docstr_start, *docstr;
@@ -91,7 +91,6 @@
 
 /* union types for parsed rules */
 %type <node> start
-%type <node> sentence_root
 %type <node> literal_token
 %type <node> placeholder_token
 %type <node> simple_token
 /* called automatically before yyparse */
 %initial-action {
   /* clear state pointers */
-  ctx->currnode = ctx->startnode = NULL;
-
-  ctx->startnode = vector_slot (ctx->graph->nodes, 0);
+  ctx->currnode = vector_slot (ctx->graph->nodes, 0);
 
   /* copy docstring and keep a pointer to the copy */
   if (ctx->el->doc)
 %%
 
 start:
-  sentence_root cmd_token_seq
+  cmd_token_seq
 {
   // tack on the command element
   terminate_graph (ctx, ctx->currnode);
 }
-| sentence_root cmd_token_seq placeholder_token '.' '.' '.'
+| cmd_token_seq placeholder_token '.' '.' '.'
 {
-  if ((ctx->currnode = add_edge_dedup (ctx->currnode, $3)) != $3)
-    graph_delete_node (ctx->graph, $3);
+  if ((ctx->currnode = add_edge_dedup (ctx->currnode, $2)) != $2)
+    graph_delete_node (ctx->graph, $2);
 
   ((struct cmd_token *)ctx->currnode->data)->allowrepeat = 1;
 
@@ -194,19 +191,6 @@ start:
 }
 ;
 
-sentence_root: WORD
-{
-  struct graph_node *root =
-    new_token_node (ctx, WORD_TKN, strdup ($1), doc_next(ctx));
-
-  if ((ctx->currnode = add_edge_dedup (ctx->startnode, root)) != root)
-    graph_delete_node (ctx->graph, root);
-
-  free ($1);
-  $$ = ctx->currnode;
-}
-;
-
 cmd_token_seq:
   /* empty */
 | cmd_token_seq cmd_token