Skip to content

Commit 0eff437

Browse files
authored
Use recommended lib loading; accept negative numbers (#4)
* Use recommended way of loading language lib * grammar.js: allow negative numbers
1 parent 6f43c65 commit 0eff437

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

grammar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ in the target code file.
457457
)
458458
),
459459

460-
number: $ => /\d+/,
460+
number: $ => seq(optional('-'), /\d+/),
461461

462462
comment: $ => token(prec(-1, seq(
463463
'--',

src/cedarscript_grammar/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import logging
22
import sys
33
from pathlib import Path
4+
from ctypes import cdll, c_void_p
5+
from os import fspath
46

57
from tree_sitter import Language
68

@@ -25,5 +27,8 @@ def language() -> Language:
2527
raise OSError(f"Unsupported platform: {sys.platform}")
2628

2729
language_path = str((_ROOT_DIR / lib_name).absolute())
28-
logger.warning(f"[{__name__}] Loading native CEDARScript parsing library from {language_path}")
29-
return Language(language_path, "CEDARScript")
30+
logger.warning(f"[{__name__}] Loading native CEDARScript parsing lib from {language_path}")
31+
lang_name = 'CEDARScript'
32+
language_function = getattr(cdll.LoadLibrary(fspath(language_path)), f"tree_sitter_{lang_name}")
33+
language_function.restype = c_void_p
34+
return Language(language_function(), name=lang_name)

0 commit comments

Comments
 (0)