Skip to content

Commit fdd3296

Browse files
committed
small fixes
1 parent f9c3b92 commit fdd3296

2 files changed

Lines changed: 49 additions & 9 deletions

File tree

editors/code/src/languages/syntaxes/tolk.tmLanguage.test.ts

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as path from "node:path"
44
interface GrammarPattern {
55
readonly name?: string
66
readonly match?: string
7+
readonly captures?: Record<string, GrammarPattern>
78
readonly begin?: string
89
readonly beginCaptures?: Record<string, GrammarPattern>
910
readonly end?: string
@@ -15,18 +16,57 @@ interface TolkGrammar {
1516
}
1617

1718
describe("Tolk TextMate grammar", () => {
18-
it("scopes integer literals with separators", () => {
19+
it("scopes integer literals with compiler-compatible separators", () => {
1920
const grammar = readTolkGrammar()
2021
const numericPattern = grammar.patterns.find(pattern => pattern.name === "constant.numeric")
2122
const numericRegex = new RegExp(numericPattern?.match ?? "", "u")
2223

2324
expect(numericRegex.exec("100_000")?.[0]).toBe("100_000")
2425
expect(numericRegex.exec("0xFF_FF")?.[0]).toBe("0xFF_FF")
2526
expect(numericRegex.exec("0b1010_0011")?.[0]).toBe("0b1010_0011")
27+
expect(numericRegex.exec("123_")?.[0]).toBe("123_")
28+
expect(numericRegex.exec("0b0_____1")?.[0]).toBe("0b0_____1")
29+
expect(numericRegex.exec("0b_0____1")?.[0]).toBe("0b_0____1")
30+
expect(numericRegex.exec("0x")?.[0]).toBe("0x")
31+
expect(numericRegex.exec("0b")?.[0]).toBe("0b")
32+
expect(numericRegex.exec("0x_FF")?.[0]).toBe("0x_FF")
33+
expect(numericRegex.exec("0b_")?.[0]).toBe("0b_")
2634

27-
expect(numericRegex.exec("100_")).toBeNull()
28-
expect(numericRegex.exec("0x_FF")).toBeNull()
29-
expect(numericRegex.exec("0b_1010")).toBeNull()
35+
expect(numericRegex.exec("_100")).toBeNull()
36+
})
37+
38+
it("scopes only ordinary string escapes accepted by the compiler", () => {
39+
const grammar = readTolkGrammar()
40+
const stringPattern = grammar.patterns.find(
41+
pattern => pattern.name === "string.quoted.double.tolk",
42+
)
43+
const escapePattern = stringPattern?.patterns?.find(
44+
pattern => pattern.name === "constant.character.escape.tolk",
45+
)
46+
const escapeRegex = new RegExp(escapePattern?.match ?? "", "u")
47+
48+
for (const validEscape of ["\\n", "\\r", "\\t", "\\\\", "\\'", '\\"']) {
49+
expect(escapeRegex.exec(validEscape)?.[0]).toBe(validEscape)
50+
}
51+
52+
expect(escapeRegex.exec("\\0")).toBeNull()
53+
expect(escapeRegex.exec("\\u")).toBeNull()
54+
expect(escapeRegex.exec("\\u1234")).toBeNull()
55+
})
56+
57+
it("keeps triple-quoted string escapes broad for asm strings", () => {
58+
const grammar = readTolkGrammar()
59+
const stringPattern = grammar.patterns.find(
60+
pattern => pattern.name === "string.quoted.triple.tolk",
61+
)
62+
const escapePattern = stringPattern?.patterns?.find(
63+
pattern => pattern.name === "constant.character.escape.tolk",
64+
)
65+
const escapeRegex = new RegExp(escapePattern?.match ?? "", "u")
66+
67+
for (const escape of ["\\n", "\\0", "\\u", "\\u1234", "\\x"]) {
68+
expect(escapeRegex.exec(escape)?.[0]).toBe(escape.slice(0, 2))
69+
}
3070
})
3171

3272
it("scopes dotted annotation names without scoping dots", () => {

syntaxes/tolk.tmLanguage.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
3-
"name": "tolk",
3+
"name": "Tolk",
44
"scopeName": "source.tolk",
55
"foldingStartMarker": "\\{\\s*$",
66
"foldingStopMarker": "^\\s*\\}",
@@ -33,13 +33,13 @@
3333
"patterns": [
3434
{
3535
"name": "constant.character.escape.tolk",
36-
"match": "\\\\([nrt0\\\\'\"u]|u[0-9a-fA-F]{4})"
36+
"match": "\\\\([nrt\\\\'\"])"
3737
}
3838
]
3939
},
4040
{
4141
"name": "constant.numeric",
42-
"match": "\\b(-?(0x[0-9a-fA-F](?:_?[0-9a-fA-F])*|0b[01](?:_?[01])*|[0-9](?:_?[0-9])*))\\b"
42+
"match": "\\b(-?(0x[0-9a-fA-F_]*|0b[01_]*|[0-9][0-9_]*))\\b"
4343
},
4444
{
4545
"name": "keyword.control",
@@ -51,7 +51,7 @@
5151
},
5252
{
5353
"name": "keyword.other",
54-
"match": "\\b(import|export|namespace|true|false|null|redef|mutate|tolk|as|is|!is|private|readonly|contract)\\b"
54+
"match": "\\b(import|export|namespace|true|false|null|mutate|tolk|as|is|private|readonly|contract)\\b"
5555
},
5656
{
5757
"name": "keyword.other",
@@ -100,7 +100,7 @@
100100
},
101101
{
102102
"name": "entity.name.function",
103-
"match": "(`[^`]+`|[a-zA-Z$_][a-zA-Z0-9$_]*)(?=\\s*(?:<[^>]+>)?\\s*\\()"
103+
"match": "(?<!\\.)(`[^`]+`|[a-zA-Z$_][a-zA-Z0-9$_]*)(?=\\s*(?:<[^()\\n]*>)?\\s*\\()"
104104
},
105105
{
106106
"name": "entity.name.type",

0 commit comments

Comments
 (0)