hare.vim (5296B)
1 " Vim syntax file. 2 " Language: Hare 3 " Maintainer: Amelia Clarke <selene@perilune.dev> 4 " Last Change: 2024-05-10 5 " Upstream: https://git.sr.ht/~sircmpwn/hare.vim 6 7 if exists('b:current_syntax') 8 finish 9 endif 10 syn include @haredoc syntax/haredoc.vim 11 let b:current_syntax = 'hare' 12 13 " Syntax {{{1 14 syn case match 15 syn iskeyword @,48-57,@-@,_ 16 17 " Keywords {{{2 18 syn keyword hareConditional else if match switch 19 syn keyword hareDefine def 20 syn keyword hareInclude use 21 syn keyword hareKeyword break continue return yield 22 syn keyword hareKeyword case 23 syn keyword hareKeyword const let 24 syn keyword hareKeyword defer 25 syn keyword hareKeyword export static 26 syn keyword hareKeyword fn 27 syn keyword hareOperator as is 28 syn keyword hareRepeat for 29 syn keyword hareTypedef type 30 31 " Attributes. 32 syn keyword hareAttribute @fini @init @test 33 syn keyword hareAttribute @offset @packed 34 syn keyword hareAttribute @symbol 35 syn keyword hareAttribute @threadlocal 36 37 " Builtins. 38 syn keyword hareBuiltin abort assert 39 syn keyword hareBuiltin align len offset 40 syn keyword hareBuiltin alloc free 41 syn keyword hareBuiltin append delete insert 42 syn keyword hareBuiltin vaarg vaend vastart 43 44 " Types {{{2 45 syn keyword hareType bool 46 syn keyword hareType done 47 syn keyword hareType f32 f64 48 syn keyword hareType i8 i16 i32 i64 int 49 syn keyword hareType never 50 syn keyword hareType opaque 51 syn keyword hareType rune str 52 syn keyword hareType u8 u16 u32 u64 uint 53 syn keyword hareType uintptr 54 syn keyword hareType valist 55 syn keyword hareType void 56 57 " Other types. 58 syn keyword hareStorageClass nullable 59 syn keyword hareStructure enum struct union 60 61 " Literals {{{2 62 syn keyword hareBoolean false true 63 syn keyword hareConstant null 64 65 " Integer literals. 66 syn match hareNumber '\v<%(0|[1-9]%(_?\d)*)%([Ee]\+?\d+)?%([iu]%(8|16|32|64)?|z)?>' display 67 syn match hareNumber '\v<0b[01]%(_?[01])*%([iu]%(8|16|32|64)?|z)?>' display 68 syn match hareNumber '\v<0o\o%(_?\o)*%([iu]%(8|16|32|64)?|z)?>' display 69 syn match hareNumber '\v<0x\x%(_?\x)*%([iu]%(8|16|32|64)?|z)?>' display 70 71 " Floating-point literals. 72 syn match hareFloat '\v<%(0|[1-9]%(_?\d)*)\.\d%(_?\d)*%([Ee][+-]?\d+)?%(f32|f64)?>' display 73 syn match hareFloat '\v<%(0|[1-9]%(_?\d)*)%([Ee][+-]?\d+)?%(f32|f64)>' display 74 syn match hareFloat '\v<0x\x%(_?\x)*%(\.\x%(_?\x)*)?[Pp][+-]?\d+%(f32|f64)?>' display 75 76 " Rune and string literals. 77 syn region hareRune start="'" skip="\\'" end="'" contains=hareEscape 78 syn region hareString start='"' skip='\\"' end='"' contains=hareEscape,hareFormat 79 syn region hareString start='`' end='`' contains=hareFormat 80 81 " Escape sequences. 82 syn match hareEscape '\\[0abfnrtv\\'"]' contained 83 syn match hareEscape '\v\\%(x\x{2}|u\x{4}|U\x{8})' contained display 84 85 " Format sequences. 86 syn match hareFormat '\v\{\d*%(:%(\.?\d+|[ +\-=Xbefgox]|F[.2ESUs]|_%(.|\\%([0abfnrtv\\'"]|x\x{2}|u\x{4}|U\x{8})))*)?}' contained contains=hareEscape display 87 syn match hareFormat '{\d*%\d*}' contained display 88 syn match hareFormat '{{\|}}' contained display 89 90 " Miscellaneous {{{2 91 92 " Comments. 93 syn region hareComment start='//' end='$' contains=hareTodo,@haredoc,@Spell display 94 syn keyword hareTodo FIXME TODO XXX contained 95 96 " Identifiers. 97 syn match hareDelimiter '::' display 98 syn match hareName '\<\h\w*\>' nextgroup=@harePostfix skipempty skipwhite transparent 99 100 " Labels. 101 syn match hareLabel ':\h\w*\>' display 102 103 " Match `size` as a type unless it is followed by an open paren. 104 syn match hareType '\<size\>' display 105 syn match hareBuiltin '\<size\ze(' display 106 107 " Postfix expressions. 108 syn cluster harePostfix contains=hareErrorTest,hareField,hareIndex,hareParens 109 syn match hareErrorTest '!=\@!' contained nextgroup=@harePostfix skipempty skipwhite 110 syn match hareErrorTest '?' nextgroup=@harePostfix skipempty skipwhite 111 syn match hareField '\.\w*\>'hs=s+1 contained contains=hareNumber nextgroup=@harePostfix skipempty skipwhite 112 syn region hareIndex start='\[' end=']' contained nextgroup=@harePostfix skipempty skipwhite transparent 113 syn region hareParens start='(' end=')' nextgroup=@harePostfix skipempty skipwhite transparent 114 115 " Whitespace errors. 116 syn match hareSpaceError '^ \+\ze\t' display 117 syn match hareSpaceError excludenl '\s\+$' containedin=ALL display 118 119 " Folding {{{3 120 syn region hareBlock start='{' end='}' fold transparent 121 122 " Default highlighting {{{1 123 hi def link hareAttribute PreProc 124 hi def link hareBoolean Boolean 125 hi def link hareBuiltin Operator 126 hi def link hareComment Comment 127 hi def link hareConditional Conditional 128 hi def link hareConstant Constant 129 hi def link hareDefine Define 130 hi def link hareDelimiter Delimiter 131 hi def link hareErrorTest Special 132 hi def link hareEscape SpecialChar 133 hi def link hareFloat Float 134 hi def link hareFormat SpecialChar 135 hi def link hareInclude Include 136 hi def link hareKeyword Keyword 137 hi def link hareLabel Special 138 hi def link hareNumber Number 139 hi def link hareOperator Operator 140 hi def link hareRepeat Repeat 141 hi def link hareRune Character 142 hi def link hareStorageClass StorageClass 143 hi def link hareString String 144 hi def link hareStructure Structure 145 hi def link hareTodo Todo 146 hi def link hareType Type 147 hi def link hareTypedef Typedef 148 149 " Highlight embedded haredoc references. 150 hi! def link haredocRefValid SpecialComment 151 152 " Highlight whitespace errors by default. 153 if get(g:, 'hare_space_error', 1) 154 hi def link hareSpaceError Error 155 endif 156 157 " vim: et sts=2 sw=2 ts=8