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

lexer errors shouldn't abort compilation #348

Open
timotheecour opened this issue Mar 5, 2021 · 2 comments
Open

lexer errors shouldn't abort compilation #348

timotheecour opened this issue Mar 5, 2021 · 2 comments

Comments

@timotheecour
Copy link
Member

timotheecour commented Mar 5, 2021

proposal

turn lexer error into a nkLexerError PNode that doesn't stop compilation.
This will make it easier to evolve nim when we need to make backward incompatible changes.

example 1

since (1,5,3):
  proc `'big`(number: string): int = ...
  echo 1234'big

this code should compile in nim < 1.5.3 and nim >= nim-lang/Nim#17020 (user-defined number suffixes)

example 2

see nim-lang/Nim#14253 (comment)

since (1,3,5):
  let foo1 {.importc.}: int  # works since lexer has always allowed it

since (1,5,3):
  const foo2 {.importc.}: int  # lexer error, but would work under this RFC

implementation

the simplest is to, upon encountering a lexer error, tokenize based on whitespace (or perhaps other delimiters) and produce a (nkLexerError) nkError PNode for each unrecognized token. An error would then be generated if semantic pass encounters it in a non-disabled context (eg when false)

note

@Araq
Copy link
Member

Araq commented Mar 5, 2021

I don't understand why we cannot use the more general (upcoming...) nkError node for this.

@timotheecour
Copy link
Member Author

timotheecour commented Mar 5, 2021

i didn't want to tie up this RFC to nkError since it doesn't exist yet, but yes, nkError makes sense to reuse for this, I've replaced nkLexerError by nkError in proposal

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

No branches or pull requests

2 participants