Skip to content

Commit 792ec44

Browse files
committed
Add support for 'is not' type test, fixes #318
1 parent d9d162c commit 792ec44

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## [4.3.1] 2024-08-24
4+
5+
### Added
6+
- Added support for "is not" type test
7+
38
## [4.3.0] 2024-08-18
49

510
### Added

gdtoolkit/parser/gdscript.lark

+3-3
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,9 @@ not_in_op: "not" "in"
223223
!?pow_expr: type_test ("**" asless_type_test)*
224224
| actual_type_cast ("**" asless_type_test)+
225225
!?asless_pow_expr: asless_type_test ("**" asless_type_test)*
226-
!?type_test: await_expr ("is" TYPE_HINT)*
227-
| actual_type_cast ("is" TYPE_HINT)+
228-
!?asless_type_test: await_expr ("is" TYPE_HINT)*
226+
!?type_test: await_expr (("is" | "is not") TYPE_HINT)*
227+
| actual_type_cast (("is" | "is not") TYPE_HINT)+
228+
!?asless_type_test: await_expr (("is" | "is not") TYPE_HINT)*
229229
!?await_expr: ("await")* call_expr
230230
?call_expr: attr_expr
231231
| (NAME | GET | SET) _call_arglist -> standalone_call

tests/formatter/input-output-pairs/type_test_expressions.in.gd

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ class X:
33
var x = 1 is int is bool
44
var y = 1 is int is bool is bool is bool is bool is bool is bool is bool is bool is bool is bool is bool is bool is bool
55
print([1,2.1] is Array[int])
6+
var z = 1 is not int
7+
var z1 = 1 is not int is not bool is not bool is not bool is not bool is not bool is not bool is not bool is not bool is not bool

tests/formatter/input-output-pairs/type_test_expressions.out.gd

+14
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,17 @@ class X:
1919
is bool
2020
)
2121
print([1, 2.1] is Array[int])
22+
var z = 1 is not int
23+
var z1 = (
24+
1
25+
is not int
26+
is not bool
27+
is not bool
28+
is not bool
29+
is not bool
30+
is not bool
31+
is not bool
32+
is not bool
33+
is not bool
34+
is not bool
35+
)

tests/valid-gd-scripts/expressions.gd

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func foo():
4444
~8
4545
5 ** 5
4646
x is int
47+
x is not int
4748
x is Xyz # TODO: fix/remove x.Type
4849
x is Zyx.Qwe # TODO: fix/remove x.Type
4950
x.attr

0 commit comments

Comments
 (0)