diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b4cd943..14b9635b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ ## [Unreleased] +### Changed +- Improved syntax highlighting for numeric literals. + ## [2.1.0-beta.2] - 2022-12-26 ### Changed diff --git a/src/editor/pybricksMicroPython.ts b/src/editor/pybricksMicroPython.ts index 7b6c7f12..8d1f0df0 100644 --- a/src/editor/pybricksMicroPython.ts +++ b/src/editor/pybricksMicroPython.ts @@ -219,10 +219,12 @@ export const language = { [/"/, 'string'], ], - // Recognize hex, negatives, decimals, imaginaries, longs, and scientific notation + // Recognize binary, octal, hex, decimals, imaginary, and scientific notation numbers: [ - [/-?0x([abcdef]|[ABCDEF]|\d)+[lL]?/, 'constant.numeric.hex'], - [/-?(\d*\.)?\d+([eE][+-]?\d+)?[jJ]?[lL]?/, 'constant.numeric'], + [/\b0[bB](0|1|_)+/, 'constant.numeric.bin'], + [/\b0[oO]([0-7]|_)+/, 'constant.numeric.oct'], + [/\b0[xX]([abcdef]|[ABCDEF]|\d|_)+/, 'constant.numeric.hex'], + [/\b([\d_]*\.)?[\d_]+([eE][+-]?[\d_]+)?[jJ]?/, 'constant.numeric'], ], // Recognize strings, including those broken across lines with \ (but not without)