From 5bef7e26379cd95318233bf0526dfa8ffcbadee1 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Tue, 27 Dec 2022 11:02:52 -0600 Subject: [PATCH] editor/pybricksMicroPython: improve operator highlighting This handles newer things like the := operator better. --- CHANGELOG.md | 2 +- src/editor/pybricksMicroPython.ts | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14b9635b..6725ef6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ ## [Unreleased] ### Changed -- Improved syntax highlighting for numeric literals. +- Improved syntax highlighting for operators and numeric literals. ## [2.1.0-beta.2] - 2022-12-26 diff --git a/src/editor/pybricksMicroPython.ts b/src/editor/pybricksMicroPython.ts index 8d1f0df0..ac5e86f8 100644 --- a/src/editor/pybricksMicroPython.ts +++ b/src/editor/pybricksMicroPython.ts @@ -180,13 +180,12 @@ export const language = { { include: '@whitespace' }, { include: '@numbers' }, { include: '@strings' }, - { include: '@operators' }, - - [/[,:;]/, 'delimiter'], - [/[{}[\]()]/, '@brackets'], - [/@[a-zA-Z_]\w*/, 'tag'], - + [/\.\.\./, 'keyword'], + [/->/, 'delimiter'], + { include: '@operators' }, + [/[,:.;=]/, 'delimiter'], + [/[{}[\]()]/, '@brackets'], [ /[a-zA-Z_]\w*/, { @@ -249,7 +248,12 @@ export const language = { [/\\$/, 'string'], ], - operators: [[/[=+\-*/%@&|<>!~^]/, 'keyword.operator']], + operators: [ + [ + /(\*\*|\/\/|<<|>>|:=|<=|>=|==|!=|\+=|-=|\*-|\/=|\.\.=|%=|@=|&=|\|=|\^=|>>=|<<=|\*\*=|[+\-*/%@&|^~<>])/, + 'keyword.operator', + ], + ], attributes: [ [/\b/, '@pop'],