blob: 07cf33fb119f799c6bb5ae689738e623d4ce5c97 [file] [log] [blame]
Bram Moolenaar9fbdbb82022-09-27 17:30:34 +01001" PRELUDE {{{1
2" Vim syntax file
3" Language: Hare
4" Maintainer: Amelia Clarke <me@rsaihe.dev>
5" Last Change: 2022-09-21
6
7if exists("b:current_syntax")
8 finish
9endif
10let b:current_syntax = "hare"
11
12" SYNTAX {{{1
13syn case match
14
15" KEYWORDS {{{2
16syn keyword hareConditional if else match switch
17syn keyword hareKeyword break continue return yield
18syn keyword hareKeyword defer
19syn keyword hareKeyword fn
20syn keyword hareKeyword let
21syn keyword hareLabel case
22syn keyword hareOperator as is
23syn keyword hareRepeat for
24syn keyword hareStorageClass const def export nullable static
25syn keyword hareStructure enum struct union
26syn keyword hareTypedef type
27
28" C ABI.
29syn keyword hareKeyword vastart vaarg vaend
30
31" BUILTINS {{{2
32syn keyword hareBuiltin abort
33syn keyword hareBuiltin alloc free
34syn keyword hareBuiltin append delete insert
35syn keyword hareBuiltin assert
36syn keyword hareBuiltin len offset
37
38" TYPES {{{2
39syn keyword hareType bool
40syn keyword hareType char str
41syn keyword hareType f32 f64
42syn keyword hareType u8 u16 u32 u64 i8 i16 i32 i64
43syn keyword hareType uint int
44syn keyword hareType rune
45syn keyword hareType uintptr
46syn keyword hareType void
47
48" C ABI.
49syn keyword hareType valist
50
51" LITERALS {{{2
52syn keyword hareBoolean true false
53syn keyword hareNull null
54
55" Number literals.
56syn match hareNumber "\v(\.@1<!|\.\.)\zs<\d+([Ee][+-]?\d+)?(z|[iu](8|16|32|64)?)?>" display
57syn match hareNumber "\v(\.@1<!|\.\.)\zs<0b[01]+(z|[iu](8|16|32|64)?)?>" display
58syn match hareNumber "\v(\.@1<!|\.\.)\zs<0o\o+(z|[iu](8|16|32|64)?)?>" display
59syn match hareNumber "\v(\.@1<!|\.\.)\zs<0x\x+(z|[iu](8|16|32|64)?)?>" display
60
61" Floating-point number literals.
62syn match hareFloat "\v<\d+\.\d+([Ee][+-]?\d+)?(f32|f64)?>" display
63syn match hareFloat "\v<\d+([Ee][+-]?\d+)?(f32|f64)>" display
64
65" String and rune literals.
66syn match hareEscape "\\[\\'"0abfnrtv]" contained display
67syn match hareEscape "\v\\(x\x{2}|u\x{4}|U\x{8})" contained display
68syn match hareFormat "\v\{\d*(\%\d*|(:[ 0+-]?\d*(\.\d+)?[Xbox]?))?}" contained display
69syn match hareFormat "\({{\|}}\)" contained display
70syn region hareRune start="'" end="'\|$" skip="\\'" contains=hareEscape display extend
71syn region hareString start=+"+ end=+"\|$+ skip=+\\"+ contains=hareEscape,hareFormat display extend
72syn region hareString start="`" end="`\|$" contains=hareFormat display
73
74" MISCELLANEOUS {{{2
75syn keyword hareTodo FIXME TODO XXX contained
76
77" Attributes.
78syn match hareAttribute "@[a-z]*"
79
80" Blocks.
81syn region hareBlock start="{" end="}" fold transparent
82
83" Comments.
84syn region hareComment start="//" end="$" contains=hareCommentDoc,hareTodo,@Spell display keepend
85syn region hareCommentDoc start="\[\[" end="]]\|\ze\_s" contained display
86
87" The size keyword can be either a builtin or a type.
88syn match hareBuiltin "\v<size>\ze(\_s*//.*\_$)*\_s*\(" contains=hareComment
89syn match hareType "\v<size>((\_s*//.*\_$)*\_s*\()@!" contains=hareComment
90
91" Trailing whitespace.
92syn match hareSpaceError "\v\s+$" display excludenl
93syn match hareSpaceError "\v\zs +\ze\t" display
94
95" Use statement.
96syn region hareUse start="\v^\s*\zsuse>" end=";" contains=hareComment display
97
98syn match hareErrorAssertion "\v(^([^/]|//@!)*\)\_s*)@<=!\=@!"
99syn match hareQuestionMark "?"
100
101" DEFAULT HIGHLIGHTING {{{1
102hi def link hareAttribute Keyword
103hi def link hareBoolean Boolean
104hi def link hareBuiltin Function
105hi def link hareComment Comment
106hi def link hareCommentDoc SpecialComment
107hi def link hareConditional Conditional
108hi def link hareEscape SpecialChar
109hi def link hareFloat Float
110hi def link hareFormat SpecialChar
111hi def link hareKeyword Keyword
112hi def link hareLabel Label
113hi def link hareNull Constant
114hi def link hareNumber Number
115hi def link hareOperator Operator
116hi def link hareQuestionMark Special
117hi def link hareRepeat Repeat
118hi def link hareRune Character
119hi def link hareStorageClass StorageClass
120hi def link hareString String
121hi def link hareStructure Structure
122hi def link hareTodo Todo
123hi def link hareType Type
124hi def link hareTypedef Typedef
125hi def link hareUse PreProc
126
127hi def link hareSpaceError Error
128autocmd InsertEnter * hi link hareSpaceError NONE
129autocmd InsertLeave * hi link hareSpaceError Error
130
131hi def hareErrorAssertion ctermfg=red cterm=bold guifg=red gui=bold
132
133" vim: tabstop=8 shiftwidth=2 expandtab