Skip to content

fix(groovy) support underscores in numeric literals#4422

Open
greymoth-jp wants to merge 1 commit into
highlightjs:mainfrom
greymoth-jp:fix-groovy-numeric-underscores
Open

fix(groovy) support underscores in numeric literals#4422
greymoth-jp wants to merge 1 commit into
highlightjs:mainfrom
greymoth-jp:fix-groovy-numeric-underscores

Conversation

@greymoth-jp

Copy link
Copy Markdown

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 generic C_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_000
  • 0xFF_EC_DE_5E -> <number>0xFF</number>_EC_DE_5E
  • 0b1010_0101 -> <number>0b1010</number>_0101

After:

  • 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.js already handles this by importing the shared Java NUMERIC mode (with the note "the number mode of kotlin is the same as java 8"). Groovy is in the same spot, so this switches it to NUMERIC too. Same idea as #4280, which added digit separator support to C#.

Checklist

  • Added markup tests (test/markup/groovy/numbers)
  • Updated the changelog at CHANGES.md

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant