-
Is there a way to restrict matching in the following case: struct param_a : seq< istring<'a','='>, digit > {};
struct param_b : seq< istring<'b','='>, alpha > {};
struct param_other : seq< alpha, one<'='>, alnum > {};
struct params : sor< param_a, param_b, param_other > {}; Namely, I don't want grammar to accept neither 'a=c' nor 'b=3' but the last choice allows it. Please note that this is simplified example and in reality there's about 10 choices with lengthy name part (instead of 'a' and 'b'). Therefore it's really hard and clumsy to exclude in param_other case all previous cases. I wonder if there's more elegant way to restrict the rule? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
What we usually do in this situation is to use |
Beta Was this translation helpful? Give feedback.
-
You could use nested
which is strangely formatted when it comes to nesting and which leaves the question of where to attach the actions. But from a pure parsing POV, it will do exactly what you need. I think we could also easily build a better interface, maybe a "sequenced switch" with an interface like
and maybe allow specializing on |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot! If-then-else looks fine to me, and I hope actions can be attached to digit and alpha since their values are all what's needed. |
Beta Was this translation helpful? Give feedback.
-
You could attach actions to struct intro_a : istring<'a','='> {};
struct value_a : digit {};
struct intro_b : istring<'b','='> {};
struct value_b : alpha {};
struct other : seq< alpha, one<'='>, alnum > {};
struct params : if_then_else< intro_a, value_a,
if_then_else< intro_b, value_b,
other > > {}; Then just attach actions to Also: Phew! Good to know I'm not the only one who prefers minimalistic interfaces :) |
Beta Was this translation helpful? Give feedback.
You could use nested
if_then_else
rules, e.g.which is strangely formatted when it comes to nesting and which leaves the question of where to attach the actions. But from a pure parsing POV, it will do exactly what you need.
I think we could also easily build a better interface, maybe a "sequenced switch" with an interface like
and maybe allow specializing on
sswitch_case<istring<'a','='>>
for the actions and passing the whole matching input of the case. @ColinH What do you think?