Flattening recursive lists in Grammar Kit: private, inner, upper, left
Answered
I have a grammar that looks like the following
rule ::= item (SEP rule?)
I would like to flatten it out so a rule is a list, is it possible to do so with inner, upper, or private modifiers? Or, should I hand-roll methods to access the grammar like a list?
Also, what does private mean with respect to precedence? I'd like to use it to flatten the hierarchy but worried it would change the order of evaluation and bork the grammar on something like this
ySegmentExclNat ::= ySegmentMulti | containedSegment | YNAME
Where multi must be evaluated first
here's a link to the grammar: https://github.com/kieda/yapping-intellij/blob/main/src/main/java/io/hostilerobot/yapping/parser/grammar/Yapping.bnf
Please sign in to leave a comment.
Hi,
I'm not sure about the meaning of:
Did you mean:
If so, why do you want to use recursion here? Why not using:
You will have a flat list in this case.
The
private
modifier doesn't change the precedence. If it is used, then the AST won't include a node for this rule, but directly the children.Hey!
Yep - misplaced comma. It turns out using private works and does not change the precedence/priority. I need the recursive property for more advanced constructs that may begin with other constructs, like
This was remediated and flattened using
I had reservations about private, as this doc seems to imply that private is used to define statements of the same priority. However it's probably more of a best practice rather than something that actually changes the functionality