Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

263 lines
11 KiB
VimL
Raw Permalink Normal View History

2025-09-08 15:30:41 -04:00
vim9script
# Vim syntax file.
# Language: Hare
# Maintainer: Amelia Clarke <selene@perilune.dev>
# Last Change: 2026 Feb 15
2025-09-08 15:30:41 -04:00
# Upstream: https://git.sr.ht/~sircmpwn/hare.vim
2022-09-27 17:30:34 +01:00
2024-05-24 08:05:00 +02:00
if exists('b:current_syntax')
2022-09-27 17:30:34 +01:00
finish
endif
2025-09-08 15:30:41 -04:00
# Syntax {{{1
2022-09-27 17:30:34 +01:00
syn case match
2024-05-24 08:05:00 +02:00
syn iskeyword @,48-57,@-@,_
2022-09-27 17:30:34 +01:00
2026-02-06 09:44:16 +00:00
# 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
2025-09-08 15:30:41 -04:00
# Reserved keywords.
2026-02-06 09:44:16 +00:00
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 '\%(&&\|^^\|||\)=\?'
2024-05-24 08:05:00 +02:00
2025-09-08 15:30:41 -04:00
# Types {{{2
2026-02-06 09:44:16 +00:00
syn cluster hareType contains=hareArray,hareError,harePointer,hareStorageClass,hareStructure,hareTaggedUnion,hareType
2022-09-27 17:30:34 +01:00
syn keyword hareType bool
2024-05-24 08:05:00 +02:00
syn keyword hareType done
2022-09-27 17:30:34 +01:00
syn keyword hareType f32 f64
2024-05-24 08:05:00 +02:00
syn keyword hareType i8 i16 i32 i64 int
syn keyword hareType never
2025-09-08 15:30:41 -04:00
syn keyword hareType nomem
2024-05-24 08:05:00 +02:00
syn keyword hareType opaque
syn keyword hareType rune str
2025-09-08 15:30:41 -04:00
syn keyword hareType u8 u16 u32 u64 uint uintptr
2022-09-27 17:30:34 +01:00
syn keyword hareType void
2025-09-08 15:30:41 -04:00
# C ABI.
syn keyword hareType valist
2026-02-06 09:44:16 +00:00
# Pointer types.
syn match harePointer '*' contained containedin=hareTaggedUnion,hareTypeParens nextgroup=@hareType skipempty skipwhite
syn keyword hareStorageClass nullable nextgroup=harePointer skipempty skipwhite
2025-09-08 15:30:41 -04:00
# Slice and array types.
2026-02-06 09:44:16 +00:00
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
2025-09-08 15:30:41 -04:00
# Other types.
2026-02-06 09:44:16 +00:00
syn match hareError '!' contained containedin=hareTaggedUnion,hareTypeParens nextgroup=@hareType skipempty skipwhite
2024-05-24 08:05:00 +02:00
syn keyword hareStructure enum struct union
2022-09-27 17:30:34 +01:00
2025-09-08 15:30:41 -04:00
# Declarations {{{2
syn keyword hareDefine def
syn keyword hareInclude use
syn keyword hareKeyword export static
2026-02-06 09:44:16 +00:00
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
2025-09-08 15:30:41 -04:00
# Function declarations.
2026-02-06 09:44:16 +00:00
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
2025-09-08 15:30:41 -04:00
# Type declarations.
2026-02-06 09:44:16 +00:00
# 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
2025-09-08 15:30:41 -04:00
# Attributes {{{3
syn keyword hareAttribute @init @fini @test
syn keyword hareAttribute @packed
2026-02-06 09:44:16 +00:00
syn keyword hareAttribute @symbol nextgroup=hareAttributeParens skipempty skipwhite
2025-09-08 15:30:41 -04:00
syn keyword hareAttribute @threadlocal
syn keyword hareAttribute @undefined
2025-09-08 15:30:41 -04:00
2026-02-06 09:44:16 +00:00
# Match the parens following attributes.
syn region hareAttributeParens matchgroup=hareParen start='(' end=')' contained contains=TOP transparent
2025-09-08 15:30:41 -04:00
# Expressions {{{2
syn keyword hareConditional else
2026-02-06 09:44:16 +00:00
syn keyword hareConditional if nextgroup=hareConditionParens skipempty skipwhite
2025-09-08 15:30:41 -04:00
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
2026-02-06 09:44:16 +00:00
syn keyword hareStatement break continue return yield
syn keyword hareStatement defer
2025-09-08 15:30:41 -04:00
2026-02-06 09:44:16 +00:00
# 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
2025-09-08 15:30:41 -04:00
# Builtins {{{3
2026-02-06 09:44:16 +00:00
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
2025-09-08 15:30:41 -04:00
# C ABI.
2026-02-06 09:44:16 +00:00
syn keyword hareBuiltin vastart vaarg vaend
2025-09-08 15:30:41 -04:00
2026-02-06 09:44:16 +00:00
# Highlight `size` as a type unless it is followed by an open paren.
2025-09-08 15:30:41 -04:00
syn match hareType '\<size\>'
2026-02-06 09:44:16 +00:00
syn match hareBuiltin '\<size\ze(' nextgroup=hareTypeParens
2025-09-08 15:30:41 -04:00
2026-02-06 09:44:16 +00:00
# Match the parens in builtin expressions expecting a type.
syn region hareTypeParens matchgroup=hareParen start='(' end=')' contained contains=TOP nextgroup=@harePostfix skipempty skipwhite transparent
2025-09-08 15:30:41 -04:00
# Postfix expressions {{{3
# TODO: Match postfix expressions after literals.
2026-02-06 09:44:16 +00:00
syn cluster harePostfix contains=hareCast,hareField,hareSlice,hareSpecial
2025-09-08 15:30:41 -04:00
# Casts and type hints.
syn match hareCast ':' nextgroup=@hareType skipempty skipwhite
2026-02-06 09:44:16 +00:00
# Error checking.
syn match hareSpecial '!=\@!' contained nextgroup=@harePostfix skipempty skipwhite
syn match hareSpecial '?' nextgroup=@harePostfix skipempty skipwhite
2025-09-08 15:30:41 -04:00
# Field access.
2026-02-06 09:44:16 +00:00
syn match hareField '\.\w\+\>' contained contains=hareName,hareNumber,@hareReserved nextgroup=@harePostfix skipempty skipwhite transparent
2025-09-08 15:30:41 -04:00
# Indexing and slicing.
2026-02-06 09:44:16 +00:00
syn region hareSlice matchgroup=hareBracket start='\[' end=']' contained contains=TOP nextgroup=@harePostfix skipempty skipwhite transparent
2025-09-08 15:30:41 -04:00
2026-02-06 09:44:16 +00:00
# Literals {{{2
2025-09-08 15:30:41 -04:00
syn keyword hareBoolean true false
2024-05-24 08:05:00 +02:00
syn keyword hareConstant null
2022-09-27 17:30:34 +01:00
2026-02-06 09:44:16 +00:00
# Integers {{{3
2025-09-08 15:30:41 -04:00
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)?>'
2022-09-27 17:30:34 +01:00
2026-02-06 09:44:16 +00:00
# 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.
2025-09-08 15:30:41 -04:00
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)?>'
2024-05-24 08:05:00 +02:00
2026-02-06 09:44:16 +00:00
# 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
2024-05-24 08:05:00 +02:00
2025-09-08 15:30:41 -04:00
# Escape sequences.
2024-05-24 08:05:00 +02:00
syn match hareEscape '\\[0abfnrtv\\'"]' contained
syn match hareEscape '\v\\%(x\x{2}|u\x{4}|U\x{8})' contained display
2025-09-08 15:30:41 -04:00
# Format sequences.
2026-02-06 09:44:16 +00:00
syn match hareFormat '\v\{\d*%(:%(\.?\d+|[- +=befgoxX]|F[.2EsSU]|_%(\_[^\\]|\\%([0abfnrtv\\'"]|x\x{2}|u\x{4}|U\x{8})))*)?}' contained contains=hareEscape
2024-05-24 08:05:00 +02:00
syn match hareFormat '{\d*%\d*}' contained display
2025-09-08 15:30:41 -04:00
syn match hareFormat '{{\|}}' contained
2024-05-24 08:05:00 +02:00
2025-09-08 15:30:41 -04:00
# Miscellaneous {{{2
2022-09-27 17:30:34 +01:00
2025-09-08 15:30:41 -04:00
# Annotations.
2026-02-06 09:44:16 +00:00
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
2022-09-27 17:30:34 +01:00
2025-09-08 15:30:41 -04:00
# Comments.
2026-02-06 09:44:16 +00:00
syn region hareComment excludenl start='//' end='$' contains=hareSpecialComment,hareTodo,@Spell
syn match hareSpecialComment '\v\[\[\h\w*%(::\h\w*)*%(::)?]]' contained contains=@NoSpell display
2025-09-08 15:30:41 -04:00
syn keyword hareTodo FIXME TODO XXX contained
2022-09-27 17:30:34 +01:00
2026-02-06 09:44:16 +00:00
# Scope delimiters.
syn match hareScopeDelimiter '::'
2022-09-27 17:30:34 +01:00
2026-02-06 09:44:16 +00:00
# User labels.
syn match hareUserLabel ':\h\w*\>' contains=hareName,@hareReserved
2024-05-24 08:05:00 +02:00
2025-09-08 15:30:41 -04:00
# Default highlighting {{{1
2026-02-06 09:44:16 +00:00
hi def link hareAnnotation Special
hi def link hareAnnotationIdentifier hareAnnotation
hi def link hareAnnotationParen hareAnnotation
hi def link hareArrayBounds harePointer
2024-05-24 08:05:00 +02:00
hi def link hareAttribute PreProc
2022-09-27 17:30:34 +01:00
hi def link hareBoolean Boolean
2026-02-06 09:44:16 +00:00
hi def link hareBuiltin hareOperator
2022-09-27 17:30:34 +01:00
hi def link hareComment Comment
hi def link hareConditional Conditional
2024-05-24 08:05:00 +02:00
hi def link hareConstant Constant
hi def link hareDefine Define
2026-02-06 09:44:16 +00:00
hi def link hareError hareSpecial
2022-09-27 17:30:34 +01:00
hi def link hareEscape SpecialChar
hi def link hareFloat Float
hi def link hareFormat SpecialChar
2025-09-08 15:30:41 -04:00
hi def link hareFunction Function
2024-05-24 08:05:00 +02:00
hi def link hareInclude Include
2022-09-27 17:30:34 +01:00
hi def link hareKeyword Keyword
2025-09-08 15:30:41 -04:00
hi def link hareLabel Label
2022-09-27 17:30:34 +01:00
hi def link hareNumber Number
hi def link hareOperator Operator
2025-09-08 15:30:41 -04:00
hi def link harePointer hareStorageClass
2022-09-27 17:30:34 +01:00
hi def link hareRepeat Repeat
hi def link hareRune Character
2026-02-06 09:44:16 +00:00
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
2022-09-27 17:30:34 +01:00
hi def link hareStorageClass StorageClass
hi def link hareString String
2026-02-06 09:44:16 +00:00
hi def link hareStringDelimiter hareString
2022-09-27 17:30:34 +01:00
hi def link hareStructure Structure
hi def link hareTodo Todo
hi def link hareType Type
hi def link hareTypedef Typedef
2025-09-08 15:30:41 -04:00
hi def link hareUserLabel Identifier
2022-09-27 17:30:34 +01:00
2025-09-08 15:30:41 -04:00
# Highlight incorrect whitespace by default.
2026-02-06 09:44:16 +00:00
syn match hareSpaceError excludenl '\s\+$' containedin=ALL display
2025-09-08 15:30:41 -04:00
syn match hareSpaceError ' \+\ze\t' display
2024-05-24 08:05:00 +02:00
if get(g:, 'hare_space_error', 1)
2025-09-08 15:30:41 -04:00
hi! def link hareSpaceError Error
else
hi! def link hareSpaceError NONE
2024-05-24 08:05:00 +02:00
endif
2022-09-27 17:30:34 +01:00
2025-09-08 15:30:41 -04:00
b:current_syntax = 'hare'
# vim: fdm=marker et sts=2 sw=2 ts=8 tw=80