File: hare.vim

package info (click to toggle)
vim 2%3A9.1.2141-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 95,004 kB
  • sloc: ansic: 433,946; cpp: 6,440; makefile: 4,625; sh: 2,397; java: 2,312; xml: 2,099; python: 1,619; perl: 1,419; awk: 730; lisp: 501; cs: 458; objc: 369; csh: 9; sed: 8; haskell: 1
file content (262 lines) | stat: -rw-r--r-- 11,102 bytes parent folder | download
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
vim9script

# Vim syntax file.
# Language:    Hare
# Maintainer:  Amelia Clarke <selene@perilune.dev>
# Last Change: 2026 Feb 01
# Upstream:    https://git.sr.ht/~sircmpwn/hare.vim

if exists('b:current_syntax')
  finish
endif

# Syntax {{{1
syn case match
syn iskeyword @,48-57,@-@,_

# Identifiers {{{2
syn cluster hareIdentifier contains=hareName,hareScopeDelimiter,@hareReserved
syn match hareIdentifier '\v<\h\w*%(::\h\w*)*>' contains=@hareIdentifier nextgroup=hareScopeDelimiter,@harePostfix skipempty skipwhite
syn match hareName '\<\h\w*\>' contained transparent

# Reserved keywords.
syn cluster hareReserved contains=hareBoolean,hareBuiltin,hareConditional,hareConstant,hareDefine,hareInclude,hareKeyword,hareLabel,hareOperator,hareRepeat,hareStatement,hareStorageClass,hareStructure,hareType,hareTypedef

# Punctuators {{{2

# Balanced tokens.
syn region hareBraces matchgroup=hareBrace start='{' end='}' contains=TOP fold transparent
syn region hareBrackets matchgroup=hareBracket start='\[' end=']' contains=TOP transparent
syn region hareParens matchgroup=hareParen start='(' end=')' contains=TOP nextgroup=@harePostfix skipempty skipwhite transparent

# Symbolic operators.
syn match hareSymbolOperator '\.\{2,3}'
syn match hareSymbolOperator '[!<=>]=\?'
syn match hareSymbolOperator '=>'

# Additive and multiplicative arithmetic.
syn match hareSymbolOperator '[-+*/%]=\?'

# Bitwise arithmetic.
syn match hareSymbolOperator '\%(<<\|>>\)=\?'
syn match hareSymbolOperator '[&^|]=\?'
syn match hareSymbolOperator '\~'

# Logical arithmetic.
syn match hareSymbolOperator '\%(&&\|^^\|||\)=\?'

# Types {{{2
syn cluster hareType contains=hareArray,hareError,harePointer,hareStorageClass,hareStructure,hareTaggedUnion,hareType
syn keyword hareType bool
syn keyword hareType done
syn keyword hareType f32 f64
syn keyword hareType i8 i16 i32 i64 int
syn keyword hareType never
syn keyword hareType nomem
syn keyword hareType opaque
syn keyword hareType rune str
syn keyword hareType u8 u16 u32 u64 uint uintptr
syn keyword hareType void

# C ABI.
syn keyword hareType valist

# Pointer types.
syn match harePointer '*' contained containedin=hareTaggedUnion,hareTypeParens nextgroup=@hareType skipempty skipwhite
syn keyword hareStorageClass nullable nextgroup=harePointer skipempty skipwhite

# Slice and array types.
syn region hareArray matchgroup=hareBracket start='\[' end=']' contained containedin=hareTaggedUnion,hareTypeParens contains=TOP nextgroup=@hareType skipempty skipwhite transparent
syn match hareArray '\[[*_]]' contains=hareArrayBounds nextgroup=@hareType skipempty skipwhite transparent
syn match hareArrayBounds '*' contained display

# Tagged union and tuple types.
syn region hareTaggedUnion matchgroup=hareParen start='(' end=')' contained containedin=hareTaggedUnion,hareTypeParens contains=TOP transparent
syn match hareTaggedUnionBar '|' contained containedin=hareTaggedUnion

# Other types.
syn match hareError '!' contained containedin=hareTaggedUnion,hareTypeParens nextgroup=@hareType skipempty skipwhite
syn keyword hareStructure enum struct union

# Declarations {{{2
syn keyword hareDefine def
syn keyword hareInclude use
syn keyword hareKeyword export static
syn keyword hareKeyword fn nextgroup=@hareFunction,@hareReserved skipempty skipwhite
syn keyword hareStatement const let
syn keyword hareTypedef type nextgroup=hareTypedefBinding,@hareReserved skipempty skipwhite

# Highlight `const` as a storage-class in places types are expected.
syn keyword hareStorageClass const contained containedin=hareTaggedUnion,hareTypeParens nextgroup=@hareType skipempty skipwhite

# Function declarations.
syn cluster hareFunction contains=hareFunction,hareFunctionParams
syn match hareFunction '\v<\h\w*%(::\h\w*)*>' contained contains=@hareIdentifier nextgroup=hareFunctionParams skipempty skipwhite
syn region hareFunctionParams matchgroup=hareParen start='(' end=')' contained contains=TOP nextgroup=@hareType skipempty skipwhite transparent

# Type declarations.
# XXX: Does not yet account for type declarations with multiple bindings.
syn match hareTypedefBinding '\v<\h\w*%(::\h\w*)*>' contained nextgroup=hareTypedefEquals skipempty skipwhite transparent
syn match hareTypedefEquals '=' contained nextgroup=@hareType skipempty skipwhite transparent

# Attributes {{{3
syn keyword hareAttribute @init @fini @test
syn keyword hareAttribute @offset nextgroup=hareAttributeParens skipempty skipwhite
syn keyword hareAttribute @packed
syn keyword hareAttribute @symbol nextgroup=hareAttributeParens skipempty skipwhite
syn keyword hareAttribute @threadlocal

# Match the parens following attributes.
syn region hareAttributeParens matchgroup=hareParen start='(' end=')' contained contains=TOP transparent

# Expressions {{{2
syn keyword hareConditional else
syn keyword hareConditional if nextgroup=hareConditionParens skipempty skipwhite
syn keyword hareConditional match switch nextgroup=@hareCondition skipempty skipwhite
syn keyword hareLabel case nextgroup=@hareType skipempty skipwhite
syn keyword hareOperator as is nextgroup=@hareType skipempty skipwhite
syn keyword hareRepeat for nextgroup=@hareCondition skipempty skipwhite
syn keyword hareStatement break continue return yield
syn keyword hareStatement defer

# Match the parens in conditionals and loops.
syn cluster hareCondition contains=hareConditionLabel,hareConditionParens
syn match hareConditionLabel ':\h\w*\>' contained nextgroup=hareConditionParens skipempty skipwhite transparent
syn region hareConditionParens matchgroup=hareParen start='(' end=')' contained contains=TOP transparent

# Builtins {{{3
syn keyword hareBuiltin abort assert
syn keyword hareBuiltin align nextgroup=hareTypeParens skipempty skipwhite
syn keyword hareBuiltin alloc free
syn keyword hareBuiltin append insert delete
syn keyword hareBuiltin len offset

# C ABI.
syn keyword hareBuiltin vastart vaarg vaend

# Highlight `size` as a type unless it is followed by an open paren.
syn match hareType '\<size\>'
syn match hareBuiltin '\<size\ze(' nextgroup=hareTypeParens

# Match the parens in builtin expressions expecting a type.
syn region hareTypeParens matchgroup=hareParen start='(' end=')' contained contains=TOP nextgroup=@harePostfix skipempty skipwhite transparent

# Postfix expressions {{{3
# TODO: Match postfix expressions after literals.
syn cluster harePostfix contains=hareCast,hareField,hareSlice,hareSpecial

# Casts and type hints.
syn match hareCast ':' nextgroup=@hareType skipempty skipwhite

# Error checking.
syn match hareSpecial '!=\@!' contained nextgroup=@harePostfix skipempty skipwhite
syn match hareSpecial '?' nextgroup=@harePostfix skipempty skipwhite

# Field access.
syn match hareField '\.\w\+\>' contained contains=hareName,hareNumber,@hareReserved nextgroup=@harePostfix skipempty skipwhite transparent

# Indexing and slicing.
syn region hareSlice matchgroup=hareBracket start='\[' end=']' contained contains=TOP nextgroup=@harePostfix skipempty skipwhite transparent

# Literals {{{2
syn keyword hareBoolean true false
syn keyword hareConstant null

# Integers {{{3
syn match hareNumber '\v<%(0|[1-9]%(_?\d)*)%([Ee]\+?\d+)?%([iu]%(8|16|32|64)?|z)?>'
syn match hareNumber '\v<0b[01]%(_?[01])*%([iu]%(8|16|32|64)?|z)?>'
syn match hareNumber '\v<0o\o%(_?\o)*%([iu]%(8|16|32|64)?|z)?>'
syn match hareNumber '\v<0x\x%(_?\x)*%([iu]%(8|16|32|64)?|z)?>'

# Floats {{{3
# XXX: Technically, the third form is not a valid floating literal according to
#      the specification, but is currently accepted by the Hare compiler and
#      used occasionally within the standard library.
syn match hareFloat '\v<%(0|[1-9]%(_?\d)*)\.\d%(_?\d)*%([Ee][+-]?\d+)?%(f32|f64)?>'
syn match hareFloat '\v<%(0|[1-9]%(_?\d)*)%([Ee][+-]?\d+)?%(f32|f64)>'
syn match hareFloat '\v<%(0|[1-9]%(_?\d)*)[Ee]-\d+>'
syn match hareFloat '\v<0x\x%(_?\x)*%(\.\x%(_?\x)*)?[Pp][+-]?\d+%(f32|f64)?>'

# Rune and string literals {{{3
syn region hareRune matchgroup=hareRuneDelimiter start="'" skip="\\'" end="'" contains=hareEscape
syn region hareString matchgroup=hareStringDelimiter start='"' skip='\\"' end='"' contains=hareEscape,hareFormat
syn region hareString matchgroup=hareStringDelimiter start='`' end='`' contains=hareFormat

# Escape sequences.
syn match hareEscape '\\[0abfnrtv\\'"]' contained
syn match hareEscape '\v\\%(x\x{2}|u\x{4}|U\x{8})' contained display

# Format sequences.
syn match hareFormat '\v\{\d*%(:%(\.?\d+|[- +=befgoxX]|F[.2EsSU]|_%(\_[^\\]|\\%([0abfnrtv\\'"]|x\x{2}|u\x{4}|U\x{8})))*)?}' contained contains=hareEscape
syn match hareFormat '{\d*%\d*}' contained display
syn match hareFormat '{{\|}}' contained

# Miscellaneous {{{2

# Annotations.
syn region hareAnnotation start='#\[' end=']' contains=hareAnnotationIdentifier,hareComment,hareRune,hareString
syn match hareAnnotationIdentifier '\v#\[\s*\zs\h\w*%(::\h\w*)*>' contained contains=hareName,@hareReserved nextgroup=hareAnnotationParens skipempty skipwhite
syn region hareAnnotationParens matchgroup=hareAnnotationParen start='(' end=')' contained contains=TOP

# Comments.
syn region hareComment excludenl start='//' end='$' contains=hareSpecialComment,hareTodo,@Spell
syn match hareSpecialComment '\v\[\[\h\w*%(::\h\w*)*%(::)?]]' contained contains=@NoSpell display
syn keyword hareTodo FIXME TODO XXX contained

# Scope delimiters.
syn match hareScopeDelimiter '::'

# User labels.
syn match hareUserLabel ':\h\w*\>' contains=hareName,@hareReserved

# Default highlighting {{{1
hi def link hareAnnotation Special
hi def link hareAnnotationIdentifier hareAnnotation
hi def link hareAnnotationParen hareAnnotation
hi def link hareArrayBounds harePointer
hi def link hareAttribute PreProc
hi def link hareBoolean Boolean
hi def link hareBuiltin hareOperator
hi def link hareComment Comment
hi def link hareConditional Conditional
hi def link hareConstant Constant
hi def link hareDefine Define
hi def link hareError hareSpecial
hi def link hareEscape SpecialChar
hi def link hareFloat Float
hi def link hareFormat SpecialChar
hi def link hareFunction Function
hi def link hareInclude Include
hi def link hareKeyword Keyword
hi def link hareLabel Label
hi def link hareNumber Number
hi def link hareOperator Operator
hi def link harePointer hareStorageClass
hi def link hareRepeat Repeat
hi def link hareRune Character
hi def link hareRuneDelimiter hareRune
hi def link hareScopeDelimiter Delimiter
hi def link hareSpecial Special
hi def link hareSpecialComment SpecialComment
hi def link hareStatement Statement
hi def link hareStorageClass StorageClass
hi def link hareString String
hi def link hareStringDelimiter hareString
hi def link hareStructure Structure
hi def link hareTodo Todo
hi def link hareType Type
hi def link hareTypedef Typedef
hi def link hareUserLabel Identifier

# Highlight incorrect whitespace by default.
syn match hareSpaceError excludenl '\s\+$' containedin=ALL display
syn match hareSpaceError ' \+\ze\t' display
if get(g:, 'hare_space_error', 1)
  hi! def link hareSpaceError Error
else
  hi! def link hareSpaceError NONE
endif

b:current_syntax = 'hare'

# vim: fdm=marker et sts=2 sw=2 ts=8 tw=80