Replies: 2 comments 2 replies
-
Option 1Add logic to sort the CST children of Option 2Wrap the $.RULE("expr", () => {
$.MANY(() => {
$.SUBRULE($.foo) // The visitor will only have `foo` sub-children elements **in-order**
})
})
$.RULE("foo", () => {
$.MANY(() => {
$.OR([
{ ALT: () => $.SUBRULE($.a) },
{ ALT: () => $.SUBRULE($.b) },
{ ALT: () => $.SUBRULE($.c) },
{ ALT: () => $.SUBRULE($.d) }
])
})
}) |
Beta Was this translation helpful? Give feedback.
1 reply
-
Thanks @bd82 (and @timneedham) The problem for me is that if there are many subrules (dozens or even hundreds) it gets painful to list them all, as in Option 2 (which I ended up using). So I would prefer the first option, but it was/is not quite clear to me how to implement this... |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm sure this is an obvious question, but if I have a parser rule called
expr
which accepts zero or more ofa
orb
orc
ord
, how can my visitor visit each production in the order it occurred in the input ?grammar:
parser:
visitor:
thanks!
Beta Was this translation helpful? Give feedback.
All reactions