robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
ec1bea9c05
master
1" Vim syntax file 2" Language: Tera 3" Maintainer: Muntasir Mahmud <muntasir.joypurhat@gmail.com> 4" Last Change: 2026 Jan 29 5" 2026 Mar 31 by Vim project: prevent code execution in filename 6 7if exists ( "b:current_syntax" ) 8finish 9endif 10 11" Detect the underlying language based on filename pattern 12" For files like file.html.tera, we want to load html syntax 13let s: filename = expand ( "%:t" ) 14let s: dotpos = strridx ( s: filename , '.' , strridx ( s: filename , '.tera' ) - 1 ) 15let s: underlying_filetype = "" 16 17if s: dotpos != -1 18let s: underlying_ext = s: filename [ s: dotpos + 1 : strridx ( s: filename , '.tera' ) - 1 ] 19if s: underlying_ext != "" && s: underlying_ext != "tera" 20let s: underlying_filetype = s: underlying_ext 21endif 22endif 23 24" Load the underlying language syntax if detected 25if s: underlying_filetype != "" 26execute "runtime! syntax/" . fnameescape ( s: underlying_filetype ) . ".vim" 27unlet ! b: current_syntax 28else 29" Default to HTML if no specific language detected 30runtime ! syntax/html.vim 31unlet ! b: current_syntax 32endif 33 34" Tera comment blocks: {# comment #} 35syn region teraCommentBlock start = "{#-? "end = "-?#} "contains = @Spell 36 37" Tera statements: {% if condition %} 38syn region teraStatement start = "{%-? "end = "-?%} "contains = teraKeyword , teraString , teraNumber , teraFunction , teraBoolean , teraFilter , teraOperator , teraIdentifier , teraTest , teraNamespace , teraProperty , teraBracket , teraArgument 39 40" Tera expressions: {{ variable }} 41syn region teraExpression start = "{{-? "end = "-?}} "contains = teraString , teraNumber , teraFunction , teraBoolean , teraFilter , teraOperator , teraIdentifier , teraTest , teraNamespace , teraProperty , teraBracket 42 43" Special handling for raw blocks - content inside shouldn't be processed 44syn region teraRawBlock start = "{%-\?\s * raw\s * -%}\? "end = "{%-\?\s * endraw\s * -%}\? "contains = TOP , teraCommentBlock , teraStatement , teraExpression 45 46" Control structure keywords 47syn keyword teraKeyword contained if else elif endif for endfor in macro endmacro 48syn keyword teraKeyword contained block endblock extends include import set endset set_global 49syn keyword teraKeyword contained break continue filter endfilter raw endraw 50 51" Identifiers - define before operators for correct priority 52syn match teraIdentifier contained "\<\w\+\> " 53 54" Operators used in expressions and statements 55syn match teraOperator contained "==\|!=\|>=\|<=\|>\|<\|+\|-\|*\|/ " 56syn match teraOperator contained "{\@<!%}\@! "" Match % but not when part of {% or %} 57syn keyword teraOperator contained and or not is as 58 59" Functions and filters 60syn match teraFunction contained "\<\w\+\ze( " 61syn match teraFilter contained "|\_s * \w\+ " 62 63" String literals - both single and double quoted 64syn region teraString contained start = +" +skip = +\\" +end = +" +contains = @Spell 65syn region teraString contained start = +' +skip = +\\' +end = +' +contains = @Spell 66 67" Numeric literals - both integer and float 68syn match teraNumber contained "\<\d\+\> " 69syn match teraNumber contained "\<\d\+\.\d\+\> " 70 71" Boolean values 72syn keyword teraBoolean contained true false 73 74" Special variables (loop, __tera_context) 75syn keyword teraSpecialVariable contained loop __tera_context 76 77" 'is' test patterns: 'is not test_name' or 'is test_name' 78syn match teraTest contained "\<is\s\+not\?\s\+\w\+\> " 79 80" Namespace function calls: namespace::function() 81syn match teraNamespace contained "\<\w\+:: " 82 83" Property/member access: .property or ["key"] or [variable] 84syn match teraProperty contained "\.\w\+ " 85syn region teraBracket contained start = "\[ "end = "\] "contains = teraString , teraIdentifier , teraNumber , teraOperator 86 87" Backtick strings for raw content 88syn region teraString contained start = "` "skip = "\\` "end = "` "contains = @Spell 89 90" String escape sequences 91syn match teraStringEscape contained "\\. " 92 93" Highlighting links 94hi def link teraCommentBlock Comment 95hi def link teraKeyword Statement 96hi def link teraOperator Operator 97hi def link teraFunction Function 98hi def link teraIdentifier Identifier 99hi def link teraString String 100hi def link teraStringEscape SpecialChar 101hi def link teraNumber Number 102hi def link teraBoolean Boolean 103hi def link teraSpecialVariable Special 104hi def link teraTest Keyword 105hi def link teraNamespace Function 106hi def link teraProperty Identifier 107hi def link teraBracket Operator 108hi def link teraFilter Function 109hi def link teraStatement Statement 110hi def link teraExpression Statement 111 112" Clean up script-local variables 113unlet s: filename 114unlet s: dotpos 115if exists ( "s:underlying_ext" ) 116unlet s: underlying_ext 117endif 118unlet s: underlying_filetype 119 120let b: current_syntax = "tera"