fix(groovy) support underscores in numeric literals#4422
Open
greymoth-jp wants to merge 1 commit into
Open
Conversation
Groovy uses Java's numeric literal grammar, which allows underscores as digit separators (1_000, 0xFF_EC, 0b1010_0101). The grammar was using the generic C_NUMBER_MODE, so 1_000_000 highlighted only the leading 1. Switch to the shared Java NUMERIC mode, the same approach kotlin.js already takes.
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.
Changes
Groovy uses the same numeric literal grammar as Java, which allows underscores as digit separators (
1_000,0xFF_EC,0b1010_0101,3.141_592). The grammar was using the genericC_NUMBER_MODE/BINARY_NUMBER_MODE, neither of which accepts_, so anything past the first separator dropped out of the number.Before:
1_000_000-><number>1</number>_000_0000xFF_EC_DE_5E-><number>0xFF</number>_EC_DE_5E0b1010_0101-><number>0b1010</number>_0101After:
1_000_000-><number>1_000_000</number>0xFF_EC_DE_5E-><number>0xFF_EC_DE_5E</number>0b1010_0101-><number>0b1010_0101</number>kotlin.jsalready handles this by importing the shared JavaNUMERICmode (with the note "the number mode of kotlin is the same as java 8"). Groovy is in the same spot, so this switches it toNUMERICtoo. Same idea as #4280, which added digit separator support to C#.Checklist
test/markup/groovy/numbers)CHANGES.md