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

SKIP_TOKEN return value unintuive #1699

Closed
NaridaL opened this issue Nov 2, 2021 · 1 comment
Closed

SKIP_TOKEN return value unintuive #1699

NaridaL opened this issue Nov 2, 2021 · 1 comment
Labels

Comments

@NaridaL
Copy link
Collaborator

NaridaL commented Nov 2, 2021

There's no CONSUME_ANY_TOKEN in the public API, but you can use SKIP_TOKEN. However that doesn't return the skipped token (which is what I would expect), but rather the token after the skipped token.

Example to skip over all tokens until the next comma

    const skippedTokens = []
    this.MANY({
      GATE: () => this.LA(1).tokenType !== TOKEN.COMMA,
      DEF: () => skippedTokens.push(this.SKIP_TOKEN()),
    })
    this.CONSUME(TOKEN.COMMA)
@bd82 bd82 added the API label Nov 2, 2021
@bd82
Copy link
Member

bd82 commented Nov 2, 2021

I think the main problem is that SKIP_TOKEN lacks documentation

In regards to the code snippet.
There is no need to wrap the SKIP_TOKEN with the MANY you can use a simple loop instead.
The only things that must be wrapped with the grammar methods are the grammar methods themselves, e.g CONSUME inside of MANY

SKIP_TOKEN is currently used internally for recovery related logic, I guess in that scenario it made more sense discard the skipped token. Perhaps other utilities should be exposed to make your use case easy to implement?
Although LA(1) provides you with the "next_token" so maybe that is sufficient for your scenario.

@bd82 bd82 closed this as completed in dc53555 Jun 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants