Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support tokens amount in range #19

Closed
uriva opened this issue Aug 9, 2017 · 4 comments
Closed

Support tokens amount in range #19

uriva opened this issue Aug 9, 2017 · 4 comments

Comments

@uriva
Copy link

uriva commented Aug 9, 2017

Hi,
Would a code that adds support for the following:

start -> some_expression{1,3}

Be merged?

(The meaning here is that we are willing to parse 1-3 consecutive occurrences of some_expression)

@erezsh
Copy link
Member

erezsh commented Aug 9, 2017

Sure, I'm open to this feature.
How do you plan to implement it?

@uriva
Copy link
Author

uriva commented Aug 9, 2017

Regexp manipulation on grammar before it is processed. (Not my code so won't take credit:))

@erezsh
Copy link
Member

erezsh commented Aug 9, 2017

If you mean literally running regexps on the grammar, then I won't merge such code. Using regexps, it will be limited to simple expressions only, it won't handle typos well, and it will hinder future additions to the syntax.

That way to implement this feature is to:

  1. Add it to the grammar parser (in load_grammar)

  2. Manipulate the resulting tree, before it's compiled into a new parser

erezsh added a commit that referenced this issue Feb 10, 2018
…ues #75, #19)

Syntax: symbol~number
      | symbol~min..max

Example:

  HEXCOLOR: "#" (HEXDIGIT~3 | HEXDIGIT~6)
  short_sentence: word~4..20

Added range for tokens
@erezsh
Copy link
Member

erezsh commented Feb 10, 2018

Just added support for this in latest master (not in the official release yet). Let me know if it works for you!
Syntax looks like:

start: some_expression~1..3

@erezsh erezsh closed this as completed Apr 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants