Skip to content

Commit 47e49c1

Browse files
HolonProductionScony
authored andcommitted
Add Unicode support.
Based on godotengine/godot#71676
1 parent 238230a commit 47e49c1

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

gdtoolkit/parser/gdscript.lark

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,13 @@ _NL: ( /\r?\n[\t ]*/ | COMMENT )+
267267
COMMENT: /#[^\n]*/
268268
LINE_CONT: /\\[\t \f]*\r?\n/
269269

270+
// UAX#31 with GDScript modifications.
271+
NAME: /[\p{XID_Start}_\u037a-\u037d\u309b-\u309f\ufe70-\ufe74\ufe76-\ufefc\u0000][\p{XID_Continue}_\u037a-\u037d\ufe76-\ufefc\u0000]*/
272+
270273
%declare _INDENT _DEDENT
271274

272275
%ignore WS_INLINE
273276
%ignore COMMENT
274277
%ignore LINE_CONT
275278

276279
%import common.WS_INLINE
277-
%import common.CNAME -> NAME

gdtoolkit/parser/parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def _get_parser(
9393
propagate_positions=add_metadata,
9494
maybe_placeholders=False,
9595
cache=cache_filepath,
96+
regex=True,
9697
)
9798

9899
return a_parser

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
},
3232
include_package_data=True,
3333
install_requires=[
34-
"lark-parser==0.12.0",
34+
"lark-parser[regex]==0.12.0",
3535
"docopt>=0.6.2",
3636
"pyyaml>=5.1",
3737
"radon>=5.1",

stubs/lark/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Tree:
3939
def pretty(self, indent_str: str = ...) -> str: ...
4040

4141
class Lark:
42-
def __init__(self, grammar: Any): ...
42+
def __init__(self, grammar: Any, **options): ...
4343
@classmethod
4444
def open(
4545
cls: Any, grammar_filename: str, rel_to: Optional[str] = ..., **options

tests/generated/test_expression_parsing.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import re
2+
13
import pytest
24
import hypothesis.extra.lark
35
from hypothesis import settings, given, HealthCheck
@@ -16,6 +18,14 @@
1618
'["+"] atom',
1719
'["+"] " " atom " "',
1820
)
21+
# hypothesis does not support the \p syntax
22+
simplified_gdscript_grammar = re.sub(
23+
r"NAME:.*$",
24+
r"%import common.CNAME -> NAME",
25+
simplified_gdscript_grammar,
26+
flags=re.MULTILINE,
27+
)
28+
print(simplified_gdscript_grammar)
1929
for keyword in ["as", "not", "await", "and", "else", "if", "or", "in"]:
2030
simplified_gdscript_grammar = simplified_gdscript_grammar.replace(
2131
f'"{keyword}"', f'" {keyword} "'
@@ -27,7 +37,7 @@
2737
simplified_gdscript_grammar = simplified_gdscript_grammar.replace(
2838
"%ignore COMMENT", ""
2939
)
30-
gdscript_lark = Lark(simplified_gdscript_grammar)
40+
gdscript_lark = Lark(simplified_gdscript_grammar, regex=True)
3141

3242

3343
def format_and_check_safety(input_code):

0 commit comments

Comments
 (0)