From 1db0c48844667462622708e233c2e546856dfdd2 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Tue, 27 Dec 2022 10:13:31 -0600 Subject: [PATCH] editor/pybricksMicroPython: improve numeric literal highlighting - Drop Python 2.x "L" suffix. - Add support for underscores. - Drop including leading minus sign. - Add support for binary. - Add support for octal. --- CHANGELOG.md | 3 +++ src/editor/pybricksMicroPython.ts | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) 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)