From 9f0db9b2388ecb07b3b2d39bd151d9b6c22deabf Mon Sep 17 00:00:00 2001 From: RedCMD <33529441+RedCMD@users.noreply.github.com> Date: Wed, 2 Apr 2025 02:05:56 +1300 Subject: [PATCH 1/4] Empty `end` match immediately --- src/rule.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rule.ts b/src/rule.ts index 6f30da68..499beb3c 100644 --- a/src/rule.ts +++ b/src/rule.ts @@ -221,7 +221,7 @@ export class BeginEndRule extends Rule { super($location, id, name, contentName); this._begin = new RegExpSource(begin, this.id); this.beginCaptures = beginCaptures; - this._end = new RegExpSource(end ? end : '\uFFFF', -1); + this._end = new RegExpSource(end ? end : '', -1); this.endHasBackReferences = this._end.hasBackReferences; this.endCaptures = endCaptures; this.applyEndPatternLast = applyEndPatternLast || false; From 6fcc3b4ac0a3af855fd8d0edff15ba7ac7ae27f2 Mon Sep 17 00:00:00 2001 From: RedCMD <33529441+RedCMD@users.noreply.github.com> Date: Wed, 2 Apr 2025 09:00:48 +1300 Subject: [PATCH 2/4] Empty 'while' match immediately --- src/rule.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rule.ts b/src/rule.ts index 499beb3c..cc840c53 100644 --- a/src/rule.ts +++ b/src/rule.ts @@ -372,7 +372,7 @@ export class BeginWhileRule extends Rule { this._cachedCompiledWhilePatterns.push(this._while.hasBackReferences ? this._while.clone() : this._while); } if (this._while.hasBackReferences) { - this._cachedCompiledWhilePatterns.setSource(0, endRegexSource ? endRegexSource : '\uFFFF'); + this._cachedCompiledWhilePatterns.setSource(0, endRegexSource ? endRegexSource : ''); } return this._cachedCompiledWhilePatterns; } From 24b6d7a690cbf5d4b6c35655db00a0b3f687c896 Mon Sep 17 00:00:00 2001 From: RedCMD Date: Wed, 2 Apr 2025 23:37:14 +1300 Subject: [PATCH 3/4] Add test case #251 empty `end` match immediately --- .../suite1/fixtures/251.tmLanguage.json | 11 ++++++ test-cases/suite1/tests.json | 35 ++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 test-cases/suite1/fixtures/251.tmLanguage.json diff --git a/test-cases/suite1/fixtures/251.tmLanguage.json b/test-cases/suite1/fixtures/251.tmLanguage.json new file mode 100644 index 00000000..c0a9347a --- /dev/null +++ b/test-cases/suite1/fixtures/251.tmLanguage.json @@ -0,0 +1,11 @@ +{ + "$schema": "https://raw.githubusercontent.com/RedCMD/TmLanguage-Syntax-Highlighter/main/vscode.tmLanguage.schema.json", + "scopeName": "source.empty.end", + "patterns": [ + { + "begin": "comment", + "end": "", + "name": "comment" + } + ] +} \ No newline at end of file diff --git a/test-cases/suite1/tests.json b/test-cases/suite1/tests.json index 0d89599b..2a4130fe 100644 --- a/test-cases/suite1/tests.json +++ b/test-cases/suite1/tests.json @@ -1828,5 +1828,38 @@ ] } ] + }, + { + "grammars": [ + "fixtures/251.tmLanguage.json" + ], + "grammarPath": "fixtures/251.tmLanguage.json", + "desc": "Issue #251 empty `end` match immediately", + "lines": [ + { + "line": " comment ", + "tokens": [ + { + "value": " ", + "scopes": [ + "source.empty.end" + ] + }, + { + "value": "comment", + "scopes": [ + "source.empty.end", + "comment" + ] + }, + { + "value": " ", + "scopes": [ + "source.empty.end" + ] + } + ] + } + ] } -] +] \ No newline at end of file From 0eab4b56c0e6c94f36399859499a2d5ce7f2bc8a Mon Sep 17 00:00:00 2001 From: RedCMD Date: Wed, 2 Apr 2025 23:37:44 +1300 Subject: [PATCH 4/4] Fix test case #66 `end` matching `undefined` --- test-cases/suite1/fixtures/66.plist | 4 ++-- test-cases/suite1/tests.json | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/test-cases/suite1/fixtures/66.plist b/test-cases/suite1/fixtures/66.plist index 0e22924a..102ecd58 100644 --- a/test-cases/suite1/fixtures/66.plist +++ b/test-cases/suite1/fixtures/66.plist @@ -13,8 +13,8 @@ - begin. - nameinvalid + begin.+ + namestring diff --git a/test-cases/suite1/tests.json b/test-cases/suite1/tests.json index 2a4130fe..e49cc299 100644 --- a/test-cases/suite1/tests.json +++ b/test-cases/suite1/tests.json @@ -1443,7 +1443,7 @@ "value": "ust some text", "scopes": [ "text.test", - "comment" + "string" ] } ] @@ -1452,11 +1452,18 @@ "line": "which contains undefined and then", "tokens": [ { - "value": "which contains undefined and then", + "value": "w", "scopes": [ "text.test", "comment" ] + }, + { + "value": "hich contains undefined and then", + "scopes": [ + "text.test", + "string" + ] } ] }, @@ -1464,11 +1471,18 @@ "line": "more text", "tokens": [ { - "value": "more text", + "value": "m", "scopes": [ "text.test", "comment" ] + }, + { + "value": "ore text", + "scopes": [ + "text.test", + "string" + ] } ] }