Skip to content

Commit 1c94f25

Browse files
authored
feat(tolk): support ?? operator from Tolk 1.3 (#256)
Fixes #255
1 parent 975c6c2 commit 1c94f25

7 files changed

Lines changed: 32463 additions & 30954 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
========================================================================
2+
Null coalescing operator ?? — Basic
3+
========================================================================
4+
fun main() {
5+
val a: int?;
6+
val b: int;
7+
val c = a ?? b;
8+
//! ^ int
9+
}
10+
------------------------------------------------------------------------
11+
ok
12+
13+
========================================================================
14+
Null coalescing operator ?? — Left is Null
15+
========================================================================
16+
fun main() {
17+
val a: null;
18+
val b: int;
19+
val c = a ?? b;
20+
//! ^ int
21+
}
22+
------------------------------------------------------------------------
23+
ok
24+
25+
========================================================================
26+
Null coalescing operator ?? — Left is not Nullable
27+
========================================================================
28+
fun main() {
29+
val a: int;
30+
val b: bool;
31+
val c = a ?? b;
32+
//! ^ int | bool
33+
}
34+
------------------------------------------------------------------------
35+
ok
36+
37+
========================================================================
38+
Null coalescing operator ?? — Right side type
39+
========================================================================
40+
fun main() {
41+
val a: int?;
42+
val b: bool;
43+
val c = a ?? b;
44+
//! ^ int | bool
45+
}
46+
------------------------------------------------------------------------
47+
ok
48+
49+
========================================================================
50+
Null coalescing operator ?? — Smart cast in RHS
51+
========================================================================
52+
fun main() {
53+
val a: int?;
54+
val c =
55+
//! ^ int?
56+
a ?? a;
57+
//! ^ null
58+
}
59+
------------------------------------------------------------------------
60+
ok
61+
62+
========================================================================
63+
Null coalescing operator ?? — Incomplete
64+
========================================================================
65+
fun main() {
66+
val a: int?;
67+
val c = a ??;
68+
//! ^ int?
69+
}
70+
------------------------------------------------------------------------
71+
ok

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ const TOLK_GRAMMAR = {
443443

444444
binary_operator: $ =>
445445
choice(
446+
prec.right(10, seq($._expression, field("operator_name", "??"), $._expression)),
446447
prec.left(
447448
13,
448449
seq($._expression, field("operator_name", choice("&&", "||")), $._expression),

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

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/src/languages/tolk/tree-sitter-tolk/src/node-types.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)