Skip to content

Commit 11d4035

Browse files
committed
feat: support cython
1 parent e58b08d commit 11d4035

File tree

8 files changed

+604
-0
lines changed

8 files changed

+604
-0
lines changed

book/src/generated/lang-support.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
| csv || | | | | |
3737
| cue || | | | | `cuelsp` |
3838
| cylc |||| | | |
39+
| cython || ||| | |
3940
| d |||| | | `serve-d` |
4041
| dart |||| | | `dart` |
4142
| dbml || | | | | |

languages.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4605,3 +4605,16 @@ comment-tokens = ["#"]
46054605
[[grammar]]
46064606
name = "properties"
46074607
source = { git = "https://github.com/tree-sitter-grammars/tree-sitter-properties", rev = "579b62f5ad8d96c2bb331f07d1408c92767531d9" }
4608+
4609+
[[language]]
4610+
name = "cython"
4611+
scope = "source.cython"
4612+
file-types = ["pxd", "pxi", "pyx"]
4613+
comment-token = "#"
4614+
roots = ["pyproject.toml", "setup.py", "poetry.lock"]
4615+
indent = { tab-width = 4, unit = " " }
4616+
grammar = "cython"
4617+
4618+
[[grammar]]
4619+
name = "cython"
4620+
source = { git = "https://github.com/b0o/tree-sitter-cython", rev = "62f44f5e7e41dde03c5f0a05f035e293bcf2bcf8" }

runtime/queries/cython/folds.scm

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[
2+
(function_definition)
3+
(class_definition)
4+
(while_statement)
5+
(for_statement)
6+
(if_statement)
7+
(with_statement)
8+
(try_statement)
9+
(match_statement)
10+
(import_from_statement)
11+
(parameters)
12+
(argument_list)
13+
(parenthesized_expression)
14+
(generator_expression)
15+
(list_comprehension)
16+
(set_comprehension)
17+
(dictionary_comprehension)
18+
(tuple)
19+
(list)
20+
(set)
21+
(dictionary)
22+
(string)
23+
] @fold
24+
25+
[
26+
(import_statement)
27+
(import_from_statement)
28+
]+ @fold
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
; Punctuation
2+
3+
["," "." ":" ";" (ellipsis)] @punctuation.delimiter
4+
["(" ")" "[" "]" "{" "}"] @punctuation.bracket
5+
(interpolation
6+
"{" @punctuation.special
7+
"}" @punctuation.special)
8+
9+
; Identifier naming conventions
10+
11+
(identifier) @variable
12+
13+
((identifier) @constructor
14+
(#match? @constructor "^[A-Z]"))
15+
16+
((identifier) @constant
17+
(#match? @constant "^[A-Z][A-Z_]*$"))
18+
19+
; Function calls
20+
21+
(decorator) @function
22+
23+
(call
24+
function: (attribute attribute: (identifier) @function.method))
25+
(call
26+
function: (identifier) @function)
27+
28+
; Builtin functions
29+
30+
((call
31+
function: (identifier) @function.builtin)
32+
(#any-of?
33+
@function.builtin
34+
"abs" "all" "any" "ascii" "bin" "bool" "breakpoint" "bytearray" "bytes" "callable" "chr" "classmethod" "compile" "complex" "delattr" "dict" "dir" "divmod" "enumerate" "eval" "exec" "filter" "float" "format" "frozenset" "getattr" "globals" "hasattr" "hash" "help" "hex" "id" "input" "int" "isinstance" "issubclass" "iter" "len" "list" "locals" "map" "max" "memoryview" "min" "next" "object" "oct" "open" "ord" "pow" "print" "property" "range" "repr" "reversed" "round" "set" "setattr" "slice" "sorted" "staticmethod" "str" "sum" "super" "tuple" "type" "vars" "zip" "__import__"))
35+
36+
; Types
37+
38+
(maybe_typed_name
39+
type: ((_) @type))
40+
41+
(type
42+
(identifier) @type)
43+
44+
(c_type
45+
type: ((_) @type))
46+
(c_type
47+
((identifier) @type))
48+
(c_type
49+
((int_type) @type))
50+
51+
(maybe_typed_name
52+
name: ((identifier) @variable))
53+
54+
; Function definitions
55+
56+
(function_definition
57+
name: (identifier) @function)
58+
59+
(cdef_statement
60+
(cvar_def
61+
(maybe_typed_name
62+
name: ((identifier) @function))
63+
(c_function_definition)))
64+
65+
(cvar_decl
66+
(c_type
67+
([(identifier) (int_type)]))
68+
(c_name
69+
((identifier) @function))
70+
(c_function_definition))
71+
72+
(attribute attribute: (identifier) @property)
73+
74+
; Literals
75+
76+
[
77+
(none)
78+
] @constant.builtin
79+
80+
[
81+
(true)
82+
(false)
83+
] @boolean
84+
85+
[
86+
(integer)
87+
(float)
88+
] @number
89+
90+
(comment) @comment
91+
(string) @string
92+
(escape_sequence) @escape
93+
94+
(interpolation
95+
"{" @punctuation.special
96+
"}" @punctuation.special) @embedded
97+
98+
[
99+
"-"
100+
"-="
101+
"!="
102+
"*"
103+
"**"
104+
"**="
105+
"*="
106+
"/"
107+
"//"
108+
"//="
109+
"/="
110+
"&"
111+
"&="
112+
"%"
113+
"%="
114+
"^"
115+
"^="
116+
"+"
117+
"->"
118+
"+="
119+
"<"
120+
"<<"
121+
"<<="
122+
"<="
123+
"<>"
124+
"="
125+
":="
126+
"=="
127+
">"
128+
">="
129+
">>"
130+
">>="
131+
"|"
132+
"|="
133+
"~"
134+
"@="
135+
"and"
136+
"in"
137+
"is"
138+
"not"
139+
"or"
140+
"@"
141+
] @operator
142+
143+
[
144+
"as"
145+
"assert"
146+
"async"
147+
"await"
148+
"break"
149+
"class"
150+
"continue"
151+
"def"
152+
"del"
153+
"elif"
154+
"else"
155+
"except"
156+
"exec"
157+
"finally"
158+
"for"
159+
"from"
160+
"global"
161+
"if"
162+
"import"
163+
"lambda"
164+
"nonlocal"
165+
"pass"
166+
"print"
167+
"raise"
168+
"return"
169+
"try"
170+
"while"
171+
"with"
172+
"yield"
173+
"match"
174+
"case"
175+
176+
; cython-specific
177+
"cdef"
178+
"cpdef"
179+
"ctypedef"
180+
"cimport"
181+
"nogil"
182+
"gil"
183+
"extern"
184+
"inline"
185+
"public"
186+
"readonly"
187+
"struct"
188+
"union"
189+
"enum"
190+
"fused"
191+
"property"
192+
"namespace"
193+
"cppclass"
194+
"const"
195+
] @keyword.control
196+
197+
(dotted_name
198+
(identifier)* @namespace)
199+
200+
(aliased_import
201+
alias: (identifier) @namespace)
202+

0 commit comments

Comments
 (0)