diff options
author | Muntasir Mahmud <muntasir.joypurhat@gmail.com> | 2025-03-09 15:13:52 +0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-09 17:13:52 +0800 |
commit | d4584903f3a7123a389332afa2620f2b997b7f1b (patch) | |
tree | 055933b725f6798a273d847b0ffd4b0ce1bb36e0 /runtime/syntax | |
parent | d414d0e8eab8906db19e2f83b9983ce8727f8de6 (diff) | |
download | rneovim-d4584903f3a7123a389332afa2620f2b997b7f1b.tar.gz rneovim-d4584903f3a7123a389332afa2620f2b997b7f1b.tar.bz2 rneovim-d4584903f3a7123a389332afa2620f2b997b7f1b.zip |
vim-patch:9.1.1188: runtime(tera): tera support can be improved (#32799)
Problem: runtime(tera): tera support can be improved
Solution: update tera filetype plugin, include a tera syntax script
update the filetype test, update makemenu and synmenu vim scripts
(MuntasirSZN)
closes: vim/vim#16830
vim/vim@14da0fb
Diffstat (limited to 'runtime/syntax')
-rw-r--r-- | runtime/syntax/tera.vim | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/runtime/syntax/tera.vim b/runtime/syntax/tera.vim new file mode 100644 index 0000000000..922b9c9752 --- /dev/null +++ b/runtime/syntax/tera.vim @@ -0,0 +1,96 @@ +" Vim syntax file +" Language: Tera +" Maintainer: Muntasir Mahmud <muntasir.joypurhat@gmail.com> +" Last Change: 2025 Mar 09 + +if exists("b:current_syntax") + finish +endif + +" Detect the underlying language based on filename pattern +" For files like file.html.tera, we want to load html syntax +let s:filename = expand("%:t") +let s:dotpos = strridx(s:filename, '.', strridx(s:filename, '.tera') - 1) +let s:underlying_filetype = "" + +if s:dotpos != -1 + let s:underlying_ext = s:filename[s:dotpos+1:strridx(s:filename, '.tera')-1] + if s:underlying_ext != "" && s:underlying_ext != "tera" + let s:underlying_filetype = s:underlying_ext + endif +endif + +" Load the underlying language syntax if detected +if s:underlying_filetype != "" + execute "runtime! syntax/" . s:underlying_filetype . ".vim" + unlet! b:current_syntax +else + " Default to HTML if no specific language detected + runtime! syntax/html.vim + unlet! b:current_syntax +endif + +" Tera comment blocks: {# comment #} +syn region teraCommentBlock start="{#" end="#}" contains=@Spell containedin=cssDefinition,cssStyle,htmlHead,htmlTitle + +" Tera statements: {% if condition %} +syn region teraStatement start="{%" end="%}" contains=teraKeyword,teraString,teraNumber,teraFunction,teraBoolean,teraFilter,teraOperator containedin=cssDefinition,cssStyle,htmlHead,htmlTitle + +" Tera expressions: {{ variable }} +syn region teraExpression start="{{" end="}}" contains=teraString,teraNumber,teraFunction,teraBoolean,teraFilter,teraOperator,teraIdentifier containedin=cssDefinition,cssStyle,htmlHead,htmlTitle + +" Special handling for raw blocks - content inside shouldn't be processed +syn region teraRawBlock start="{% raw %}" end="{% endraw %}" contains=TOP,teraCommentBlock,teraStatement,teraExpression + +" Control structure keywords +syn keyword teraKeyword contained if else elif endif for endfor in macro endmacro +syn keyword teraKeyword contained block endblock extends include import set endset +syn keyword teraKeyword contained break continue filter endfilter raw endraw with endwith + +" Identifiers - define before operators for correct priority +syn match teraIdentifier contained "\<\w\+\>" + +" Operators used in expressions and statements +syn match teraOperator contained "==\|!=\|>=\|<=\|>\|<\|+\|-\|*\|/" +syn match teraOperator contained "{\@<!%}\@!" " Match % but not when part of {% or %} +syn keyword teraOperator contained and or not is as + +" Functions and filters +syn match teraFunction contained "\<\w\+\ze(" +syn match teraFilter contained "|\_s*\w\+" + +" String literals - both single and double quoted +syn region teraString contained start=+"+ skip=+\\"+ end=+"+ contains=@Spell +syn region teraString contained start=+'+ skip=+\\'+ end=+'+ contains=@Spell + +" Numeric literals - both integer and float +syn match teraNumber contained "\<\d\+\>" +syn match teraNumber contained "\<\d\+\.\d\+\>" + +" Boolean values +syn keyword teraBoolean contained true false + +" Highlighting links +hi def link teraCommentBlock Comment +hi def link teraKeyword Statement +hi def link teraOperator Operator +hi def link teraFunction Function +hi def link teraIdentifier Identifier +hi def link teraString String +hi def link teraNumber Number +hi def link teraBoolean Boolean +hi def link teraFilter PreProc + +" Special highlighting for blocks and expressions +hi def link teraStatement PreProc +hi def link teraExpression PreProc + +" Clean up script-local variables +unlet s:filename +unlet s:dotpos +if exists("s:underlying_ext") + unlet s:underlying_ext +endif +unlet s:underlying_filetype + +let b:current_syntax = "tera" |