All contributions

alecthomas/chroma

Chroma

A general purpose syntax highlighter in pure Go: it turns source code and other structured text into highlighted HTML or ANSI-coloured text.

Language
Go
GitHub stars
5,086
Merged changes
1

What we changed

The TypeScript lexer recognises binary, octal, upper-case hex, exponent and underscore-separated literals such as 0b1010, 0o17, 0XFF, 1e5 and 1_000, instead of splitting them into a number and a name.

What this work shows

  • Lexers and syntax highlighting
  • Regular expressions for numeric literals
  • Golden-file tests
What was broken

0b1010 split into a number and a name

The TypeScript lexer had only three number rules. Literals such as 0b1010, 0o17, 0XFF, 1e5 and 1_000 were split into a number and a name, so each part was highlighted separately.

How we fixed it

Number rules from the JavaScript lexer

We ported the number rules from the JavaScript lexer: separate rules for binary, octal and hex with a lower- or upper-case prefix, and a float rule that still keeps a fraction and an exponent together, as in 1.5e10. A new number_literals fixture checks all of these cases.

#1396

Merged change 1

  1. #1396 fix(lexers): recognize TypeScript binary, octal and exponent literals Merged 15 October 2026

What it taught us

The lexers of two related languages drift apart quietly, so it is better to close the whole class of cases at once. TypeScript writes numbers the same way JavaScript does, so we ported the rules from the JavaScript lexer and covered them with a golden-file test.

More about this technology: Golang

Other projects we write code for

Describe your project.

A free quote comes back within an hour during working hours.