2019-03-04 03:28:35 -05:00
|
|
|
if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'ansible') != -1
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
2015-12-17 04:48:07 -05:00
|
|
|
" Vim syntax file
|
2018-04-30 15:00:42 -04:00
|
|
|
" Language: Jinja2 - with special modifications for compound-filetype
|
|
|
|
" compatibility
|
|
|
|
" Maintainer: Dave Honneffer <pearofducks@gmail.com>
|
|
|
|
" Last Change: 2018.02.11
|
2015-12-17 04:48:07 -05:00
|
|
|
|
|
|
|
if !exists("main_syntax")
|
2018-04-30 15:00:42 -04:00
|
|
|
let main_syntax = 'jinja2'
|
2015-12-17 04:48:07 -05:00
|
|
|
endif
|
|
|
|
|
2018-04-30 15:00:42 -04:00
|
|
|
let b:current_syntax = ''
|
|
|
|
unlet b:current_syntax
|
2015-12-17 04:48:07 -05:00
|
|
|
|
|
|
|
syntax case match
|
|
|
|
|
|
|
|
" Jinja template built-in tags and parameters (without filter, macro, is and raw, they
|
|
|
|
" have special threatment)
|
|
|
|
syn keyword jinjaStatement containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained and if else in not or recursive as import
|
|
|
|
|
|
|
|
syn keyword jinjaStatement containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained is filter skipwhite nextgroup=jinjaFilter
|
|
|
|
syn keyword jinjaStatement containedin=jinjaTagBlock contained macro skipwhite nextgroup=jinjaFunction
|
|
|
|
syn keyword jinjaStatement containedin=jinjaTagBlock contained block skipwhite nextgroup=jinjaBlockName
|
|
|
|
|
|
|
|
" Variable Names
|
|
|
|
syn match jinjaVariable containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained /[a-zA-Z_][a-zA-Z0-9_]*/
|
|
|
|
syn keyword jinjaSpecial containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained false true none False True None loop super caller varargs kwargs
|
|
|
|
|
|
|
|
" Filters
|
|
|
|
syn match jinjaOperator "|" containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained skipwhite nextgroup=jinjaFilter
|
|
|
|
syn match jinjaFilter contained /[a-zA-Z_][a-zA-Z0-9_]*/
|
|
|
|
syn match jinjaFunction contained /[a-zA-Z_][a-zA-Z0-9_]*/
|
|
|
|
syn match jinjaBlockName contained /[a-zA-Z_][a-zA-Z0-9_]*/
|
|
|
|
|
|
|
|
" Jinja template constants
|
|
|
|
syn region jinjaString containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained start=/"/ skip=/\(\\\)\@<!\(\(\\\\\)\@>\)*\\"/ end=/"/
|
|
|
|
syn region jinjaString containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained start=/'/ skip=/\(\\\)\@<!\(\(\\\\\)\@>\)*\\'/ end=/'/
|
|
|
|
syn match jinjaNumber containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained /[0-9]\+\(\.[0-9]\+\)\?/
|
|
|
|
|
|
|
|
" Operators
|
|
|
|
syn match jinjaOperator containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained /[+\-*\/<>=!,:]/
|
|
|
|
syn match jinjaPunctuation containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained /[()\[\]]/
|
|
|
|
syn match jinjaOperator containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained /\./ nextgroup=jinjaAttribute
|
|
|
|
syn match jinjaAttribute contained /[a-zA-Z_][a-zA-Z0-9_]*/
|
|
|
|
|
|
|
|
" Jinja template tag and variable blocks
|
|
|
|
syn region jinjaNested matchgroup=jinjaOperator start="(" end=")" transparent display containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained
|
|
|
|
syn region jinjaNested matchgroup=jinjaOperator start="\[" end="\]" transparent display containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained
|
|
|
|
syn region jinjaNested matchgroup=jinjaOperator start="{" end="}" transparent display containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained
|
|
|
|
syn region jinjaTagBlock matchgroup=jinjaTagDelim start=/{%-\?/ end=/-\?%}/ containedin=ALLBUT,jinjaTagBlock,jinjaVarBlock,jinjaRaw,jinjaString,jinjaNested,jinjaComment
|
|
|
|
|
2018-07-08 09:16:28 -04:00
|
|
|
syn region jinjaVarBlock matchgroup=jinjaVarDelim start=/{{-\?/ end=/-\?}}/ containedin=ALLBUT,yamlComment,jinjaTagBlock,jinjaVarBlock,jinjaRaw,jinjaString,jinjaNested,jinjaComment
|
2015-12-17 04:48:07 -05:00
|
|
|
|
|
|
|
" Jinja template 'raw' tag
|
|
|
|
syn region jinjaRaw matchgroup=jinjaRawDelim start="{%\s*raw\s*%}" end="{%\s*endraw\s*%}" containedin=ALLBUT,jinjaTagBlock,jinjaVarBlock,jinjaString,jinjaComment
|
|
|
|
|
|
|
|
" Jinja comments
|
|
|
|
syn region jinjaComment matchgroup=jinjaCommentDelim start="{#" end="#}" containedin=ALLBUT,jinjaTagBlock,jinjaVarBlock,jinjaString
|
|
|
|
|
|
|
|
" Block start keywords. A bit tricker. We only highlight at the start of a
|
|
|
|
" tag block and only if the name is not followed by a comma or equals sign
|
|
|
|
" which usually means that we have to deal with an assignment.
|
|
|
|
syn match jinjaStatement containedin=jinjaTagBlock contained /\({%-\?\s*\)\@<=\<[a-zA-Z_][a-zA-Z0-9_]*\>\(\s*[,=]\)\@!/
|
|
|
|
|
|
|
|
" and context modifiers
|
|
|
|
syn match jinjaStatement containedin=jinjaTagBlock contained /\<with\(out\)\?\s\+context\>/
|
|
|
|
|
|
|
|
|
|
|
|
" Define the default highlighting.
|
2018-04-30 15:00:42 -04:00
|
|
|
if !exists("did_jinja_syn_inits")
|
|
|
|
command -nargs=+ HiLink hi def link <args>
|
2015-12-17 04:48:07 -05:00
|
|
|
|
|
|
|
HiLink jinjaPunctuation jinjaOperator
|
|
|
|
HiLink jinjaAttribute jinjaVariable
|
|
|
|
HiLink jinjaFunction jinjaFilter
|
|
|
|
|
|
|
|
HiLink jinjaTagDelim jinjaTagBlock
|
|
|
|
HiLink jinjaVarDelim jinjaVarBlock
|
|
|
|
HiLink jinjaCommentDelim jinjaComment
|
|
|
|
HiLink jinjaRawDelim jinja
|
|
|
|
|
|
|
|
HiLink jinjaSpecial Special
|
|
|
|
HiLink jinjaOperator Normal
|
|
|
|
HiLink jinjaRaw Normal
|
|
|
|
HiLink jinjaTagBlock PreProc
|
|
|
|
HiLink jinjaVarBlock PreProc
|
|
|
|
HiLink jinjaStatement Statement
|
|
|
|
HiLink jinjaFilter Function
|
|
|
|
HiLink jinjaBlockName Function
|
|
|
|
HiLink jinjaVariable Identifier
|
|
|
|
HiLink jinjaString Constant
|
|
|
|
HiLink jinjaNumber Constant
|
|
|
|
HiLink jinjaComment Comment
|
|
|
|
|
|
|
|
delcommand HiLink
|
|
|
|
endif
|
|
|
|
|
2018-04-30 15:00:42 -04:00
|
|
|
let b:current_syntax = "jinja2"
|