Add -E / --all-errors flag to nwn_script_comp#153
Open
cgtudor wants to merge 3 commits intoniv:masterfrom
Open
Add -E / --all-errors flag to nwn_script_comp#153cgtudor wants to merge 3 commits intoniv:masterfrom
-E / --all-errors flag to nwn_script_comp#153cgtudor wants to merge 3 commits intoniv:masterfrom
Conversation
This flag allows the compilation of a file (or files) without requiring an entry point (void main or StartingConditional). Useful for validating files, especially for compatibility with the vscode language server.
This is to support collecting and outputing all errors instead of exiting early after finding one. Useful for validation and language servers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Built on top of #152 and dependent on it. If I could have made that branch the base and have it still show in this repo, I would have.
Adds a new
-E/--all-errorsflag tonwn_script_compthat collects and reports all compilation errors in a file instead of stopping at the first one. This is useful for (potential) IDEs, language servers, and batch validation workflows.Multi-error collection infrastructure
The compiler gains a multi-error mode controlled by
SetCollectAllErrors(). When enabled:;or}at brace depth 0), resets the SR stack, and continues parsing. This allows multiple parse errors in different functions to be reported in a single pass.WalkParseTree) saves and restores code-gen state around eachFUNCTIONAL_UNITnode. A semantic error in one function rolls back that function and continues to the next.m_vCapturedErrors/m_vnCapturedErrorStrRefsvectors (up to a configurable limit) and exposed throughGetCollectedErrorCount()/GetCollectedError().scriptCompApiSetCollectAllErrors,scriptCompApiGetCollectedErrorCount,scriptCompApiGetCollectedError) and corresponding Nim bindings.Mixed parse + semantic error reporting
When a file has both parse errors and semantic errors in different functions, the initial implementation only reported parse errors; semantic errors in correctly-parsed functions were silently lost. This happened because:
DeleteCompileStack()which destroyed the entire parse tree, including already-completed functions.CompileFileskippedGenerateFinalCodeFromParseTreeentirely when parse errors existed, so the tree walker never ran.The fix saves completed function subtrees from the SR stack before error recovery destroys them, accumulating them in
m_pSavedParseTree. After parsing completes, these saved trees are walked for semantic errors viaInitializeFinalCode+InsertGlobalVariablesInParseTree+WalkParseTree. Post-recovery functions that were parsed after the error but before EOF are also collected, including completing any pending grammar reductions (e.g., linking a function body that was still inpReturnTree).For example, a file with a semantic error on line 31 and a parse error on line 43 now reports both:
Output format
When
-Eis active, each collected error is printed as a separate log line. Without-E, the compiler behaves exactly as before (stops at the first error).Testing
Tested with five scenarios:
)and{(line 43)Also verified normal mode (without
-E) is unaffected.Changelog
Added
-E/--all-errorsflag fornwn_script_comp: collects and reports all compilation errors per file instead of stopping at the first. Useful for IDEs and language servers.Licence