Skip to content

Commit fa0419a

Browse files
committed
Add highlights.scm queries and ci
1 parent 89d4b39 commit fa0419a

File tree

4 files changed

+692
-2
lines changed

4 files changed

+692
-2
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ jobs:
2424
run: |
2525
tree-sitter generate
2626
27-
- name: Run tests
27+
- name: Run parse tests
2828
run: |
2929
tree-sitter test
3030
31+
- name: Run highlight tests
32+
run: |
33+
tree-sitter highlight --paths test/highlight_paths_file.txt
34+

queries/highlights.scm

Lines changed: 325 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,325 @@
1+
;; Comments
2+
(one_line_comment) @comment
3+
(block_comment) @comment
4+
5+
6+
;; Strings
7+
(string_literal) @string
8+
(quoted_string) @string ; `include strings
9+
(system_lib_string) @string
10+
11+
12+
;; Keywords
13+
(["begin" "end" "this"]) @keyword
14+
(["input" "output" "inout" "ref"]) @keyword
15+
(["alias" "and" "assert" "assign" "assume" "before" "bind" "binsof" "break"
16+
"case" "checker" "class" "class" "clocking" "config" "const" "constraint"
17+
"cover" "covergroup" "coverpoint" "cross" "default" "defparam" "disable"
18+
"do" "else" "endcase" "endchecker" "endclass" "endclocking" "endconfig"
19+
"endfunction" "endgenerate" "endgroup" "endinterface" "endmodule"
20+
"endpackage" "endprogram" "endproperty" "endsequence" "endtask" "enum"
21+
"extends" "extern" "final" "first_match" "for" "force" "foreach" "forever"
22+
"fork" "forkjoin" "function" "generate" "genvar" "if" "iff" "illegal_bins"
23+
"implements" "import" "initial" "inside" "interconnect" "interface"
24+
"intersect" "join" "join_any" "join_none" "local" "localparam" "matches"
25+
"modport" "new" "null" "option" "or" "package" "packed" "parameter"
26+
"program" "property" "pure" "randcase" "randomize" "release" "repeat"
27+
"return" "sequence" "showcancelled" "soft" "solve" "struct" "super" "tagged"
28+
"task" "timeprecision" "timeunit" "type" "typedef" "union" "unique"
29+
"virtual" "wait" "while" "with"
30+
(always_keyword) ; always, always_comb, always_latch, always_ff
31+
(bins_keyword) ; bins, illegal_bins, ignore_bins
32+
(case_keyword) ; case, casez, casex
33+
(class_item_qualifier) ; static, protected, local
34+
(edge_identifier) ; posedge, negedge, edge
35+
(lifetime) ; static, automatic
36+
(module_keyword) ; module, macromodule
37+
(random_qualifier) ; rand, randc
38+
(unique_priority)]) @keyword ; unique, unique0, priority
39+
40+
41+
;; Preprocessor directives and macro usage
42+
(["`include" "`define" "`ifdef" "`ifndef" "`timescale" "`default_nettype"
43+
"`elsif" "`undef" (resetall_compiler_directive) (undefineall_compiler_directive)
44+
"`endif" "`else" "`unconnected_drive" (celldefine_compiler_directive)
45+
(endcelldefine_compiler_directive) (endkeywords_directive) "`line"
46+
"`begin_keywords" "`pragma" "`__FILE__" "`__LINE__"]) @string.special
47+
(text_macro_usage
48+
(simple_identifier) @string.special)
49+
50+
51+
;; Delimiters, operators
52+
([";" ":" "," "::"
53+
"=" "?" "|=" "&=" "^="
54+
"|->" "|=>" "->"
55+
":=" ":/" "-:" "+:"]) @punctuation.delimiter
56+
(["(" ")"]) @punctuation.bracket
57+
(["[" "]"]) @punctuation.bracket
58+
(["{" "}" "'{"]) @punctuation.bracket
59+
60+
(["."] @operator)
61+
(["+" "-" "*" "/" "%" "**"]) @operator
62+
(["<" "<=" ">" ">="]) @operator
63+
(["===" "!==" "==" "!="]) @operator
64+
(["&&" "||" "!"]) @operator
65+
(["~" "&" "~&" "|" "~|" "^" "~^"]) @operator
66+
(["<<" ">>" "<<<" ">>>"]) @operator
67+
68+
(["@" "#" "##"]) @operator
69+
(assignment_operator) @operator
70+
(unary_operator) @operator
71+
(inc_or_dec_operator) @operator
72+
(stream_operator) @operator
73+
(event_trigger) @operator
74+
(["->" "->>"]) @operator
75+
76+
77+
;; Declarations
78+
;; Module/interface/program/package/class/checker
79+
(module_nonansi_header
80+
name: (simple_identifier) @function)
81+
(module_ansi_header
82+
name: (simple_identifier) @function)
83+
(interface_nonansi_header
84+
name: (simple_identifier) @function)
85+
(interface_ansi_header
86+
name: (simple_identifier) @function)
87+
(program_nonansi_header
88+
name: (simple_identifier) @function)
89+
(program_ansi_header
90+
name: (simple_identifier) @function)
91+
(package_declaration
92+
name: (simple_identifier) @function)
93+
(class_declaration
94+
name: (simple_identifier) @function)
95+
(interface_class_declaration
96+
name: (simple_identifier) @function)
97+
(checker_declaration
98+
name: (simple_identifier) @function)
99+
(class_declaration
100+
(class_type
101+
(simple_identifier) @type)) ; Parent class
102+
;; Function/task/methods
103+
(function_body_declaration
104+
name: (simple_identifier) @function)
105+
(task_body_declaration
106+
name: (simple_identifier) @function)
107+
(function_prototype
108+
(data_type_or_void)
109+
name: (simple_identifier) @function)
110+
(task_prototype
111+
name: (simple_identifier) @function)
112+
(class_scope ; Definition of extern defined methods
113+
(class_type
114+
(simple_identifier)) @function)
115+
116+
117+
;; Types
118+
[(integer_vector_type) ; bit, logic, reg
119+
(integer_atom_type) ; byte, shortint, int, longint, integer, time
120+
(non_integer_type) ; shortreal, real, realtime
121+
(net_type) ; supply0, supply1, tri, triand, trior, trireg, tri0, tri1, uwire, wire, wand, wor
122+
["string" "event" "signed" "unsigned" "chandle"]] @type
123+
(data_type_or_implicit
124+
(data_type
125+
(simple_identifier)) @type)
126+
(data_type
127+
(class_type
128+
(simple_identifier) @type
129+
(parameter_value_assignment)))
130+
(data_type
131+
(class_type
132+
(simple_identifier) @operator
133+
(simple_identifier) @type))
134+
(net_port_header
135+
(net_port_type
136+
(simple_identifier) @type))
137+
(variable_port_header
138+
(variable_port_type
139+
(data_type
140+
(simple_identifier) @type)))
141+
(["void'" (data_type_or_void)]) @type ; void cast of task called as a function
142+
(interface_port_header ; Interfaces with modports
143+
interface_name: (simple_identifier) @type
144+
modport_name: (simple_identifier) @type)
145+
(type_assignment
146+
name: (simple_identifier) @type)
147+
(net_declaration ; User type variable declaration
148+
(simple_identifier) @type)
149+
(enum_base_type ; Enum base type with user type
150+
(simple_identifier) @type)
151+
152+
153+
;; Instances
154+
;; Module names
155+
(module_instantiation
156+
instance_type: (simple_identifier) @module)
157+
(interface_instantiation
158+
instance_type: (simple_identifier) @module)
159+
(program_instantiation
160+
instance_type: (simple_identifier) @module)
161+
(checker_instantiation
162+
instance_type: (simple_identifier) @module)
163+
(udp_instantiation
164+
instance_type: (simple_identifier) @module)
165+
(gate_instantiation
166+
[(cmos_switchtype)
167+
(mos_switchtype)
168+
(enable_gatetype)
169+
(n_input_gatetype)
170+
(n_output_gatetype)
171+
(pass_en_switchtype)
172+
(pass_switchtype)
173+
"pulldown" "pullup"]
174+
@module)
175+
;; Instance names
176+
(name_of_instance
177+
instance_name: (simple_identifier) @constant)
178+
;; Instance parameters
179+
(module_instantiation
180+
(parameter_value_assignment
181+
(list_of_parameter_value_assignments
182+
(named_parameter_assignment
183+
(simple_identifier) @constant))))
184+
(module_instantiation
185+
(parameter_value_assignment
186+
(list_of_parameter_value_assignments
187+
(ordered_parameter_assignment
188+
(param_expression
189+
(data_type
190+
(simple_identifier) @constant))))))
191+
;; Port names
192+
(named_port_connection
193+
port_name: (simple_identifier) @constant)
194+
(named_parameter_assignment
195+
(simple_identifier) @constant)
196+
(named_checker_port_connection
197+
port_name: (simple_identifier) @constant)
198+
;; Bind statements
199+
(bind_directive
200+
(bind_target_scope
201+
(simple_identifier) @constant))
202+
203+
204+
;; Numbers
205+
(hex_number
206+
size: (unsigned_number) @number
207+
base: (hex_base) @punctuation.delimiter)
208+
(decimal_number
209+
size: (unsigned_number) @number
210+
base: (decimal_base) @punctuation.delimiter)
211+
(octal_number
212+
size: (unsigned_number) @number
213+
base: (octal_base) @punctuation.delimiter)
214+
(binary_number
215+
size: (unsigned_number) @number
216+
base: (binary_base) @punctuation.delimiter)
217+
;; Same as before but without the width (width extension)
218+
(hex_number
219+
base: (hex_base) @punctuation.delimiter)
220+
(decimal_number
221+
base: (decimal_base) @punctuation.delimiter)
222+
(octal_number
223+
base: (octal_base) @punctuation.delimiter)
224+
(binary_number
225+
base: (binary_base) @punctuation.delimiter)
226+
227+
228+
;; Arrays
229+
(unpacked_dimension
230+
[(constant_expression) (constant_range)] @number)
231+
(packed_dimension
232+
(constant_range) @number)
233+
(select
234+
(constant_range) @number)
235+
(constant_select
236+
(constant_range
237+
(constant_expression) @number))
238+
(constant_bit_select
239+
(constant_expression) @number)
240+
(bit_select
241+
(expression) @number)
242+
(indexed_range
243+
(expression) @number
244+
(constant_expression) @number)
245+
(constant_indexed_range
246+
(constant_expression) @number)
247+
(value_range ; inside {[min_range:max_range]}, place here to apply override
248+
(expression) @constant)
249+
(dynamic_array_new
250+
(expression) @constant)
251+
252+
253+
;; Misc
254+
;; Timeunit
255+
((time_unit) @constant.builtin)
256+
;; Enum labels
257+
(enum_name_declaration
258+
(simple_identifier) @constant.builtin)
259+
;; Case item label (not radix)
260+
(case_item_expression
261+
(expression
262+
(primary
263+
(hierarchical_identifier
264+
(simple_identifier) @constant.builtin))))
265+
;; Hierarchical references, interface signals, class members, package scope
266+
(hierarchical_identifier
267+
(simple_identifier) @punctuation.delimiter
268+
"."
269+
(simple_identifier))
270+
(method_call
271+
(primary) @punctuation.delimiter
272+
(["." "::"])
273+
(method_call_body))
274+
(package_scope
275+
(simple_identifier) @punctuation.delimiter)
276+
(method_call
277+
(primary
278+
(select
279+
(simple_identifier) @punctuation.delimiter))
280+
(method_call_body))
281+
;; Attributes
282+
(["(*" "*)"] @constant)
283+
(attribute_instance
284+
(attr_spec (simple_identifier) @attribute))
285+
;; Typedefs
286+
(type_declaration
287+
(class_type (simple_identifier) @type)
288+
type_name: (simple_identifier) @constant)
289+
(type_declaration
290+
type_name: (simple_identifier) @constant)
291+
("typedef" "class" (simple_identifier) @constant)
292+
;; Coverpoint & cross labels
293+
(cover_point
294+
name: (simple_identifier) @constant)
295+
(cover_cross
296+
name: (simple_identifier) @constant)
297+
;; Loop variables (foreach[i])
298+
(loop_variables
299+
(simple_identifier) @constant)
300+
;; Bins values
301+
(bins_or_options
302+
(expression
303+
(primary
304+
(concatenation
305+
(expression) @constant))))
306+
;; Bins ranges
307+
(covergroup_value_range
308+
(expression) @constant)
309+
;; Queue dimension
310+
(("$") @punctuation.special)
311+
;; Parameterized classes (e.g: uvm_config_db #(axi_stream_agent_config))
312+
(class_type
313+
(parameter_value_assignment
314+
(list_of_parameter_value_assignments) @punctuation.delimiter))
315+
316+
317+
;; System-tf
318+
([(system_tf_identifier) ; System task/function
319+
"$fatal" "$error" "$warning" "$info" ; (severity_system_task)
320+
"$stop" "$finish" "$exit"]) ; (simulation_control_task)
321+
@function.builtin
322+
323+
324+
;; Errors
325+
(ERROR) @error

0 commit comments

Comments
 (0)