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