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

Scannerless parsing #23

Merged
merged 12 commits into from
Oct 5, 2023
Merged

Scannerless parsing #23

merged 12 commits into from
Oct 5, 2023

Conversation

alllex
Copy link
Owner

@alllex alllex commented Oct 4, 2023

In this approach to parsing, there is no separate tokenization process. Instead, each parser tries to directly parse a token it expects.

This has a number of advantages:

  • The priority of tokens becomes local to the parser declaration (the order of components in the or sequence).
  • Token declaration order becomes largerly irrelevant, which reduces the potential for user errors.
  • Grammar composition and inheritance become more straightforward.

The main drawback for now is a slight drop in performance. This is due to inability to proactively extract the next token and make smarter work avoidance decisions (e.g. jumping directly to the right parser in the set of alternatives using the 1-token lookahead). However, this is a small price to pay for added flexibility and developer experience.

This is related and alleviates the problems described in

@alllex alllex merged commit fde0d8b into main Oct 5, 2023
1 check passed
@alllex alllex deleted the scannerless-parsing branch October 5, 2023 20:48
@EndzeitBegins
Copy link

Hey @alllex, just wanted to let you know that I've tried the changes you made using a local build of parsus and from my point of view, it works like a charm now!

I can now easily declare my parser as a series of expected tokens or combinations thereof, basically just translating the specification document to Kotlin. I really, really like the declarativeness and composability this entails. Thank you for your work.

I'm looking forward for the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants