-
I'm sure this is super obvious (I'm a new user), but how to define a parser rule that says one or more of a few options:
Is the proper way to create a sub-rule for each option (as below,) or can I simply say AT_LEAST_ONE(OR [{ALT: ..., }]) $.RULE("element-part", () => {
$.OR([
{ ALT: () => $.SUBRULE($.chars) },
{ ALT: () => $.SUBRULE($.choice) },
{ ALT: () => $.SUBRULE($.symbol) },
])
})
$.RULE("element", () => {
$.AT_LEAST_ONE(() => $.SUBRULE($.element-part"));
}); |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hey @dhowe, I've converted this into an discussions, since they are better suited for asking and answering questions on GitHub.
Yes, everything in Chevrotain is embeddable into each other. In your case it would be: $.RULE("element", () => {
$.AT_LEAST_ONE(() =>
$.OR([
{ ALT: () => $.SUBRULE($.chars) },
{ ALT: () => $.SUBRULE($.choice) },
{ ALT: () => $.SUBRULE($.symbol) },
])
));
}); |
Beta Was this translation helpful? Give feedback.
-
thanks @msujew - ended up with something quite similar... now trying to figure out why some of these subrules never fire does the order of subrules matter? |
Beta Was this translation helpful? Give feedback.
Hey @dhowe, I've converted this into an discussions, since they are better suited for asking and answering questions on GitHub.
Yes, everything in Chevrotain is embeddable into each other. In your case it would be: