Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
422 views
in Technique[技术] by (71.8m points)

plantuml - How can I split a rule with Lark EBNF?

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

I had:

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

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

But had to change to:

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

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 ??

question from:https://stackoverflow.com/questions/65872693/how-can-i-split-a-rule-with-lark-ebnf

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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?)? "
"
_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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...