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.
From #555
Summary
This PR implements a new WebGAL parser based on parsing expression grammar (PEG). This has certain advantages over the current non-standard string-based parsing and enables the possibility of optimizations, advanced grammar, better error handling, etc. The new parser aims to be fully compatible with the old one.
Features (If Implemented Correctly)
Backward compatibility
The new parser also generates a
sentenceListwith all fields available in the old parser. It may add some extra fields (e.g., recording errors and some utility command string information), but the result should work on the current engine.New Behavior for Syntax Errors
Now, if the parser encounters syntax errors when parsing a command, it will stop at the character that contains the error and skip to the next line, but the parsed command will still be effective
For example, if a script contains
it will then be parsed as
which preserves the behavior of
pixiInit.Error Reporting and Recovery
The new parser supports error reporting and recovery. All errors in the script will be recorded in an
errorsfield, which can be shown to the user after adapting the language server protocol (LSP) on this.The aforementioned new behaviors on syntax errors ensures error recovery.
Changes to Source Code
The source code of the old parser is moved to
packages/parser_legacy. The package name is changed towebgal-parser-legacyThe source code of the new parser is put in
packages/parser. It is distributed under MPL-2.0 license (license file attached).What's Next
parser.jsto ~100KB. Together with gzip on the web server, it may reduce the final data transmission.@MakinoharaShoko, feel free to change the merge base branch :)