From 90c8406c209a698ecc28c80ad7ebced13a84e3e8 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Thu, 26 Aug 2021 11:43:08 +0200 Subject: lib: add `![...]` syntax for easy "no" forms This allows defining a CLI command like this: `[no] some setting ![VALUE]` with VALUE being optional for the "no" form, but required for the positive form. It's just a `[...]` where the empty branch can only be taken for commands starting with `no`. Signed-off-by: David Lamparter --- lib/command_parse.y | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib/command_parse.y') diff --git a/lib/command_parse.y b/lib/command_parse.y index f5e42cc304..3e2cdc79af 100644 --- a/lib/command_parse.y +++ b/lib/command_parse.y @@ -105,6 +105,9 @@ %token MAC %token MAC_PREFIX +/* special syntax, value is irrelevant */ +%token EXCL_BRACKET + /* union types for parsed rules */ %type start %type literal_token @@ -372,6 +375,19 @@ selector: '[' selector_seq_seq ']' varname_token } ; +/* ![option] productions */ +selector: EXCL_BRACKET selector_seq_seq ']' varname_token +{ + struct graph_node *neg_only = new_token_node (ctx, NEG_ONLY_TKN, NULL, NULL); + + $$ = $2; + graph_add_edge ($$.start, neg_only); + graph_add_edge (neg_only, $$.end); + cmd_token_varname_set ($2.end->data, $4); + XFREE (MTYPE_LEX, $4); +} +; + %% #undef scanner -- cgit v1.2.3