On Fri, Feb 12, 2021 at 01:20:07PM +0100, Florian Westphal wrote: > Phil Sutter <phil@xxxxxx> wrote: > > I didn't find a better way to conditionally parse two following args as > > strings instead of just a single one. Basically I miss an explicit end > > condition from which to call BEGIN(0). > > Yes, thats part of the problem. > > > > Seems we need allow "{" for "*" and then count the {} nests so > > > we can pop off a scanner state stack once we make it back to the > > > same } level that we had at the last state switch. > > > > What is the problem? > > Detect when we need to exit the current start condition. > > We may not even be able to do BEGIN(0) if we have multiple, nested > start conditionals. flex supports start condition stacks, but that > still leaves the exit/closure issue. > > Example: > > table chain { > chain bla { /* should start to recognize rules, but > we did not see 'rule' keyword */ > ip saddr { ... } /* can't exit rule start condition on } ... */ > ip daddr { ... } > } /* should disable rule keywords again */ > > chain dynamic { /* so 'dynamic' is a string here ... */ > } > } > > I don't see a solution, perhaps add dummy bison rule(s) > to explicitly signal closure of e.g. a rule context? You can always push/pop the flexer state from bison code blocks, maybe that's what you mean on "dummy bison rules". Trigger the state from bison and make sure it ends. Something like this: diff --git a/src/parser_bison.y b/src/parser_bison.y index 11e899ff..d8107181 100644 --- a/src/parser_bison.y +++ b/src/parser_bison.y @@ -2397,7 +2397,10 @@ chain_policy : ACCEPT { $$ = NF_ACCEPT; } identifier : STRING ; -string : STRING +string : { yy_push_state(scanner, STRING); } __string { yy_pop_state(scanner); } + ; + +__string : STRING | QUOTED_STRING | ASTERISK_STRING ; -- Bazsi