diff options
| author | David Lamparter <equinox@opensourcerouting.org> | 2016-11-18 15:56:18 +0100 | 
|---|---|---|
| committer | David Lamparter <equinox@opensourcerouting.org> | 2016-12-15 23:13:52 +0100 | 
| commit | 7d5718c140611ae125dfab56b94f6a96e19b5922 (patch) | |
| tree | 76b5d634724313564e078600818bd66f132c66a7 /lib/command_parse.y | |
| parent | fa133e00c2103ffcacbf3a20d0c1a7a1a86d63ab (diff) | |
lib: parser: support keyword arguments
This re-adds "{foo WORD|bar WORD}" keyword-argument support to the CLI
parser.  Note that token graphs may now contain loops for this purpose;
therefore the matching functions retain a history of already-matched
tokens.  Each token can thus only be consumed once.
And then LINE... gets its special treatment with allowrepeat.
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'lib/command_parse.y')
| -rw-r--r-- | lib/command_parse.y | 22 | 
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/command_parse.y b/lib/command_parse.y index 339e6be8f9..3dba8f0e89 100644 --- a/lib/command_parse.y +++ b/lib/command_parse.y @@ -180,6 +180,8 @@ start:    if ((ctx->currnode = add_edge_dedup (ctx->currnode, $3)) != $3)      graph_delete_node (ctx->graph, $3); +  ctx->currnode->allowrepeat = 1; +    // adding a node as a child of itself accepts any number    // of the same token, which is what we want for variadics    add_edge_dedup (ctx->currnode, ctx->currnode); @@ -336,6 +338,26 @@ selector_seq_seq:  }  ; +/* {keyword} productions */ +selector: '{' selector_seq_seq '}' +{ +  $$ = malloc (sizeof (struct subgraph)); +  $$->start = new_token_node (ctx, SELECTOR_TKN, NULL, NULL); +  $$->end   = new_token_node (ctx, NUL_TKN, NULL, NULL); +  graph_add_edge ($$->start, $$->end); +  for (unsigned int i = 0; i < vector_active ($2->start->to); i++) +  { +    struct graph_node *sn = vector_slot ($2->start->to, i), +                      *en = vector_slot ($2->end->from, i); +    graph_add_edge ($$->start, sn); +    graph_add_edge (en, $$->start); +  } +  graph_delete_node (ctx->graph, $2->start); +  graph_delete_node (ctx->graph, $2->end); +  free ($2); +}; + +  selector_token_seq:    simple_token  {  | 
