elixir-tools / spitfire

Error tolerant parser for Elixir
https://www.elixir-tools.dev
MIT License
69 stars 7 forks source link

refactor: on demand lexing #31

Open mhanberg opened 3 months ago

mhanberg commented 3 months ago

Description

Recursive Descent parsers tend to lex the document as they go, rather than all up front. This allows you to know what to do in the case a bad token is lexed in the context of the current parsing state.

The existing lexer (elixir_tokenizer) is designed to work with a parser generator (yecc), so it parses it all up front, and if it reaches a bad token, it bails and returns an error.

Solution

Refactor the existing :elixir_tokenizer (vendored as :spitfire_tokenzier to enable on demand lexing.

The API of the module should basically consist of

The token structure should stay the same and contain the same semantics.

Considerations