blob: 966b60f6f8929d65a9a66e3c1c9331dbbb6d32b0 [file] [log] [blame]
Bram Moolenaar7a329912010-05-21 12:05:36 +02001" Vim syntax file
2" Language: Liquid
3" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
4" Filenames: *.liquid
Bram Moolenaar47c532e2022-03-19 15:18:53 +00005" Last Change: 2022 Mar 15
Bram Moolenaar7a329912010-05-21 12:05:36 +02006
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
Bram Moolenaar47c532e2022-03-19 15:18:53 +000071syn 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
Bram Moolenaar7a329912010-05-21 12:05:36 +020075
Bram Moolenaar543b7ef2013-06-01 14:50:56 +020076syn cluster liquidExempt contains=liquidStatement,liquidExpression,liquidComment,liquidRaw,@liquidStatement,liquidYamlHead
Bram Moolenaar7a329912010-05-21 12:05:36 +020077syn 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
Bram Moolenaar47c532e2022-03-19 15:18:53 +000082syn region liquidHighlight start="{%-\=\s*highlight\s\+\w\+\s*-\=%}" end="{%-\= endhighlight -\=%}" keepend
Bram Moolenaar7a329912010-05-21 12:05:36 +020083
84for s:type in g:liquid_highlight_types
85 exe 'syn match liquidTypeHighlight "\<'.matchstr(s:type,'[^=]*').'\>" contained'
Bram Moolenaar47c532e2022-03-19 15:18:53 +000086 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')
Bram Moolenaar7a329912010-05-21 12:05:36 +020087endfor
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
Bram Moolenaar47c532e2022-03-19 15:18:53 +000095syn keyword liquidNull null nil blank contained
Bram Moolenaar7a329912010-05-21 12:05:36 +020096syn match liquidEmpty "\<empty\>" contained
97
98syn keyword liquidOperator and or not contained
99syn match liquidPipe '|' contained skipwhite nextgroup=liquidFilter
100
Bram Moolenaar47c532e2022-03-19 15:18:53 +0000101syn keyword liquidFilter date capitalize downcase upcase escape escape_once first last join sort size where uniq strip_html strip_newlines newline_to_br replace replace_first remove remove_first slice split strip truncate truncatewords prepend append url_encode url_decode abs at_most at_least ceil divided_by floor minus plus round times modulo contained
Bram Moolenaar7a329912010-05-21 12:05:36 +0200102
103syn keyword liquidConditional if elsif else endif unless endunless case when endcase ifchanged endifchanged contained
Bram Moolenaar47c532e2022-03-19 15:18:53 +0000104syn keyword liquidRepeat for endfor tablerow endtablerow in break continue limit offset reversed contained
105syn match liquidRepeat "\%({%-\=\s*\)\@<=empty\>" contained
106syn keyword liquidKeyword assign capture endcapture increasement decreasement cycle include with render contained
Bram Moolenaar7a329912010-05-21 12:05:36 +0200107
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