From 47e981c0d66881fa6ab2be2ff185c814f0a372c1 Mon Sep 17 00:00:00 2001 From: notmeegoreng Date: Sat, 14 Sep 2024 16:53:43 +0800 Subject: [PATCH 1/3] Fix faulty regex --- src/editors/ace/modes/source.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/editors/ace/modes/source.ts b/src/editors/ace/modes/source.ts index c507e581e..8d09b6945 100644 --- a/src/editors/ace/modes/source.ts +++ b/src/editors/ace/modes/source.ts @@ -113,9 +113,9 @@ export function HighlightRulesSelector( const VariantForbiddenRegexSelector = () => { if (variant === Variant.TYPED) { // Removes the part of the regex that highlights singular |, since Typed variant uses union types - return /\.{3}|--+|\+\++|\^|(==|!=)[^=]|[$%&*+\-~\/^]=+|[^&]*&[^&]/ + return /\.{3}|--+|\+\++|\^|(==|!=)[^=]|[$%&*+\-~\/^]=+|(? Date: Sat, 14 Sep 2024 21:41:07 +0800 Subject: [PATCH 2/3] fix regex properly, removing extra *s --- src/editors/ace/modes/source.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/editors/ace/modes/source.ts b/src/editors/ace/modes/source.ts index 8d09b6945..2b402101d 100644 --- a/src/editors/ace/modes/source.ts +++ b/src/editors/ace/modes/source.ts @@ -113,9 +113,9 @@ export function HighlightRulesSelector( const VariantForbiddenRegexSelector = () => { if (variant === Variant.TYPED) { // Removes the part of the regex that highlights singular |, since Typed variant uses union types - return /\.{3}|--+|\+\++|\^|(==|!=)[^=]|[$%&*+\-~\/^]=+|(? Date: Sat, 14 Sep 2024 21:41:19 +0800 Subject: [PATCH 3/3] add tests --- src/__tests__/mode.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/__tests__/mode.ts b/src/__tests__/mode.ts index 9f792e21a..12f318aff 100644 --- a/src/__tests__/mode.ts +++ b/src/__tests__/mode.ts @@ -79,7 +79,7 @@ test('constants are not correctly loaded', () => { }) test('operator syntax type error', () => { - const code = 'const num = 3; \nnum++; \nnum--; \nnum += 1;' + const code = 'const num = 3; \nnum++; \nnum--; \nnum += 1; \n5 + num |2;' setSession(Chapter.SOURCE_1, defaultVariant, defaultExternal, code) @@ -91,6 +91,15 @@ test('operator syntax type error', () => { const token3 = session.getTokenAt(3, 5) expect(expectedBool(token3, CATEGORY.forbidden)).toBe(true) + + const token4 = session.getTokenAt(4, 1) + expect(expectedBool(token4, CATEGORY.number)).toBe(true) + + const token5 = session.getTokenAt(4, 9) + expect(expectedBool(token5, CATEGORY.forbidden)).toBe(true) + + const token6 = session.getTokenAt(4, 10) + expect(expectedBool(token6, CATEGORY.number)).toBe(true) }) test('forbidden keywords', () => {