xref: /vim-8.2.3635/runtime/syntax/liquid.vim (revision 36e294c0)
1" Vim syntax file
2" Language:     Liquid
3" Maintainer:   Tim Pope <[email protected]>
4" Filenames:    *.liquid
5" Last Change:	2013 May 30
6
7if exists('b:current_syntax')
8  finish
9endif
10
11if !exists('main_syntax')
12  let main_syntax = 'liquid'
13endif
14
15if !exists('g:liquid_default_subtype')
16  let g:liquid_default_subtype = 'html'
17endif
18
19if !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
31endif
32
33if exists('b:liquid_subtype') && b:liquid_subtype != ''
34  exe 'runtime! syntax/'.b:liquid_subtype.'.vim'
35  unlet! b:current_syntax
36endif
37
38syn case match
39
40if 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
45endif
46
47if !exists('g:liquid_highlight_types')
48  let g:liquid_highlight_types = []
49endif
50
51if !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
69endif
70
71syn region  liquidStatement  matchgroup=liquidDelimiter start="{%" end="%}" contains=@liquidStatement containedin=ALLBUT,@liquidExempt keepend
72syn region  liquidExpression matchgroup=liquidDelimiter start="{{" end="}}" contains=@liquidExpression  containedin=ALLBUT,@liquidExempt keepend
73syn region  liquidComment    matchgroup=liquidDelimiter start="{%\s*comment\s*%}" end="{%\s*endcomment\s*%}" contains=liquidTodo,@Spell containedin=ALLBUT,@liquidExempt keepend
74syn region  liquidRaw        matchgroup=liquidDelimiter start="{%\s*raw\s*%}" end="{%\s*endraw\s*%}" contains=TOP,@liquidExempt containedin=ALLBUT,@liquidExempt keepend
75
76syn cluster liquidExempt contains=liquidStatement,liquidExpression,liquidComment,liquidRaw,@liquidStatement,liquidYamlHead
77syn cluster liquidStatement contains=liquidConditional,liquidRepeat,liquidKeyword,@liquidExpression
78syn cluster liquidExpression contains=liquidOperator,liquidString,liquidNumber,liquidFloat,liquidBoolean,liquidNull,liquidEmpty,liquidPipe,liquidForloop
79
80syn keyword liquidKeyword highlight nextgroup=liquidTypeHighlight skipwhite contained
81syn keyword liquidKeyword endhighlight contained
82syn region liquidHighlight start="{%\s*highlight\s\+\w\+\s*%}" end="{% endhighlight %}" keepend
83
84for s:type in g:liquid_highlight_types
85  exe 'syn match liquidTypeHighlight "\<'.matchstr(s:type,'[^=]*').'\>" contained'
86  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')
87endfor
88unlet! s:type
89
90syn region liquidString matchgroup=liquidQuote start=+"+ end=+"+ contained
91syn region liquidString matchgroup=liquidQuote start=+'+ end=+'+ contained
92syn match liquidNumber "-\=\<\d\+\>" contained
93syn match liquidFloat "-\=\<\d\+\>\.\.\@!\%(\d\+\>\)\=" contained
94syn keyword liquidBoolean true false contained
95syn keyword liquidNull null nil contained
96syn match liquidEmpty "\<empty\>" contained
97
98syn keyword liquidOperator and or not contained
99syn match liquidPipe '|' contained skipwhite nextgroup=liquidFilter
100
101syn 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
102
103syn keyword liquidConditional if elsif else endif unless endunless case when endcase ifchanged endifchanged contained
104syn keyword liquidRepeat      for endfor tablerow endtablerow in contained
105syn match   liquidRepeat      "\%({%\s*\)\@<=empty\>" contained
106syn keyword liquidKeyword     assign cycle include with contained
107
108syn keyword liquidForloop forloop nextgroup=liquidForloopDot contained
109syn match liquidForloopDot "\." nextgroup=liquidForloopAttribute contained
110syn keyword liquidForloopAttribute length index index0 rindex rindex0 first last contained
111
112syn keyword liquidTablerowloop tablerowloop nextgroup=liquidTablerowloopDot contained
113syn match liquidTablerowloopDot "\." nextgroup=liquidTableForloopAttribute contained
114syn keyword liquidTablerowloopAttribute length index index0 col col0 index0 rindex rindex0 first last col_first col_last contained
115
116hi def link liquidDelimiter             PreProc
117hi def link liquidComment               Comment
118hi def link liquidTypeHighlight         Type
119hi def link liquidConditional           Conditional
120hi def link liquidRepeat                Repeat
121hi def link liquidKeyword               Keyword
122hi def link liquidOperator              Operator
123hi def link liquidString                String
124hi def link liquidQuote                 Delimiter
125hi def link liquidNumber                Number
126hi def link liquidFloat                 Float
127hi def link liquidEmpty                 liquidNull
128hi def link liquidNull                  liquidBoolean
129hi def link liquidBoolean               Boolean
130hi def link liquidFilter                Function
131hi def link liquidForloop               Identifier
132hi def link liquidForloopAttribute      Identifier
133
134let b:current_syntax = 'liquid'
135
136if exists('main_syntax') && main_syntax == 'liquid'
137  unlet main_syntax
138endif
139