Skip to content

Commit a6343a5

Browse files
authored
feat: Add Purescript support (#591)
1 parent ac27f21 commit a6343a5

File tree

6 files changed

+219
-1
lines changed

6 files changed

+219
-1
lines changed

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,3 +606,9 @@
606606
update = none
607607
ignore = dirty
608608
branch = master
609+
[submodule "repos/purescript"]
610+
path = repos/purescript
611+
url = https://github.com/postsolar/tree-sitter-purescript
612+
update = none
613+
ignore = dirty
614+
branch = main

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

3-
## Unreleased
3+
# Unreleased
4+
#- Add `Purescript` support
45

56
## 0.12.190 - 2024-05-06
67

queries/purescript/highlights.scm

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
; ------------------------------------------------------------------------------
2+
; Literals and comments
3+
4+
[
5+
(integer)
6+
(exp_negation)
7+
] @number
8+
9+
(exp_literal
10+
(number)) @float
11+
12+
(char) @character
13+
14+
[
15+
(string)
16+
(triple_quote_string)
17+
] @string
18+
19+
(comment) @comment @spell
20+
21+
; ------------------------------------------------------------------------------
22+
; Punctuation
23+
24+
[
25+
"("
26+
")"
27+
"{"
28+
"}"
29+
"["
30+
"]"
31+
] @punctuation.bracket
32+
33+
[
34+
(comma)
35+
";"
36+
(qualified_module) ; grabs the `.` (dot), ex: import System.IO
37+
"."
38+
] @punctuation.delimiter
39+
40+
41+
; ------------------------------------------------------------------------------
42+
; Keywords, operators, includes
43+
44+
[
45+
"if"
46+
"then"
47+
"else"
48+
"case"
49+
"of"
50+
] @conditional
51+
52+
[
53+
"import"
54+
"module"
55+
] @include
56+
57+
[
58+
(operator)
59+
(constructor_operator)
60+
(type_operator)
61+
(all_names)
62+
"="
63+
"|"
64+
"::"
65+
""
66+
"=>"
67+
""
68+
"<="
69+
""
70+
"->"
71+
""
72+
"<-"
73+
""
74+
"\\"
75+
"`"
76+
"@"
77+
] @operator
78+
79+
(qualified_module
80+
(module) @constructor)
81+
82+
(module) @namespace
83+
84+
(qualified_type
85+
(module) @namespace)
86+
87+
(qualified_variable
88+
(module) @namespace)
89+
90+
(import
91+
(module) @namespace)
92+
93+
[
94+
(where)
95+
"let"
96+
"in"
97+
"class"
98+
"instance"
99+
"derive"
100+
"foreign"
101+
"data"
102+
"newtype"
103+
"type"
104+
"as"
105+
"hiding"
106+
"do"
107+
"ado"
108+
"forall"
109+
""
110+
"infix"
111+
"infixl"
112+
"infixr"
113+
] @keyword
114+
115+
(class_instance
116+
"else" @keyword)
117+
118+
(type_role_declaration
119+
"role" @keyword
120+
role: (type_role) @type.qualifier)
121+
122+
(hole) @character.special
123+
124+
; `_` wildcards in if-then-else and case-of expressions,
125+
; as well as record updates and operator sections
126+
(wildcard) @parameter
127+
128+
; ------------------------------------------------------------------------------
129+
; Functions and variables
130+
131+
(variable) @variable
132+
(exp_apply
133+
.
134+
(exp_name
135+
(variable) @function))
136+
137+
(exp_apply
138+
.
139+
(exp_name
140+
(qualified_variable
141+
(variable) @function)))
142+
143+
(row_field
144+
(field_name) @field)
145+
146+
(record_field
147+
(field_name) @field)
148+
149+
(record_field
150+
(field_pun) @field)
151+
152+
(record_accessor
153+
field: [ (variable)
154+
(string)
155+
(triple_quote_string)
156+
] @variable.other.member)
157+
158+
(exp_record_access
159+
field: [ (variable)
160+
(string)
161+
(triple_quote_string)
162+
] @variable.other.member)
163+
164+
(signature
165+
name: (variable) @type)
166+
167+
(kind_declaration
168+
(class_name) @type)
169+
170+
(function
171+
name: (variable) @function)
172+
173+
(foreign_import
174+
(variable) @function)
175+
176+
(class_instance
177+
(instance_name) @function)
178+
179+
(derive_declaration
180+
(instance_name) @function)
181+
182+
((variable) @boolean
183+
(#any-of? @boolean "true" "false"))
184+
185+
; The former one works for `tree-sitter highlight` but not in Helix/Kakoune.
186+
; The latter two work in Helix (but not Kakoune) and are a good compromise between not highlighting anything at all
187+
; as an operator and leaving it to the child nodes, and highlighting everything as an operator.
188+
(exp_ticked
189+
(_) @operator)
190+
191+
(exp_ticked
192+
(exp_name
193+
(variable) @operator))
194+
195+
(exp_ticked
196+
(exp_name
197+
(qualified_variable
198+
(variable) @operator)))
199+
200+
; ------------------------------------------------------------------------------
201+
; Types
202+
203+
(type) @type
204+
205+
(constructor) @constructor

queries/purescript/locals.scm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(signature name: (variable)) @definition.type
2+
(function name: (variable)) @definition.function
3+
(pat_name (variable)) @definition
4+
(exp_name (variable)) @reference

repos/purescript

Submodule purescript added at daf9b3e

tree-sitter-langs.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ See `tree-sitter-langs-repos'."
186186
(org-mode . org)
187187
(pascal-mode . pascal)
188188
(perl-mode . perl)
189+
(purescript-mode . purescript)
189190
(cperl-mode . perl)
190191
(php-mode . php)
191192
(qss-mode . css)

0 commit comments

Comments
 (0)