Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/grammars/sema.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
{
"include": "#comment"
},
{
"include": "#regex"
},
{
"include": "#string"
},
Expand Down Expand Up @@ -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": "#\\|",
Expand Down
13 changes: 13 additions & 0 deletions tests/syntax-highlight-sync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ describe('highlightToHtmlSync', () => {
expect(out).toContain('<span class="tok-builtin">tool/policy-subjects</span>')
})

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('</span><span class="tok-string">', '')
expect(out).toContain('<span class="tok-builtin">regex/match?</span>')
expect(out).toContain('<span class="tok-builtin">regex/match</span>')
expect(normalized).toContain('<span class="tok-string">#"\\d+"</span>')
expect(normalized).toContain('<span class="tok-string">#"\\"[^\\"]+\\""</span>')
})

it('supports non-sema languages too (json), unlike the old sema-only tokenizer', async () => {
await preloadLanguage('json')
const out = highlightToHtmlSync('{"a": 1}', 'json')
Expand Down