From d2ca3465008b05522972fad8168d08509c65a8d5 Mon Sep 17 00:00:00 2001 From: Helge Sverre Date: Mon, 10 Aug 2026 22:32:51 +0200 Subject: [PATCH] fix: scope Sema regex literals --- src/grammars/sema.tmLanguage.json | 14 ++++++++++++++ tests/syntax-highlight-sync.test.ts | 13 +++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/grammars/sema.tmLanguage.json b/src/grammars/sema.tmLanguage.json index 8f03646..c4b2d25 100644 --- a/src/grammars/sema.tmLanguage.json +++ b/src/grammars/sema.tmLanguage.json @@ -9,6 +9,9 @@ { "include": "#comment" }, + { + "include": "#regex" + }, { "include": "#string" }, @@ -50,6 +53,17 @@ } ], "repository": { + "regex": { + "name": "string.regexp.sema", + "begin": "#\"", + "end": "\"", + "patterns": [ + { + "name": "string.regexp.sema", + "match": "\\\\." + } + ] + }, "block-comment": { "name": "comment.block.sema", "begin": "#\\|", diff --git a/tests/syntax-highlight-sync.test.ts b/tests/syntax-highlight-sync.test.ts index f911dd2..a3825a4 100644 --- a/tests/syntax-highlight-sync.test.ts +++ b/tests/syntax-highlight-sync.test.ts @@ -30,6 +30,19 @@ describe('highlightToHtmlSync', () => { expect(out).toContain('tool/policy-subjects') }) + it('classifies complete raw regex literals and regex builtins', async () => { + await preloadLanguage('sema') + const out = highlightToHtmlSync( + '(regex/match? #"\\d+" text)\n(regex/match #"\\\"[^\\\"]+\\\"" text)', + 'sema', + ) + const normalized = out.replaceAll('', '') + expect(out).toContain('regex/match?') + expect(out).toContain('regex/match') + expect(normalized).toContain('#"\\d+"') + expect(normalized).toContain('#"\\"[^\\"]+\\""') + }) + it('supports non-sema languages too (json), unlike the old sema-only tokenizer', async () => { await preloadLanguage('json') const out = highlightToHtmlSync('{"a": 1}', 'json')