Fix parsing of multiple consecutive underscore in digits #6

Merged
sergeichestakov merged 2 commits from fix-underscore-digit-parsing into main 2023-02-11 11:27:41 +01:00
sergeichestakov commented 2023-02-10 20:45:19 +01:00 (Migrated from github.com)

In Java, having multiple underscores in between digits is valid syntax. e.g.

int num = 123____456;

but it seems that is not being properly highlighted in CodeMirror. This PR attempts to address that by modifying the grammar to permit an arbitrary number of _ in between numbers when parsing digits. Let me know if this looks right.

In Java, having multiple underscores in between digits is valid syntax. e.g. ```java int num = 123____456; ``` but it seems that is not being properly highlighted in CodeMirror. This PR attempts to address that by modifying the grammar to permit an arbitrary number of `_` in between numbers when parsing digits. Let me know if this looks right.
marijnh commented 2023-02-10 21:29:27 +01:00 (Migrated from github.com)

Are you sure this is valid Java? When I try this I get a "SyntaxError: number cannot contain multiple adjacent underscores" error.

Are you sure this is valid Java? When I try this I get a "SyntaxError: number cannot contain multiple adjacent underscores" error.
sergeichestakov commented 2023-02-10 22:00:11 +01:00 (Migrated from github.com)

yes I believe it's only valid for JDK 8+. Am referencing the docs here. Have a runnable example here: https://replit.com/@SergeiChestakov/undercore-int-example

yes I believe it's only valid for JDK 8+. Am referencing the docs [here](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html). Have a runnable example here: https://replit.com/@SergeiChestakov/undercore-int-example
marijnh commented 2023-02-10 23:14:39 +01:00 (Migrated from github.com)

Ah, seems you are right. Could you change the * to a + in your change? I am pretty sure Lezer's DFA generation will handle the scary ambiguity of the way you have it now, but it seems needlessly obscure and will cause people used to backtracking regexps to get nervous when they read it.

Ah, seems you are right. Could you change the `*` to a `+` in your change? I am pretty sure Lezer's DFA generation will handle the scary ambiguity of the way you have it now, but it seems needlessly obscure and will cause people used to backtracking regexps to get nervous when they read it.
sergeichestakov commented 2023-02-10 23:20:52 +01:00 (Migrated from github.com)

done, thanks!

done, thanks!
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lezer/java!6
No description provided.