ajhahn.de
← Flash
Vim Script 86 lines
" Vim syntax file for the Flash systems language.
" Language:  Flash
" Filenames: *.flash
"
" Pure highlight-group syntax — ships no colors of its own; it links Flash
" tokens to the standard groups (Keyword, Type, String, Comment, Function, …)
" so the active colorscheme paints them. Tracks the lexical surface defined in
" src/token.zig and src/lexer.zig; token.zig is the source of truth.

if exists("b:current_syntax")
  finish
endif

" Definition order matters: when two items match at the same position, the one
" defined LAST wins (:help :syn-priority). So the low-priority operator class is
" defined first and strings/comments last, letting a comment beat the '/' in
" '//' and keywords beat a call-like 'if ('.

" --- operators (lowest priority) ---
syntax match flashOperator "+%=\|-%=\|\*%=\|++\|\*\*\|+%\|-%\|*%\|<<=\|>>=\|->\|=>\|:=\|==\|!=\|<=\|>=\|<<\|>>\|&&\|||\|\.\.\.\|\.\.\|[-+*/%<>=&|^~!?]"

" --- numbers: all literal forms the lexer recognises ---
syntax match flashNumber "\<0x[0-9a-fA-F_]\+\>"
syntax match flashNumber "\<0b[01_]\+\>"
syntax match flashNumber "\<0o[0-7_]\+\>"
syntax match flashFloat  "\<[0-9][0-9_]*\.[0-9][0-9_]*\([eE][+-]\?[0-9_]\+\)\?\>"
syntax match flashNumber "\<[0-9][0-9_]*\>"

" --- function call: an identifier immediately before '(' ---
syntax match flashFunctionCall "\<[A-Za-z_]\w*\ze\s*("

" --- primitive types ---
syntax match flashType "\<\%(u\d\+\|i\d\+\|f16\|f32\|f64\|f80\|f128\|usize\|isize\|bool\|void\|anyopaque\|anyerror\|anytype\|type\|noreturn\|comptime_int\|comptime_float\|c_int\|c_uint\|c_char\|c_short\|c_ushort\|c_long\|c_ulong\|c_longlong\|c_ulonglong\|c_longdouble\)\>"

" --- language constants ---
syntax keyword flashBoolean  true false
syntax keyword flashConstant null undefined unreachable

" --- keywords (defined after call/type so they win at e.g. 'if (' ) ---
syntax keyword flashImport      use as link
syntax keyword flashConditional if else switch
syntax keyword flashRepeat      while for
syntax keyword flashKeyword     in break continue return orelse asm
syntax keyword flashException   try catch defer errdefer
syntax keyword flashStructure   struct enum union error test
syntax keyword flashStorage     const var pub inline comptime extern export callconv align linksection packed
syntax keyword flashKeyword     fn

" --- builtins: #name ---
syntax match flashBuiltin "#[A-Za-z_]\w*"

" --- strings, chars, escapes, raw multiline lines ---
syntax match  flashEscape      "\\\%(n\|t\|r\|0\|\\\|\"\|'\|x[0-9a-fA-F]\{2}\|u{[0-9a-fA-F]\{1,6}}\)" contained
syntax region flashString      start=+"+ skip=+\\"+ end=+"+ oneline contains=flashEscape
syntax match  flashChar        "'\%(\\.\|[^'\\]\)'" contains=flashEscape
syntax match  flashMultiString "\\\\.*$"

" --- comments: '//' line, '///' doc (exactly three slashes) ---
syntax match flashComment    "//.*$" contains=@Spell
syntax match flashDocComment "///\%(/\)\@!.*$" contains=@Spell

" --- link Flash groups to standard highlight groups ---
highlight default link flashComment       Comment
highlight default link flashDocComment    SpecialComment
highlight default link flashImport        Include
highlight default link flashConditional   Conditional
highlight default link flashRepeat        Repeat
highlight default link flashKeyword       Keyword
highlight default link flashException     Exception
highlight default link flashStructure     Structure
highlight default link flashStorage       StorageClass
highlight default link flashFunctionCall  Function
highlight default link flashType          Type
highlight default link flashBoolean       Boolean
highlight default link flashConstant      Constant
highlight default link flashString        String
highlight default link flashMultiString   String
highlight default link flashChar          Character
highlight default link flashEscape        SpecialChar
highlight default link flashBuiltin       Function
highlight default link flashNumber        Number
highlight default link flashFloat         Float
highlight default link flashOperator      Operator

let b:current_syntax = "flash"