MarkusAmshove / natls

Language Server implementation for the Natural 4GL programming language
MIT License
13 stars 3 forks source link

Move INCLUDE resolution into the Lexer #411

Open MarkusAmshove opened 1 year ago

MarkusAmshove commented 1 year ago

Currently copy codes are resolved within the parser, where a copy code is lexed and parsed when encountering an INCLUDE, passing all the copy code parameters to the lexer. The parsed statements from parsing the copy code are then appended after the INCLUDE node within the including source.

This works for a lot of cases, but does leave some edge cases behind and make them near impossible to solve.

A way to solve it would be to get the copy code resolution out of the parser and move it into the lexer. The lexer would encounter the INCLUDE keyword and then look for an identifier next and collect all the string literals that follow as copy code parameter. Then the lexer would call a new lexer for the copy code source and pass all parameter. The "nested" lexer returns a token list which is then appended instead of the INCLUDE identifier 'param'....

That should solve the following issues:

Implementation gotchas:

Claes65 commented 1 year ago

This works for a lot of cases, but does leave some edge cases behind and make them near impossible to solve.

If you fully exploit the power of Copycodes, it's no longer just a corner case. So very happy to see this going into the project. 👍