Support empty function calls and be more particular about successful parses#90
Merged
cwisniew merged 4 commits intoRPTools:mainfrom Mar 28, 2025
Merged
Conversation
This forces parse errors in cases that are obviously not correct (e.g., assigning to a string literal). This requires the lexer to consume all tokens and not allow dropping them. It also require explicitly matching multiple expressions in a single line, whereas before the parse would simply stop after the first expression and return it. In order to report unconsume input, we install a `BailErrorStrategy` which - unlike the default - does not attempt error recovery.
Add a few more tests around parsing adjacent expressions in a single line. Also add negative parse tests that are required to fail.
Use `BigDecimal#toString()` instead of `BigDecimal#toPlainString()` when converting number literals to strings. When formatting `NumberLiteral` nodes, use the node text rather than calling `BigDecimal#toString()`. In practice, these the same.
cwisniew
approved these changes
Mar 28, 2025
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.
Fixes various issues with #82
Empty function calls were being rejected since the parser grammar was requiring at least one expression between the parenthesis. This has been fixed to make the arguments optional, thus allowing zero arguments to be passed.
Another issue was that we were calling
BigDecimal#toPlainString()instead ofBigDecimal#toString()as the antrl2 implementation did. A related "problem" is that we cannBigDecimal#toString()where it isn't needed - when formattingNumberLiteralnodes, we use the node text rather than formatting theBigDecimalvalue.The final issue is that antlr is pretty lenient in its parsing by default. Since MapTool depends on parse errors to decide whether to try treating certain values as JSON, it is important that we are more particular about parsing only what the grammars define. To this end, the lexer now consumes all tokens, even unrecognized ones, and the parser explicitly matches to the end of the input. We also installed a
BailErrorStrategythat throws on parse failures and does not perform error recovery. As a result, invalid inputs such as"a" = 5are rejected now.This change is