Skip to content

Commit 961aad0

Browse files
committed
feat(tolk): support string type from Tolk 1.3
Fixes #257
1 parent bca0f23 commit 961aad0

14 files changed

Lines changed: 181 additions & 46 deletions

File tree

editors/code/src/languages/syntaxes/tolk.tmLanguage.json

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,26 @@
1616
"end": "\\*/"
1717
},
1818
{
19-
"name": "string.quoted.double",
19+
"name": "string.quoted.triple.tolk",
20+
"begin": "\"\"\"",
21+
"end": "\"\"\"",
22+
"patterns": [
23+
{
24+
"name": "constant.character.escape.tolk",
25+
"match": "\\\\."
26+
}
27+
]
28+
},
29+
{
30+
"name": "string.quoted.double.tolk",
2031
"begin": "\"",
21-
"end": "\""
32+
"end": "\"",
33+
"patterns": [
34+
{
35+
"name": "constant.character.escape.tolk",
36+
"match": "\\\\([nrt0\\\\'\"u]|u[0-9a-fA-F]{4})"
37+
}
38+
]
2239
},
2340
{
2441
"name": "constant.numeric",
@@ -30,11 +47,11 @@
3047
},
3148
{
3249
"name": "keyword.operator",
33-
"match": "\\+|-|\\*|/|%|\\?|:|,|;|\\(|\\)|\\[|\\]|{|}|=|<|>|!|&|\\||\\^|==|!=|<=|>=|<<|>>|&&|\\|\\||~/|\\^/|\\+=|-=|\\*=|/=|%=|&=|\\|=|\\^=|->|<=>|~>>|\\^>>|<<=|>>=|=>"
50+
"match": "\\+|-|\\*|/|%|\\?|:|,|;|\\(|\\)|\\[|\\]|{|}|=|<|>|!|&|\\||\\^|==|!=|<=|>=|<<|>>|&&|\\|\\||~/|\\^/|\\+=|-=|\\*=|/=|%=|&=|\\|=|\\^=|->|<=>|~>>|\\^>>|<<=|>>=|=>|\\?\\?"
3451
},
3552
{
3653
"name": "keyword.other",
37-
"match": "\\b(import|export|true|false|null|redef|mutate|tolk|as|is|!is|private|readonly)\\b"
54+
"match": "\\b(import|export|true|false|null|redef|mutate|tolk|as|is|!is|private|readonly|string)\\b"
3855
},
3956
{
4057
"name": "keyword.other",
@@ -45,7 +62,7 @@
4562
"match": "\\b[TU]\\b"
4663
},
4764
{
48-
"match": "\\b(val|var)\\s+(?:type|enum|int|map|cell|Cell|void|dict|bool|any_address|slice|tuple|builder|continuation|never|coins|address|int\\d+|uint\\d+|bits\\d+|bytes\\d+)\\b",
65+
"match": "\\b(val|var)\\s+(?:type|enum|int|map|cell|Cell|void|dict|bool|any_address|slice|string|tuple|builder|continuation|never|coins|address|int\\d+|uint\\d+|bits\\d+|bytes\\d+)\\b",
4966
"captures": {
5067
"1": {"name": "storage.modifier"}
5168
}
@@ -56,7 +73,7 @@
5673
},
5774
{
5875
"name": "storage.type",
59-
"match": "\\b(type|enum|int|map|cell|Cell|void|dict|bool|any_address|slice|tuple|builder|continuation|never|coins|int\\d+|uint\\d+|bits\\d+|bytes\\d+)\\b"
76+
"match": "\\b(type|enum|int|map|cell|Cell|void|dict|bool|any_address|slice|string|tuple|builder|continuation|never|coins|int\\d+|uint\\d+|bits\\d+|bytes\\d+)\\b"
6077
},
6178
{
6279
"name": "storage.type",

server/src/e2e/tolk/testcases/types/basic.test

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Ternary expression type inference with different types
5555
========================================================================
5656
fun main(cond: bool) {
5757
val b = cond ? 10 : "hello";
58-
//! ^ int | slice
58+
//! ^ int | string
5959
}
6060
------------------------------------------------------------------------
6161
ok
@@ -227,7 +227,7 @@ String literal type inference
227227
========================================================================
228228
fun main() {
229229
val data = "hello";
230-
//! ^ slice
230+
//! ^ string
231231
}
232232
------------------------------------------------------------------------
233233
ok
@@ -270,7 +270,7 @@ Tuple literal type inference
270270
========================================================================
271271
fun main() {
272272
val data = [1, true, "hello"];
273-
//! ^ [int, bool, slice]
273+
//! ^ [int, bool, string]
274274
}
275275
------------------------------------------------------------------------
276276
ok
@@ -280,7 +280,7 @@ Tensor literal type inference
280280
========================================================================
281281
fun main() {
282282
val data = (1, true, "hello");
283-
//! ^ (int, bool, slice)
283+
//! ^ (int, bool, string)
284284
}
285285
------------------------------------------------------------------------
286286
ok
@@ -290,7 +290,7 @@ Complex tensor literal type inference
290290
========================================================================
291291
fun main() {
292292
val data = (1, [1, [1, true, "hello"], (1, [1, [1, true, "hello"], "hello"], "hello")], "hello");
293-
//! ^ (int, [int, [int, bool, slice], (int, [int, [int, bool, slice], slice], slice)], slice)
293+
//! ^ (int, [int, [int, bool, string], (int, [int, [int, bool, string], string], string)], string)
294294
}
295295
------------------------------------------------------------------------
296296
ok
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
========================================================================
2+
String type — Basic
3+
========================================================================
4+
fun main() {
5+
val s: string = "hello";
6+
//! ^ string
7+
}
8+
------------------------------------------------------------------------
9+
ok
10+
11+
========================================================================
12+
String type — Multiline
13+
========================================================================
14+
fun main() {
15+
val s: string =
16+
//! ^ string
17+
"""
18+
multiline
19+
string
20+
""";
21+
}
22+
------------------------------------------------------------------------
23+
ok
24+
25+
========================================================================
26+
String type — Escapes
27+
========================================================================
28+
fun main() {
29+
val s: string = "hello\nworld\t\"quoted\"";
30+
//! ^ string
31+
}
32+
------------------------------------------------------------------------
33+
ok

server/src/e2e/tolk/testcases/types2/auto-return-type.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ ok
4444
Auto return type: two returns with different type
4545
========================================================================
4646
fun test(cond: bool) {
47-
//! ^ (bool) -> slice | int
47+
//! ^ (bool) -> string | int
4848
if (cond) {
4949
return "hello";
5050
}
@@ -53,9 +53,9 @@ fun test(cond: bool) {
5353

5454
fun main() {
5555
val res =
56-
//! ^ slice | int
56+
//! ^ string | int
5757
test(true);
58-
//! ^ (bool) -> slice | int
58+
//! ^ (bool) -> string | int
5959
}
6060
------------------------------------------------------------------------
6161
ok

server/src/e2e/tolk/testcases/types2/expressions.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Tuple literal expression
1717
========================================================================
1818
fun main() {
1919
val a = [1, true, ""];
20-
//! ^ [int, bool, slice]
20+
//! ^ [int, bool, string]
2121
}
2222
------------------------------------------------------------------------
2323
ok
@@ -27,7 +27,7 @@ Tensor literal type inference
2727
========================================================================
2828
fun main() {
2929
val data = (1, true, "hello");
30-
//! ^ (int, bool, slice)
30+
//! ^ (int, bool, string)
3131
}
3232
------------------------------------------------------------------------
3333
ok
@@ -37,7 +37,7 @@ Complex tensor and tuple literal type inference
3737
========================================================================
3838
fun main() {
3939
val data = (1, [1, [1, true, "hello"], (1, [1, [1, true, "hello"], "hello"], "hello")], "hello");
40-
//! ^ (int, [int, [int, bool, slice], (int, [int, [int, bool, slice], slice], slice)], slice)
40+
//! ^ (int, [int, [int, bool, string], (int, [int, [int, bool, string], string], string)], string)
4141
}
4242
------------------------------------------------------------------------
4343
ok

server/src/e2e/tolk/testcases/types2/generic-deduce.test

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fun generic<T, U, V>(a: T, b: U, c: V): [T | U, V] {}
9292

9393
fun main() {
9494
val foo = generic(1, true, "");
95-
//! ^ [int | bool, slice]
95+
//! ^ [int | bool, string]
9696
}
9797
------------------------------------------------------------------------
9898
ok
@@ -214,7 +214,7 @@ fun main() {
214214
val foo1 = 10.generic();
215215
//! ^ int
216216
val foo2 = "hello".generic();
217-
//! ^ slice
217+
//! ^ string
218218
}
219219
------------------------------------------------------------------------
220220
ok
@@ -228,7 +228,7 @@ fun main() {
228228
val foo1 = 10.generic();
229229
//! ^ int
230230
val foo2 = "hello".generic();
231-
//! ^ slice
231+
//! ^ string
232232
}
233233
------------------------------------------------------------------------
234234
ok
@@ -240,7 +240,7 @@ fun T.generic<U>(a: U): T | U {}
240240

241241
fun main() {
242242
val foo = int.generic("hello");
243-
//! ^ int | slice
243+
//! ^ int | string
244244
}
245245
------------------------------------------------------------------------
246246
ok
@@ -252,7 +252,7 @@ fun T.generic<U>(self, a: U): T | U {}
252252

253253
fun main() {
254254
val foo = 10.generic("hello");
255-
//! ^ int | slice
255+
//! ^ int | string
256256
}
257257
------------------------------------------------------------------------
258258
ok

server/src/e2e/tolk/testcases/types2/literals.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ String literal type
2020
========================================================================
2121
fun main() {
2222
val a = "hello";
23-
//! ^ slice
23+
//! ^ string
2424
}
2525
------------------------------------------------------------------------
2626
ok

server/src/e2e/tolk/testcases/types2/smartcasts.test

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -323,17 +323,17 @@ ok
323323
Assign smartcast
324324
========================================================================
325325
fun main(): void {
326-
val name: int | slice = 10;
327-
//! ^ int | slice
326+
val name: int | string = 10;
327+
//! ^ int | string
328328

329329
name;
330330
//! ^ int
331331

332332
name = "";
333-
//! ^ int | slice
333+
//! ^ int | string
334334

335335
name;
336-
//! ^ slice
336+
//! ^ string
337337
}
338338
------------------------------------------------------------------------
339339
ok
@@ -342,17 +342,17 @@ ok
342342
Assign smartcast with tuple
343343
========================================================================
344344
fun main(): void {
345-
val [name: int | slice] = [10];
346-
//! ^ int | slice
345+
val [name: int | string] = [10];
346+
//! ^ int | string
347347

348348
name;
349349
//! ^ int
350350

351351
name = "";
352-
//! ^ int | slice
352+
//! ^ int | string
353353

354354
name;
355-
//! ^ slice
355+
//! ^ string
356356
}
357357
------------------------------------------------------------------------
358358
ok
@@ -362,10 +362,10 @@ Assign smartcast with tensor
362362
========================================================================
363363
fun main(): void {
364364
val (
365-
name: int | slice,
366-
//! ^ int | slice
367-
other: slice?
368-
//! ^ slice?
365+
name: int | string,
366+
//! ^ int | string
367+
other: string?
368+
//! ^ string?
369369
) = (10, null);
370370

371371
name;
@@ -374,14 +374,14 @@ fun main(): void {
374374
//! ^ null
375375

376376
name = "";
377-
//! ^ int | slice
377+
//! ^ int | string
378378
other = "";
379-
//! ^ slice?
379+
//! ^ string?
380380

381381
name;
382-
//! ^ slice
382+
//! ^ string
383383
other;
384-
//! ^ slice
384+
//! ^ string
385385
}
386386
------------------------------------------------------------------------
387387
ok

server/src/e2e/tolk/testcases/types2/vars.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fun main() {
1717
b,
1818
//! ^ bool
1919
c] = [1, true, ""];
20-
//! ^ slice
20+
//! ^ string
2121
}
2222
------------------------------------------------------------------------
2323
ok

server/src/languages/tolk/tree-sitter-tolk/grammar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ const TOLK_GRAMMAR = {
665665
token(
666666
choice(
667667
seq('"""', repeat(choice(/[^"]/, /"[^"]/, /""[^"]/)), '"""'),
668-
/"(?:[^"\\\n]|\\.)*"/, // sing quote
668+
seq('"', repeat(choice(/[^"\\\n]/, /\\./)), '"'),
669669
),
670670
),
671671
boolean_literal: $ => choice("true", "false"),

0 commit comments

Comments
 (0)