diff options
| author | David Lamparter <equinox@opensourcerouting.org> | 2016-11-18 12:06:57 +0100 |
|---|---|---|
| committer | Quentin Young <qlyoung@users.noreply.github.com> | 2017-05-15 10:27:43 -0400 |
| commit | 16705ecc653dd657c5b8149934d8734e89c27c07 (patch) | |
| tree | 382236b56dcc7542e95d302d031c686ae6618eb7 /lib/command_parse.y | |
| parent | 6a72763d738c7c4132fbc4af03a688a7cc0e49e3 (diff) | |
lib: parser: add named variables in CLI
struct cmd_token now has a "varname" field which is derived from the
DEFUN's string definition. It can be manually specified with "$name"
after some token, e.g. "foo WORD$var". A later commit adds code to
automatically fill the value if nothing is specified.
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'lib/command_parse.y')
| -rw-r--r-- | lib/command_parse.y | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/lib/command_parse.y b/lib/command_parse.y index 0c415af3aa..7e7a68ffdd 100644 --- a/lib/command_parse.y +++ b/lib/command_parse.y @@ -104,12 +104,15 @@ %type <node> start %type <node> literal_token %type <node> placeholder_token +%type <node> placeholder_token_real %type <node> simple_token %type <subgraph> selector %type <subgraph> selector_token %type <subgraph> selector_token_seq %type <subgraph> selector_seq_seq +%type <string> varname_token + %code { /* bison declarations */ @@ -184,6 +187,16 @@ start: } ; +varname_token: '$' WORD +{ + $$ = XSTRDUP (MTYPE_LEX, $2); +} +| /* empty */ +{ + $$ = NULL; +} +; + cmd_token_seq: /* empty */ | cmd_token_seq cmd_token @@ -207,14 +220,16 @@ simple_token: | placeholder_token ; -literal_token: WORD +literal_token: WORD varname_token { $$ = new_token_node (ctx, WORD_TKN, $1, doc_next(ctx)); + cmd_set_varname ($$->data, $2); + XFREE (MTYPE_LEX, $2); XFREE (MTYPE_LEX, $1); } ; -placeholder_token: +placeholder_token_real: IPV4 { $$ = new_token_node (ctx, IPV4_TKN, $1, doc_next(ctx)); @@ -257,10 +272,22 @@ placeholder_token: XFREE (MTYPE_LEX, $1); } +placeholder_token: + placeholder_token_real varname_token +{ + struct cmd_token *token = $$->data; + $$ = $1; + cmd_set_varname (token, $2); + XFREE (MTYPE_LEX, $2); +}; + + /* <selector|set> productions */ -selector: '<' selector_seq_seq '>' +selector: '<' selector_seq_seq '>' varname_token { $$ = $2; + cmd_set_varname ($2.end->data, $4); + XFREE (MTYPE_LEX, $4); }; selector_seq_seq: @@ -283,7 +310,7 @@ selector_seq_seq: ; /* {keyword} productions */ -selector: '{' selector_seq_seq '}' +selector: '{' selector_seq_seq '}' varname_token { $$ = $2; graph_add_edge ($$.end, $$.start); @@ -293,6 +320,9 @@ selector: '{' selector_seq_seq '}' * loop-avoidal fails to handle * just use [{a|b}] if neccessary, that will work perfectly fine, and reason * #1 is good enough to keep it this way. */ + + cmd_set_varname ($2.end->data, $4); + XFREE (MTYPE_LEX, $4); }; @@ -315,10 +345,12 @@ selector_token_seq: ; /* [option] productions */ -selector: '[' selector_seq_seq ']' +selector: '[' selector_seq_seq ']' varname_token { $$ = $2; graph_add_edge ($$.start, $$.end); + cmd_set_varname ($2.end->data, $4); + XFREE (MTYPE_LEX, $4); } ; |
