Skip to content

Commit

Permalink
Merge pull request #6 from opensourcerouting/dev/osr/vty_pending
Browse files Browse the repository at this point in the history
parser: accept non-words as first tokens & numbers as word tokens
  • Loading branch information
donaldsharp authored Dec 16, 2016
2 parents bcfb39a + fd19e7a commit 6cc1ba0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 23 deletions.
2 changes: 1 addition & 1 deletion lib/command_lex.l
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "command_parse.h"
%}

WORD (\-|\+)?[a-z\*][-+_a-zA-Z0-9\*]*
WORD (\-|\+)?[a-z0-9\*][-+_a-zA-Z0-9\*]*
IPV4 A\.B\.C\.D
IPV4_PREFIX A\.B\.C\.D\/M
IPV6 X:X::X:X
Expand Down
28 changes: 6 additions & 22 deletions lib/command_parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -151,9 +150,7 @@
/* 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)
Expand All @@ -173,15 +170,15 @@
%%

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;

Expand All @@ -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
Expand Down

0 comments on commit 6cc1ba0

Please sign in to comment.