[Bug] Go numeric literals with underscore separators are split into identifiers

Open Beginner friendly
#5,577 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
83/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Domain
tooling

Research direction

Read src/languages/definitions/go/go.ts and inspect the numeric token patterns for decimal, hexadecimal, octal, and binary literals. Compare how those patterns handle apostrophes with the Go specification's underscore rules. Done means underscore separated literals, including underscores after a base prefix, remain highlighted as numeric tokens while the existing controls continue to work.

Written by the indexing model from the issue text.

Description

Reproducible in vscode.dev or VS Code Desktop?
  • Not reproducible in VS Code Desktop

The same sample is highlighted correctly in VS Code Desktop 1.112.0 with its built-in Go grammar.

Monaco Editor Playground Link

https://microsoft.github.io/monaco-editor/playground.html?source=v0.55.1#XQAAAAJ_AQAAAAAAAABBqIlHNxBQULmks8zdMxBz6L26xuvvGbdndOZD1YpFwHiNhRMYKW6igcDTvOMnqrlexg4fKmUmONbkJiaVUf7wADEiM-8n2r6kYPX5Dk5iAyYfR199txnkUusvToSQf37F2QV3ECHYc6SG8xt9_WpDPL1VGIQzIb7lwruYjdmQGrJaNOUp__pvDwEihve0X_tb3hvyf9br8dAChC6i8UBY47qhjIIHr7807GN9zJbmULXOHm9Po7rO4JGmDGK4RNjq5lBtTHdJaCyrf12Am0WQUq4DVlsN69UcWfl1fizPODzp0cnnOLewsvPuQF_E3iApegkL7j2lQy7ZcTSx0xkVTZGqRx-nnu5YLicnpba73iTaTT464X4HFv_hSmAJ

Monaco Editor Playground Code

JavaScript:

monaco.editor.create(document.getElementById("container"), {
  value: [
    "package main",
    "",
    "var decimal = 1_000",
    "var hex = 0xCA_FE",
    "var binary = 0b1010_0110",
    "",
    "var control = 1000",
    "var hexControl = 0xCAFE"
  ].join("\n"),
  language: "go",
  theme: "vs-dark",
  fontSize: 20
});

HTML:

<div id="container" style="height:100vh"></div>

CSS:

html, body { margin: 0; height: 100%; }
Reproduction Steps
  1. Open the playground link and click Load if prompted.
  2. Compare the three literals containing underscores with the controls without underscores.
Actual Behavior

The numeric token ends before the first underscore:

  • 1_000: 1 is number.go; _000 is identifier.go.
  • 0xCA_FE: 0xCA is number.hex.go; _FE is identifier.go.
  • 0b1010_0110: 0b1010 is number.binary.go; _0110 is identifier.go.

The suffix consequently uses identifier highlighting instead of number highlighting. Reproduced in playground 0.55.1 and with the Go grammar from current main at 5359a3330383137dfdf8897ba1d93d943fec4027.

Expected Behavior

The underscore and following digits should remain part of the numeric literal. These are valid Go literals: the Go specification permits underscores between digits or after a base prefix.

Additional Context

The numeric rules in src/languages/definitions/go/go.ts accept apostrophes in the hexadecimal, octal, binary and decimal patterns, but do not handle Go's underscore separators.

Go specification: https://go.dev/ref/spec
Grammar source: https://github.com/microsoft/monaco-editor/blob/main/src/languages/definitions/go/go.ts

Dominant language
JavaScript
Stars
46.9k
Forks
4.2k
Avg merge
2d 5h
Merged PRs (30d)
28

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/monaco-editor

All issues in microsoft/monaco-editor

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.