1

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 Answers1

1

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.

  • 1
    That's a good way to do it. You can allow make `_arrow` a rule (instead of terminal) with a similar effect. – Erez Feb 10 '21 at 13:59
  • 1
    You're courageous. There are also `<-dow-` and `<-righ-` possibilities. I think the PlantUML interpreter uses lots of regex, so a grammar will be tough to pull off. See [this](http://www.plantuml.com/plantuml/uml/Aov9B4bLSEI2q4vSZWeskYdvvNcwGBQJWcvHfgwTWZEN2r0q1oW40000) – Fuhrmanator Aug 24 '22 at 02:19