Skip to content

How to say "one or more of a few options" in parser? #1855

Answered by msujew
dhowe asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @dhowe, I've converted this into an discussions, since they are better suited for asking and answering questions on GitHub.

or can I simply say AT_LEAST_ONE(OR [{ALT: ..., }])

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) },
    ])
  ));
});

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by dhowe
Comment options

You must be logged in to vote
1 reply
@msujew
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1854 on September 20, 2022 10:03.