-
Notifications
You must be signed in to change notification settings - Fork 0
/
highlights.scm
187 lines (142 loc) · 6.22 KB
/
highlights.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
;; *******************************************************************
;; Comments
;; *******************************************************************
[(block_comment) (line_comment)] @comment
;; *******************************************************************
;; Keywords
;; *******************************************************************
[
;; Reserved Words Core
"abstype" "and" "andalso" "as" "case" "datatype" "do" "else" "end"
"exception" "fn" "fun" "handle" "if" "in" "infix" "infixr" "let"
"local" "nonfix" "of" "op" "open" "orelse" "raise" "rec" "then"
"type" "val" "with" "withtype" "while"
;; Reserved Words Modules
"eqtype" "functor" "include" "sharing" "sig" "signature" "struct"
"structure" "where"
] @keyword
;; *******************************************************************
;; Reserved Words
;; *******************************************************************
;; Because tree-sitter uses context-sensitive scanning, a reserved word can be
;; parsed as an identifier if that reserved word cannot occur in a particular
;; context; for example, `val x = struct` is parsed as a valbind with `struct`
;; parsed as a vid. Highlight such misinterpreted identifiers.
([(vid) (tycon) (strid) (sigid) (fctid)] @warning
(#match? @warning "^(?:a(?:bstype|nd(?:also)?|s)|case|d(?:atatype|o)|e(?:lse|nd|qtype|xception)|f(?:n|un(?:ctor)?)|handle|i(?:n(?:clude|fixr?)|[fn])|l(?:et|ocal)|nonfix|o(?:pen|relse|[fp])|r(?:aise|ec)|s(?:haring|ig(?:nature)?|truct(?:ure)?)|t(?:hen|ype)|val|w(?:h(?:(?:er|il)e)|ith(?:type)?)|:|_|\\||=>|->|#)$"))
;; As an additional special case, The Defn of SML excludes `*` from tycon.
([(tycon)] @warning
(#match? @warning "^\\*$"))
;; *******************************************************************
;; Constants
;; *******************************************************************
[(integer_scon) (word_scon) (real_scon)] @number
[(string_scon) (char_scon)] @string
;; *******************************************************************
;; Tyvar Identifiers
;; *******************************************************************
;; binding occurrences
(tyvarseq (["(" "," ")"] @type.def)? (tyvar) @type.def)
;; *******************************************************************
;; Value Identifiers (Constructors)
;; *******************************************************************
;; Assume value identifiers starting with capital letter are constructors.
;; binding occurrences
(conbind name: ((vid) @variant.def
(#match? @variant.def "^[A-Z].*")))
(exbind name: ((vid) @variant.def
(#match? @variant.def "^[A-Z].*")))
(condesc name: ((vid) @variant.def
(#match? @variant.def "^[A-Z].*")))
(exdesc name: ((vid) @variant.def
(#match? @variant.def "^[A-Z].*")))
;; use occurrences
(vid_exp (longvid ((vid) @vid
(#match? @vid "^[A-Z].*"))) @variant.use)
(exbind def: (longvid ((vid) @vid
(#match? @vid "^[A-Z].*"))) @variant.use)
(vid_pat (longvid ((vid) @vid
(#match? @vid "^[A-Z].*"))) @variant.use)
;; "true", "false", "nil", "::", and "ref" are built-in constructors.
(vid_exp (longvid ((vid) @vid
(#match? @vid "^(true|false|nil|::|ref)$"))) @variant.builtin)
(vid_pat (longvid ((vid) @vid
(#match? @vid "^(true|false|nil|::|ref)$"))) @variant.builtin)
;; *******************************************************************
;; Value Identifiers
;; *******************************************************************
;; binding occurrences
(fmrule name: (vid) @variable)
(infix_dec (vid) @variable.def)
(infixr_dec (vid) @variable.def)
(nonfix_dec (vid) @variable.def)
(vid_pat (longvid . (vid) @variable.def))
(labvar_patrow (vid) @variable.def)
; (as_pat (vid) @variable.def)
(valdesc (vid) @variable)
;; use occurrences
(vid_exp (longvid) @variable.use)
(labvar_exprow (vid) @variable.use)
;; *******************************************************************
;; Tycon Identifiers
;; *******************************************************************
;; binding occurrences
(typbind name: (tycon) @type.def)
(datbind name: (tycon) @type.def)
(datarepl_dec name: (tycon) @type.def)
(wheretype_sigexp (longtycon) @type.def)
(typedesc (tycon) @type.def)
(datdesc (tycon) @type.def)
(datarepl_spec name: (tycon) @type.def)
(sharingtype_spec (longtycon) @type.def)
;; use occurrences: see `Types`
;; *******************************************************************
;; Structure Identifiers
;; *******************************************************************
;; binding occurrences
(strbind name: (strid) @module.def)
(strdesc (strid) @module.def)
(sharing_spec (longstrid) @type.def)
(fctbind (strid) @module.def)
;; use occurences
(open_dec (longstrid) @module.use)
(strid_strexp (longstrid) @module.use)
;; *******************************************************************
;; Signature Identifiers
;; *******************************************************************
;;; binding occurrences
(sigbind name: (sigid) @interface.def)
;;; use occurrencess
(sigid_sigexp (sigid) @interface)
(include_spec (sigid) @interface)
;; *******************************************************************
;; Functor Identifiers
;; *******************************************************************
;; binding occurrences
(fctbind name: (fctid) @module.def)
;; use occurrences
(fctapp_strexp (fctid) @module.def)
;; *******************************************************************
;; Types
;; *******************************************************************
(fn_ty "->" @type.use)
(tuple_ty "*" @type.use)
(paren_ty ["(" ")"] @type.use)
(tyvar_ty (tyvar) @type.use)
(record_ty
["{" "," "}"] @type.use
(tyrow [(lab) ":"] @type.use)?
(ellipsis_tyrow ["..." ":"] @type.use)?)
(tycon_ty
(tyseq ["(" "," ")"] @type.use)?
(longtycon) @type.use)
;; *******************************************************************
;; Labels
;; *******************************************************************
(recordsel_exp "#" @field)
(lab) @field
;; *******************************************************************
;; Punctuation
;; *******************************************************************
["(" ")" "[" "]" "{" "}"] @punctuation.bracket
["," ":" ";" "|" "=>" ":>"] @punctuation.delimiter