Replies: 3 comments 1 reply
-
We do something similar in Langium where we generate a Chevrotain parser/grammar from a DSL grammar definition (see code). So it should definitely be possible to create (partially) dynamic grammars. However, I'm a bit confused by the error message you're encountering here. It sounds like you're calling |
Beta Was this translation helpful? Give feedback.
-
I also found that confusing -- the actual message is as follows (I was trying unsuccessfully to simplify the question): I do have a rule named 'gate', and a token called 'Gate', but no reference in the code to 'GATE': |
Beta Was this translation helpful? Give feedback.
-
The error ended up being rather trivial (missing parens when returning an object from an anonymous function), but the error message made it a bit hard to track down. The code (now working as expected) is: $.RULE("atom", () => {
$.OR(ruleTypes.map(t => ({ ALT: () => $.SUBRULE($[t]) })))
}); thanks for the help @msujew |
Beta Was this translation helpful? Give feedback.
-
Greetings,
So I currently have a parser rule like this:
that I would instead like to construct dynamically as follows:
Is this possible given how the grammar recording works? Currently I get the error:
TypeError: Cannot read properties of undefined (reading 'RULE') This error was thrown during the "grammar recording phase"...
thanks!
Beta Was this translation helpful? Give feedback.
All reactions