Skip to content

Repeat Parser Method n times #1876

Answered by msujew
vedant-g asked this question in Q&A
Oct 31, 2022 · 4 comments · 1 reply
Discussion options

You must be logged in to vote

Hey @vedant-g,

effectively, Chevrotain uses a grammar notation that is quite similar to the well-known EBNF. The MANY and AT_LEAST_ONE functions map to * and + in the EBNF notation respectively. However, there's no way to specify how often a repetition is to be parsed in EBNF nor in Chevrotain. You can only specify that parsing should stop using GATE properties.

If I want to have exactly 5 identifiers separated by comma, how can i specify that using AT_LEAST_ONE_SEP method

On another note, I would advise you to not go down that route. In general, grammars should be kept flexible, maybe even allowing to parse relatively unreasonable constructs. A post-processing phase should then validat…

Replies: 4 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by vedant-g
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@vedant-g
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
3 participants