" Vim syntax file " Language: Terra; for terra, based on terra.vim " Maintainer: ura " URL: https://gitdab.com/suwacrab/terra-vim if version < 600 syntax clear elseif exists("b:current_syntax") finish endif let s:cpo_save = &cpo set cpo&vim " syncing method syn sync fromstart " FIXED fold regions function! s:FoldableRegion(tag, name, expr) let synexpr = 'syntax region ' . a:name . ' ' . a:expr let pfx = 'g:terra_syntax_fold_' if !exists('g:terra_syntax_nofold') || exists(pfx . a:tag) || exists(pfx . a:name) let synexpr .= ' fold' end exec synexpr endfunction " FIXED Clusters syntax cluster terraBase contains=terraComment,terraCommentLong,terraConstant,terraNumber,terraString,terraStringLong,terraBuiltIn syntax cluster terraExpr contains=@terraBase,terraTable,terraParen,terraBracket,terraSpecialTable,terraSpecialValue,terraOperator,terraSymbolOperator,terraEllipsis,terraComma,terraFunc,terraFuncCall,terraError syntax cluster terraStat \ contains=@terraExpr,terraIfThen,terraBlock,terraLoop,terraGoto,terraLabel,terraLocal,terraStatement,terraSemiCol,terraErrHand,terraTypeName " FIXED Symbols call s:FoldableRegion('table', 'terraTable', \ 'transparent matchgroup=terraBraces start="{" end="}" contains=@terraExpr') syntax region terraParen transparent matchgroup=terraParens start='(' end=')' contains=@terraExpr syntax region terraBracket transparent matchgroup=terraBrackets start="\[" end="\]" contains=@terraExpr syntax match terraComma "," syntax match terraSemiCol ";" if !exists('g:terra_syntax_nosymboloperator') if exists('g:terra_syntax_fancynotequal') syntax match terraNotEqOperator "\V~=" conceal cchar=竕 setlocal conceallevel=2 endi syntax match terraSymbolOperator "[#<>=~^&|*/%+-]\|\.\." contains=terraNotEqOperator endi syntax match terraEllipsis "\.\.\." " FIXED Comments syntax keyword terraCommentTodo contained TODO FIXME XXX TBD syntax match terraComment "--.*$" contains=terraCommentTodo,terraDocTag,@Spell call s:FoldableRegion('comment', 'terraCommentLong', \ 'matchgroup=terraCommentLongTag start="--\[\z(=*\)\[" end="\]\z1\]" contains=terraCommentTodo,terraDocTag,@Spell') syntax match terraDocTag contained "\s@\k\+" " Catch errors caused by unbalanced brackets and keywords syntax match terraError ")" syntax match terraError "}" syntax match terraError "\]" syntax match terraError "\<\%(else\|elseif\|then\|until\)\>" " Shebang at the start syntax match terraComment "\%^#!.*" " FIXED Function calls syntax match terraFuncCall /\k\+\%(\s*[{('"]\)\@=/ " Functions call s:FoldableRegion('function', 'terraFunc', \ 'transparent matchgroup=terraFuncKeyword start="\" end="\" contains=@terraStat,terraFuncSig') syntax region terraFuncSig contained transparent start="\(\\)\@<=" end=")" contains=terraFuncId,terraFuncArgs keepend call s:FoldableRegion('terra', 'terraFunc', \ 'transparent matchgroup=terraFuncKeyword start="\" end="\" contains=@terraStat,terraFuncSig') syntax region terraFuncSig contained transparent start="\(\\)\@<=" end=")" contains=terraFuncId,terraFuncArgs keepend syntax match terraFuncId contained "[^(]*(\@=" contains=terraFuncTable,terraFuncName syntax match terraFuncTable contained /\k\+\%(\s*[.:]\)\@=/ syntax match terraFuncName contained "[^(.:]*(\@=" syntax region terraFuncArgs contained transparent matchgroup=terraFuncParens start=/(/ end=/)/ contains=@terraBase,terraFuncArgName,terraFuncArgComma,terraEllipsis,terraTypeName syntax match terraFuncArgName contained /\k\+/ syntax match terraFuncArgComma contained /,/ " if ... then syntax region terraIfThen transparent matchgroup=terraCond start="\" end="\"me=e-4 contains=@terraExpr nextgroup=terraThenEnd skipwhite skipempty " then ... end call s:FoldableRegion('control', 'terraThenEnd', \ 'contained transparent matchgroup=terraCond start="\" end="\" contains=@terraStat,terraElseifThen,terraElse') " elseif ... then syntax region terraElseifThen contained transparent matchgroup=terraCond start="\" end="\" contains=@terraExpr " else syntax keyword terraElse contained else " do ... end call s:FoldableRegion('control', 'terraLoopBlock', \ 'transparent matchgroup=terraRepeat start="\" end="\" contains=@terraStat contained') call s:FoldableRegion('control', 'terraBlock', \ 'transparent matchgroup=terraStatement start="\" end="\" contains=@terraStat') " repeat ... until call s:FoldableRegion('control', 'terraLoop', \ 'transparent matchgroup=terraRepeat start="\" end="\" contains=@terraStat nextgroup=@terraExpr') " while ... do syntax region terraLoop transparent matchgroup=terraRepeat start="\" end="\"me=e-2 contains=@terraExpr nextgroup=terraLoopBlock skipwhite skipempty " for ... do and for ... in ... do syntax region terraLoop transparent matchgroup=terraRepeat start="\" end="\"me=e-2 contains=@terraExpr,terraIn nextgroup=terraLoopBlock skipwhite skipempty syntax keyword terraIn contained in " other keywords syn keyword terraStatement return local break syn keyword terraStatement goto syn match terraLabel "::\I\i*::" syn keyword terraOperator and or not syn keyword terraConstant nil true false " (more) Terra keywords syn keyword terraStruct struct union syn keyword terraVariable var syn keyword terraTypeName rawstring niltype double float bool int uint int64 uint64 int32 uint32 int16 uint16 int8 uint8 " FIXED Strings syntax match terraStringSpecial contained #\\[\\abfnrtvz'"]\|\\x[[:xdigit:]]\{2}\|\\[[:digit:]]\{,3}# call s:FoldableRegion('string', 'terraStringLong', \ 'matchgroup=terraStringLongTag start="\[\z(=*\)\[" end="\]\z1\]" contains=@Spell') syntax region terraString start=+'+ end=+'+ skip=+\\\\\|\\'+ contains=terraStringSpecial,@Spell syntax region terraString start=+"+ end=+"+ skip=+\\\\\|\\"+ contains=terraStringSpecial,@Spell " numbers syn match terraNumber "\<\d\+\>" " floating point number, with dot, optional exponent syn match terraNumber "\<\d\+\.\d*\%([eE][-+]\=\d\+\)\=\>" " floating point number, starting with a dot, optional exponent syn match terraNumber "\.\d\+\%([eE][-+]\=\d\+\)\=\>" " floating point number, without dot, with exponent syn match terraNumber "\<\d\+[eE][-+]\=\d\+\>" " hex numbers syn match terraNumber "\<0[xX][[:xdigit:].]\+\%([pP][-+]\=\d\+\)\=\>" syn keyword terraFunc assert collectgarbage dofile error next syn keyword terraFunc print rawget rawset tonumber tostring type _VERSION syn keyword terraFunc getmetatable setmetatable syn keyword terraFunc ipairs pairs syn keyword terraFunc pcall xpcall syn keyword terraFunc _G loadfile rawequal require import syn keyword terraFunc load select syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn keyword terraFunc _ENV rawlen syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ syn match terraFunc /\/ " Define the default highlighting. " For version 5.7 and earlier: only when not done already " For version 5.8 and later: only when an item doesn't have highlighting yet if version >= 508 || !exists("did_terra_syntax_inits") if version < 508 let did_terra_syntax_inits = 1 command -nargs=+ HiLink hi link else command -nargs=+ HiLink hi def link endif HiLink terraParens Noise HiLink terraBraces Structure HiLink terraBrackets Noise HiLink terraStatement Statement HiLink terraRepeat Repeat HiLink terraFor Repeat HiLink terraString String HiLink terraString2 String HiLink terraNumber Number HiLink terraOperator Operator HiLink terraConstant Constant HiLink terraCond Conditional HiLink terraTypeName Type HiLink terraFunction Structure HiLink terraFuncArgName Noise HiLink terraFuncCall PreProc HiLink terraFuncId Function HiLink terraFuncName terraFuncId HiLink terraFuncTable terraFuncId HiLink terraFuncKeyword terraFunction HiLink terraFunction Structure HiLink terraFuncParens Noise HiLink terraQuote Function HiLink terraComment Comment HiLink terraCommentLongTag terraCommentLong HiLink terraCommentLong terraComment HiLink terraTodo Todo HiLink terraTable Structure HiLink terraStruct Structure HiLink terraError Error HiLink terraParenError Error HiLink terraSpecial SpecialChar HiLink terraFunc Identifier HiLink terraVariable Identifier HiLink terraType Type HiLink terraLabel Label delcommand HiLink endif let b:current_syntax = "terra" let &cpo = s:cpo_save unlet s:cpo_save " vim: et ts=8 sw=2