Skip to content

Commit

Permalink
LimeParser: non-greedy parsing of new lines for ceratin constants (#1651
Browse files Browse the repository at this point in the history
)

Certain sub-rules of 'constant' rule used greedy
matching of new lines at the end:
 - 'structInitializer'
 - 'listInitializer'
 - 'mapInitializer'

If the input LIME file contained invalid syntax
after such constant definition, then the parser
tried to apply greedy matching. It resulted in
meaningless error message e.g.:
 - `mismatched input '//' expecting NewLine`

This change adds the usage of 'Nongreedy Parser Subrules'
which prevent the greedy matching and meaningless error
messages.

Signed-off-by: Patryk Wrobel <[email protected]>
  • Loading branch information
pwrobeldev authored Feb 11, 2025
1 parent 2074677 commit 4094eda
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased
### Bug fixes:
* LimeParser: introduced non-greedy parsing of new lines for ceratin sub-rules of `constant` rule to prevent meaningless error messages when invalid syntax is used after declaration of a constant.
* Dart: fixed problem related to missing includes for `@Async` functions.
* JNI: removed leak of JNI weak references in JniWrapperCache.

Expand Down
6 changes: 3 additions & 3 deletions lime-loader/src/main/antlr/LimeParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,15 @@ positionalEnumeratorRef

structInitializer
: '{' NewLine* ((simpleId NewLine* '=' NewLine*)? literalConstant NewLine*
(',' NewLine* (simpleId NewLine* '=' NewLine*)? literalConstant NewLine*)*)? '}' NewLine*
(',' NewLine* (simpleId NewLine* '=' NewLine*)? literalConstant NewLine*)*)? '}' NewLine*?
;

listInitializer
: '[' NewLine* (literalConstant NewLine* (',' NewLine* literalConstant NewLine*)*)? ']' NewLine*
: '[' NewLine* (literalConstant NewLine* (',' NewLine* literalConstant NewLine*)*)? ']' NewLine*?
;

mapInitializer
: '[' NewLine* (keyValuePair NewLine* (',' NewLine* keyValuePair NewLine*)*)? ']' NewLine*
: '[' NewLine* (keyValuePair NewLine* (',' NewLine* keyValuePair NewLine*)*)? ']' NewLine*?
;

keyValuePair
Expand Down

0 comments on commit 4094eda

Please sign in to comment.