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