Skip to content

nitls: Improve resiliency to parsing errors - #2865

Open
xymus wants to merge 3 commits into
nitlang:masterfrom
xymus:nitls-parsing
Open

xymus wants to merge 3 commits into
nitlang:masterfrom
xymus:nitls-parsing

Conversation

@xymus

@xymus xymus commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Improve the dependency listing mode -M of nitls to be more resilient to parsing errors. A parsing error in a source file used to make nitlis skip listing that file in its output and not parse its imports. Skipping a file in the dependency list could have make not trigger rebuilds of existing binaries as expected. Without a rebuild, the original parsing errors are simply not reported to the user and the make command succeeds on broken code without doing any work.

Let's make nitls much more resilient to parsing errors with two new behaviors:

  • In nitls, parse only the header of each source file: the module declaration and imports. Ignore all class and method definitions as well as top-level code. This prevents parsing errors later in the file to break the whole file.

    The header information is enough for nitls’ use cases. As a bonus, the reduced work speeds up nitls significantly, nitls -M src/nitc.nit is about 9x faster. Since it can run many time on every make invocation, it becomes noticeably more snappy in large projects.

  • In the case of a parse error in the header, we now correctly list that file in the nitls -M output. It used to be skipped as we listed only type-checked MModules. Now we keep track of the parsing errors and use that information to list problematic files as well.

Intro `scan_token` as the service actually retrieving the next token
from the source file, and keep `get_token` as the service returning the token
to the clients. `get_token` can then act as a refinement point to filter or
alter the token stream.

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
The dependencies listed by `nitls -M` dropped any module with a parsing
error. A broken file would then be missing from the dependencies of a
Makefile, and make could see the binary as up to date. Without the
rebuild the error is fully hidden from the user.

Let's make this less likely by parsing only the part nitls actually
needs to list dependencies. This way a syntax error after the import
list doesn't affect nitls' behavior.

Intro the module loader_header_only, imported by nitls only, which
refines the Lexer to return EOF at the first token of the body.

As a bonus, the reduced work speeds up nitls significantly, `nitls -M
src/nitc.nit` is about 9x faster. Since it can run many time on every
`make` invocation, it becomes noticeably more snappy in large projects.

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
With `nitls -M` a module that failed to parse was not listed in the
output. This could have make think no rebuild was necessery which fully
silenced the error. Let's list the files with the parse error to address
this issue.

To do so we keep a list of the parsing errors. An alternative would be
to keep a list of the AModule parsed or the AError for the failed ones.
Then `nitls` could list those in for the `-M` output instead of the
type-checked MModules.

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
@xymus xymus changed the title nitls: Improve resiliency to parse errors nitls: Improve resiliency to parsing errors Sep 24, 2026
@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Test Results

    67 files     337 suites   16m 3s ⏱️
14 285 tests 13 727 ✅ 558 💤 0 ❌
14 757 runs  14 164 ✅ 593 💤 0 ❌

Results for commit d59a234.

♻️ This comment has been updated with latest results.

@xymus
xymus requested a review from privat September 24, 2026 23:16
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.

1 participant