Skip to content

Commit 1db0c48

Browse files
committed
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.
1 parent ac2d062 commit 1db0c48

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
## [Unreleased]
66

7+
### Changed
8+
- Improved syntax highlighting for numeric literals.
9+
710
## [2.1.0-beta.2] - 2022-12-26
811

912
### Changed

src/editor/pybricksMicroPython.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,12 @@ export const language = <monaco.languages.IMonarchLanguage>{
219219
[/"/, 'string'],
220220
],
221221

222-
// Recognize hex, negatives, decimals, imaginaries, longs, and scientific notation
222+
// Recognize binary, octal, hex, decimals, imaginary, and scientific notation
223223
numbers: [
224-
[/-?0x([abcdef]|[ABCDEF]|\d)+[lL]?/, 'constant.numeric.hex'],
225-
[/-?(\d*\.)?\d+([eE][+-]?\d+)?[jJ]?[lL]?/, 'constant.numeric'],
224+
[/\b0[bB](0|1|_)+/, 'constant.numeric.bin'],
225+
[/\b0[oO]([0-7]|_)+/, 'constant.numeric.oct'],
226+
[/\b0[xX]([abcdef]|[ABCDEF]|\d|_)+/, 'constant.numeric.hex'],
227+
[/\b([\d_]*\.)?[\d_]+([eE][+-]?[\d_]+)?[jJ]?/, 'constant.numeric'],
226228
],
227229

228230
// Recognize strings, including those broken across lines with \ (but not without)

0 commit comments

Comments
 (0)