How can I split a rule with Lark EBNF?

179 Views Asked by At

I'm writing a grammar for parsing PlantUML State diagrams and have the following doubt:

I had:

transition: STATE arrow STATE (":" event? guard? action?)? "\n"

arrow: ("->" | "-->" | "-left->" | "-right->" | "-up->" | "-down->")

But had to change to:

transition: STATE ("->" | "-->" | "-left->" | "-right->" | "-up->" | "-down->") STATE (":" event? GUARD? action?)? "\n"

Because, for my application, I don't need nor care which type of arrow is used; it is sufficient to know that an arrow was there to form the transition.

The question is: Is there a way to split the transition rule in other more manageable rules without the arrow type appearing in the parsed tree?

Full file at https://github.com/thomedes/PlantUML-Lark-EBNF. Feel free to comment / criticize. Trying to learn here

1

There are 1 best solutions below

2
On

After RTFM, I've found that terminals whose name begins with underscore are not output to the tree, so I've changed it to:

transition: STATE _ARROW STATE (":" event? GUARD? ACTION?)? "\n"
_ARROW: "->" | "-->" | "-left->" | "-right->" | "-up->" | "-down->"

And now it works fine.

Not marking this as an accepted answer because I'm sure someone with more experience could give a better answer.