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

Re-parse for unresolved conflict? #19

Closed
DiscreteTom opened this issue Sep 16, 2023 · 1 comment
Closed

Re-parse for unresolved conflict? #19

DiscreteTom opened this issue Sep 16, 2023 · 1 comment
Labels
enhancement New feature or request parser

Comments

@DiscreteTom
Copy link
Owner

In LR(1) we only check the next grammar to resolve the conflict but sometimes it's not enough.

Maybe we can add something like re-parse to rollback the parser, just like re-lex?

This may impact the performance, consider add a new build option reParse: boolean.

@DiscreteTom
Copy link
Owner Author

However, after enabling re-parse and don't resolve conflicts, the parser will usually use the wrong grammar rule to reduce.
It's not recommended to implement this feature. Language developers should always be clear about those conflicts and how to resovle them correctly.

For those conflicts that can't be resolved by next grammar, developers can use a function as the resolver's accetper, which can use the lexer to get more following tokens to resolve the conflict.

  .resolveRR(
    reducerRule,
    anotherRule,
    {
      next: "*",
      accept: ({ lexer }) => {
        lexer.clone().lex();
        return true;
      },
    },
  );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request parser
Projects
None yet
Development

No branches or pull requests

1 participant