@@ -68,64 +68,121 @@ It must be a function with two arguments: TYPE and NAME.")
68
68
(if (string= type " class" )
69
69
" *class definition*"
70
70
" *function definition*" ))
71
+
71
72
72
73
; ;; Keywords
73
74
74
- (defvar gdscript-ts--treesit-keywords '(" and" " as" " break" " class" " class_name"
75
- " const" " continue" " elif" " else" " enum" " export" " extends" " for" " func" " if" " in" " is"
76
- " master" " match" " not" " onready" " or" " pass" " puppet" " remote" " remotesync" " return" " setget" " signal"
77
- " var" " while" ))
75
+ (defvar gdscript-ts--keyword-regex
76
+ (rx bot (| " func" " var" " const" " set" " get" " setget" " signal" " extends"
77
+ " match" " if" " elif" " else" " for" " in" " while" " break" " continue"
78
+ " pass" " return" " when" " yield" " await"
79
+ " class" " class_name" " abstract" " is" " onready" " tool" " static"
80
+ " export" " as" " void" " enum" " assert" " breakpoint"
81
+ " sync" " remote" " master" " puppet"
82
+ " remotesync" " mastersync" " puppetsync"
83
+ " trait" " namespace" " super"
84
+ " and" " or" " not"
85
+ " await" " yield" " self" ) eot))
86
+
87
+ ; ;; Types
88
+
89
+ (defvar gdscript-ts--builtin-type-regex
90
+ " \\ `\\ (int\\ |bool\\ |float\\ |void\\ |Vector2\\ |Vector2i\\ |Vector3\\ |Vector3i\\ |Vector4\\ |Vector4i\\ |Color\\ |Rect2\\ |Rect2i\\ |Array\\ |Basis\\ |Dictionary\\ |Plane\\ |Quat\\ |RID\\ |Rect3\\ |Transform\\ |Transform2D\\ |Transform3D\\ |AABB\\ |String\\ |Color\\ |NodePath\\ |PoolByteArray\\ |PoolIntArray\\ |PoolRealArray\\ |PoolStringArray\\ |PoolVector2Array\\ |PoolVector3Array\\ |PoolColorArray\\ |bool\\ |int\\ |float\\ |Signal\\ |Callable\\ |StringName\\ |Quaternion\\ |Projection\\ |PackedByteArray\\ |PackedInt32Array\\ |PackedInt64Array\\ |PackedFloat32Array\\ |PackedFloat64Array\\ |PackedStringArray\\ |PackedVector2Array\\ |PackedVector2iArray\\ |PackedVector3Array\\ |PackedVector3iArray\\ |PackedVector4Array\\ |PackedColorArray\\ |JSON\\ |UPNP\\ |OS\\ |IP\\ |JSONRPC\\ |XRVRS\\ )\\ '" )
91
+
92
+ (defvar gdscript-ts--type-regex
93
+ " \\ `[A-Z][a-zA-Z0-9_]*[a-z][a-zA-Z0-9_]*\\' " )
94
+
95
+ ; ;; Constants
96
+
97
+ (defvar gdscript-ts--constant-regex " \\ `[A-Z_][A-Z0-9_]+\\' " )
78
98
79
-
80
99
; ;; Setting
81
100
101
+ (defvar gdscript-ts--feature-list
102
+ '(( comment definition)
103
+ ( keyword string type annotation)
104
+ ( number constant escape-sequence)
105
+ ( bracket delimiter function operator property)))
106
+
82
107
(defvar gdscript-ts--treesit-settings
83
108
(treesit-font-lock-rules
84
109
:language 'gdscript
85
110
:feature 'comment
86
111
'((comment) @font-lock-comment-face)
87
112
113
+ :language 'gdscript
114
+ :feature 'constant
115
+ `(([(null ) (false) (true)] @font-lock-constant-face)
116
+ (const_statement name: (name) @font-lock-constant-face)
117
+ (enumerator left: (identifier) @font-lock-constant-face)
118
+ ((identifier) @font-lock-constant-face
119
+ (:match , gdscript-ts--constant-regex @font-lock-constant-face))
120
+ (variable_statement
121
+ name: (name) @font-lock-constant-face
122
+ (:match , gdscript-ts--constant-regex @font-lock-constant-face)))
123
+
124
+ :language 'gdscript
125
+ :feature 'bracket
126
+ `([" [" " ]" " (" " )" " {" " }" ] @font-lock-bracket-face)
127
+
128
+ :language 'gdscript
129
+ :feature 'delimiter
130
+ `([" ," " :" " ." ] @font-lock-delimiter-face)
131
+
132
+ :language 'gdscript
133
+ :feature 'type
134
+ `(((identifier) @font-lock-builtin-face
135
+ (:match , gdscript-ts--builtin-type-regex @font-lock-builtin-face))
136
+ (get_node) @font-lock-builtin-face
137
+ ((identifier) @font-lock-type-face
138
+ (:match , gdscript-ts--type-regex @font-lock-type-face))
139
+ (enum_definition name: (_) @font-lock-type-face)
140
+ (class_name_statement (name) @font-lock-type-face)
141
+ (class_definition (name) @font-lock-type-face))
142
+
88
143
:language 'gdscript
89
144
:feature 'definition
90
- '((function_definition (name) @font-lock-function-name-face)
91
- (class_definition
92
- (name) @font-lock-function-name-face)
93
- (parameters (identifier) @font-lock-variable-name-face))
145
+ '((function_definition (name) @font-lock-function-name-face))
146
+
147
+ :language 'gdscript
148
+ :feature 'annotation
149
+ '((annotation " @" @font-lock-preprocessor-face
150
+ (identifier) @font-lock-preprocessor-face))
94
151
95
152
:language 'gdscript
96
153
:feature 'keyword
97
- `(([ ,@ gdscript-ts--treesit-keywords ] @font-lock-keyword-face)
98
- ([(false) (true)] @font-lock-keyword-face))
154
+ `((ERROR _ @font-lock-keyword-face ( :match , gdscript-ts--keyword-regex @font-lock-keyword-face) )
155
+ (_ _ @font-lock-keyword-face ( :match , gdscript-ts--keyword-regex @font-lock-keyword-face) ))
99
156
100
157
:language 'gdscript
101
158
:feature 'string
102
159
'((string ) @font-lock-string-face)
103
160
104
161
:language 'gdscript
105
- :feature 'type
106
- '(((type) @font-lock-type-face)
107
- (get_node) @font-lock-type-face)
108
-
109
162
:feature 'function
110
- :language 'gdscript
111
- '( (call (identifier) @font-lock-function-call-face)
163
+ '((call (identifier) @font-lock-builtin-face ( :match " preload " @font-lock-builtin-face))
164
+ (call (identifier) @font-lock-function-call-face)
112
165
(attribute_call (identifier) @font-lock-function-call-face))
113
166
114
167
:language 'gdscript
115
- :feature 'variable
116
- '((_ (name) @font-lock-variable-name-face))
117
-
118
168
:feature 'number
119
- :language 'gdscript
120
169
'(([(integer) (float )] @font-lock-number-face))
121
170
122
- :feature 'property
123
171
:language 'gdscript
172
+ :feature 'property
124
173
'((attribute (identifier) (identifier) @font-lock-property-use-face))
125
174
126
175
:feature 'operator
127
176
:language 'gdscript
128
- `([" +" " -" " *" " /" " ^" " >" " <" " =" ] @font-lock-operator-face)))
177
+ `([" +" " +=" " -" " -=" " *" " *=" " /" " /=" " ^" " ^=" " >" " >="
178
+ " <" " <=" " |" " |=" " %" " %=" " &" " &=" " >>" " >>=" " <<" " <<="
179
+ " ||" " &&" " ==" " !=" " ->" " ~" " =" " :=" ]
180
+ @font-lock-operator-face)
181
+
182
+ :language 'gdscript
183
+ :override t
184
+ :feature 'escape-sequence
185
+ '((escape_sequence) @font-lock-escape-face)))
129
186
130
187
131
188
; ;; Funtion
@@ -220,10 +277,7 @@ Similar to `gdscript-imenu-create-index' but use tree-sitter."
220
277
:syntax-table gdscript-mode-syntax-table
221
278
(when (treesit-ready-p 'gdscript )
222
279
(treesit-parser-create 'gdscript )
223
- (setq-local treesit-font-lock-feature-list
224
- '(( comment definition)
225
- ( keyword string type)
226
- ( function variable number property operator)))
280
+ (setq-local treesit-font-lock-feature-list gdscript-ts--feature-list)
227
281
(setq-local treesit-font-lock-settings gdscript-ts--treesit-settings)
228
282
; ;; TODO: create-imenu
229
283
(setq-local imenu-create-index-function
0 commit comments