xref: /vim-8.2.3635/runtime/syntax/liquid.vim (revision c3d2c447)
1" Vim syntax file
2" Language:     Liquid
3" Maintainer:   Tim Pope <[email protected]>
4" Filenames:    *.liquid
5" Last Change:	2010 May 21
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
74
75syn cluster liquidExempt contains=liquidStatement,liquidExpression,liquidComment,@liquidStatement,liquidYamlHead
76syn cluster liquidStatement contains=liquidConditional,liquidRepeat,liquidKeyword,@liquidExpression
77syn cluster liquidExpression contains=liquidOperator,liquidString,liquidNumber,liquidFloat,liquidBoolean,liquidNull,liquidEmpty,liquidPipe,liquidForloop
78
79syn keyword liquidKeyword highlight nextgroup=liquidTypeHighlight skipwhite contained
80syn keyword liquidKeyword endhighlight contained
81syn region liquidHighlight start="{%\s*highlight\s\+\w\+\s*%}" end="{% endhighlight %}" keepend
82
83for 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')
86endfor
87unlet! s:type
88
89syn region liquidString matchgroup=liquidQuote start=+"+ end=+"+ contained
90syn region liquidString matchgroup=liquidQuote start=+'+ end=+'+ contained
91syn match liquidNumber "-\=\<\d\+\>" contained
92syn match liquidFloat "-\=\<\d\+\>\.\.\@!\%(\d\+\>\)\=" contained
93syn keyword liquidBoolean true false contained
94syn keyword liquidNull null nil contained
95syn match liquidEmpty "\<empty\>" contained
96
97syn keyword liquidOperator and or not contained
98syn match liquidPipe '|' contained skipwhite nextgroup=liquidFilter
99
100syn 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
102syn keyword liquidConditional if elsif else endif unless endunless case when endcase ifchanged endifchanged contained
103syn keyword liquidRepeat      for endfor tablerow endtablerow in contained
104syn match   liquidRepeat      "\%({%\s*\)\@<=empty\>" contained
105syn keyword liquidKeyword     assign cycle include with contained
106
107syn keyword liquidForloop forloop nextgroup=liquidForloopDot contained
108syn match liquidForloopDot "\." nextgroup=liquidForloopAttribute contained
109syn keyword liquidForloopAttribute length index index0 rindex rindex0 first last contained
110
111syn keyword liquidTablerowloop tablerowloop nextgroup=liquidTablerowloopDot contained
112syn match liquidTablerowloopDot "\." nextgroup=liquidTableForloopAttribute contained
113syn keyword liquidTablerowloopAttribute length index index0 col col0 index0 rindex rindex0 first last col_first col_last contained
114
115hi def link liquidDelimiter             PreProc
116hi def link liquidComment               Comment
117hi def link liquidTypeHighlight         Type
118hi def link liquidConditional           Conditional
119hi def link liquidRepeat                Repeat
120hi def link liquidKeyword               Keyword
121hi def link liquidOperator              Operator
122hi def link liquidString                String
123hi def link liquidQuote                 Delimiter
124hi def link liquidNumber                Number
125hi def link liquidFloat                 Float
126hi def link liquidEmpty                 liquidNull
127hi def link liquidNull                  liquidBoolean
128hi def link liquidBoolean               Boolean
129hi def link liquidFilter                Function
130hi def link liquidForloop               Identifier
131hi def link liquidForloopAttribute      Identifier
132
133let b:current_syntax = 'liquid'
134
135if exists('main_syntax') && main_syntax == 'liquid'
136  unlet main_syntax
137endif
138