39
+ − 1 " Vim syntax file
+ − 2 " Language: Liquid
+ − 3 " Maintainer: Tim Pope <vimNOSPAM@tpope.org>
+ − 4 " Filenames: *.liquid
+ − 5 " Last Change: 2010 May 21
+ − 6
+ − 7 if exists('b:current_syntax')
+ − 8 finish
+ − 9 endif
+ − 10
+ − 11 if !exists('main_syntax')
+ − 12 let main_syntax = 'liquid'
+ − 13 endif
+ − 14
+ − 15 if !exists('g:liquid_default_subtype')
+ − 16 let g:liquid_default_subtype = 'html'
+ − 17 endif
+ − 18
+ − 19 if !exists('b:liquid_subtype') && main_syntax == 'liquid'
+ − 20 let s:lines = getline(1)."\n".getline(2)."\n".getline(3)."\n".getline(4)."\n".getline(5)."\n".getline("$")
+ − 21 let b:liquid_subtype = matchstr(s:lines,'liquid_subtype=\zs\w\+')
+ − 22 if b:liquid_subtype == ''
+ − 23 let b:liquid_subtype = matchstr(&filetype,'^liquid\.\zs\w\+')
+ − 24 endif
+ − 25 if b:liquid_subtype == ''
+ − 26 let b:liquid_subtype = matchstr(substitute(expand('%:t'),'\c\%(\.liquid\)\+$','',''),'\.\zs\w\+$')
+ − 27 endif
+ − 28 if b:liquid_subtype == ''
+ − 29 let b:liquid_subtype = g:liquid_default_subtype
+ − 30 endif
+ − 31 endif
+ − 32
+ − 33 if exists('b:liquid_subtype') && b:liquid_subtype != ''
+ − 34 exe 'runtime! syntax/'.b:liquid_subtype.'.vim'
+ − 35 unlet! b:current_syntax
+ − 36 endif
+ − 37
+ − 38 syn case match
+ − 39
+ − 40 if exists('b:liquid_subtype') && b:liquid_subtype != 'yaml'
+ − 41 " YAML Front Matter
+ − 42 syn include @liquidYamlTop syntax/yaml.vim
+ − 43 unlet! b:current_syntax
+ − 44 syn region liquidYamlHead start="\%^---$" end="^---\s*$" keepend contains=@liquidYamlTop,@Spell
+ − 45 endif
+ − 46
+ − 47 if !exists('g:liquid_highlight_types')
+ − 48 let g:liquid_highlight_types = []
+ − 49 endif
+ − 50
+ − 51 if !exists('s:subtype')
+ − 52 let s:subtype = exists('b:liquid_subtype') ? b:liquid_subtype : ''
+ − 53
+ − 54 for s:type in map(copy(g:liquid_highlight_types),'matchstr(v:val,"[^=]*$")')
+ − 55 if s:type =~ '\.'
+ − 56 let b:{matchstr(s:type,'[^.]*')}_subtype = matchstr(s:type,'\.\zs.*')
+ − 57 endif
+ − 58 exe 'syn include @liquidHighlight'.substitute(s:type,'\.','','g').' syntax/'.matchstr(s:type,'[^.]*').'.vim'
+ − 59 unlet! b:current_syntax
+ − 60 endfor
+ − 61 unlet! s:type
+ − 62
+ − 63 if s:subtype == ''
+ − 64 unlet! b:liquid_subtype
+ − 65 else
+ − 66 let b:liquid_subtype = s:subtype
+ − 67 endif
+ − 68 unlet s:subtype
+ − 69 endif
+ − 70
+ − 71 syn region liquidStatement matchgroup=liquidDelimiter start="{%" end="%}" contains=@liquidStatement containedin=ALLBUT,@liquidExempt keepend
+ − 72 syn region liquidExpression matchgroup=liquidDelimiter start="{{" end="}}" contains=@liquidExpression containedin=ALLBUT,@liquidExempt keepend
+ − 73 syn region liquidComment matchgroup=liquidDelimiter start="{%\s*comment\s*%}" end="{%\s*endcomment\s*%}" contains=liquidTodo,@Spell containedin=ALLBUT,@liquidExempt keepend
+ − 74
+ − 75 syn cluster liquidExempt contains=liquidStatement,liquidExpression,liquidComment,@liquidStatement,liquidYamlHead
+ − 76 syn cluster liquidStatement contains=liquidConditional,liquidRepeat,liquidKeyword,@liquidExpression
+ − 77 syn cluster liquidExpression contains=liquidOperator,liquidString,liquidNumber,liquidFloat,liquidBoolean,liquidNull,liquidEmpty,liquidPipe,liquidForloop
+ − 78
+ − 79 syn keyword liquidKeyword highlight nextgroup=liquidTypeHighlight skipwhite contained
+ − 80 syn keyword liquidKeyword endhighlight contained
+ − 81 syn region liquidHighlight start="{%\s*highlight\s\+\w\+\s*%}" end="{% endhighlight %}" keepend
+ − 82
+ − 83 for s:type in g:liquid_highlight_types
+ − 84 exe 'syn match liquidTypeHighlight "\<'.matchstr(s:type,'[^=]*').'\>" contained'
+ − 85 exe 'syn region liquidHighlight'.substitute(matchstr(s:type,'[^=]*$'),'\..*','','').' start="{%\s*highlight\s\+'.matchstr(s:type,'[^=]*').'\s*%}" end="{% endhighlight %}" keepend contains=@liquidHighlight'.substitute(matchstr(s:type,'[^=]*$'),'\.','','g')
+ − 86 endfor
+ − 87 unlet! s:type
+ − 88
+ − 89 syn region liquidString matchgroup=liquidQuote start=+"+ end=+"+ contained
+ − 90 syn region liquidString matchgroup=liquidQuote start=+'+ end=+'+ contained
+ − 91 syn match liquidNumber "-\=\<\d\+\>" contained
+ − 92 syn match liquidFloat "-\=\<\d\+\>\.\.\@!\%(\d\+\>\)\=" contained
+ − 93 syn keyword liquidBoolean true false contained
+ − 94 syn keyword liquidNull null nil contained
+ − 95 syn match liquidEmpty "\<empty\>" contained
+ − 96
+ − 97 syn keyword liquidOperator and or not contained
+ − 98 syn match liquidPipe '|' contained skipwhite nextgroup=liquidFilter
+ − 99
+ − 100 syn keyword liquidFilter date capitalize downcase upcase first last join sort size strip_html strip_newlines newline_to_br replace replace_first remove remove_first truncate truncatewords prepend append minus plus times divided_by contained
+ − 101
+ − 102 syn keyword liquidConditional if elsif else endif unless endunless case when endcase ifchanged endifchanged contained
+ − 103 syn keyword liquidRepeat for endfor tablerow endtablerow in contained
+ − 104 syn match liquidRepeat "\%({%\s*\)\@<=empty\>" contained
+ − 105 syn keyword liquidKeyword assign cycle include with contained
+ − 106
+ − 107 syn keyword liquidForloop forloop nextgroup=liquidForloopDot contained
+ − 108 syn match liquidForloopDot "\." nextgroup=liquidForloopAttribute contained
+ − 109 syn keyword liquidForloopAttribute length index index0 rindex rindex0 first last contained
+ − 110
+ − 111 syn keyword liquidTablerowloop tablerowloop nextgroup=liquidTablerowloopDot contained
+ − 112 syn match liquidTablerowloopDot "\." nextgroup=liquidTableForloopAttribute contained
+ − 113 syn keyword liquidTablerowloopAttribute length index index0 col col0 index0 rindex rindex0 first last col_first col_last contained
+ − 114
+ − 115 hi def link liquidDelimiter PreProc
+ − 116 hi def link liquidComment Comment
+ − 117 hi def link liquidTypeHighlight Type
+ − 118 hi def link liquidConditional Conditional
+ − 119 hi def link liquidRepeat Repeat
+ − 120 hi def link liquidKeyword Keyword
+ − 121 hi def link liquidOperator Operator
+ − 122 hi def link liquidString String
+ − 123 hi def link liquidQuote Delimiter
+ − 124 hi def link liquidNumber Number
+ − 125 hi def link liquidFloat Float
+ − 126 hi def link liquidEmpty liquidNull
+ − 127 hi def link liquidNull liquidBoolean
+ − 128 hi def link liquidBoolean Boolean
+ − 129 hi def link liquidFilter Function
+ − 130 hi def link liquidForloop Identifier
+ − 131 hi def link liquidForloopAttribute Identifier
+ − 132
+ − 133 let b:current_syntax = 'liquid'
+ − 134
+ − 135 if exists('main_syntax') && main_syntax == 'liquid'
+ − 136 unlet main_syntax
+ − 137 endif