Bram Moolenaar | 7a32991 | 2010-05-21 12:05:36 +0200 | [diff] [blame] | 1 | " Vim syntax file |
| 2 | " Language: Liquid |
| 3 | " Maintainer: Tim Pope <vimNOSPAM@tpope.org> |
| 4 | " Filenames: *.liquid |
Bram Moolenaar | 47c532e | 2022-03-19 15:18:53 +0000 | [diff] [blame] | 5 | " Last Change: 2022 Mar 15 |
Bram Moolenaar | 7a32991 | 2010-05-21 12:05:36 +0200 | [diff] [blame] | 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 | |
Bram Moolenaar | 47c532e | 2022-03-19 15:18:53 +0000 | [diff] [blame] | 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 | syn region liquidRaw matchgroup=liquidDelimiter start="{%-\=\s*raw\s*-\=%}" end="{%-\=\s*endraw\s*-\=%}" contains=TOP,@liquidExempt containedin=ALLBUT,@liquidExempt keepend |
Bram Moolenaar | 7a32991 | 2010-05-21 12:05:36 +0200 | [diff] [blame] | 75 | |
Bram Moolenaar | 543b7ef | 2013-06-01 14:50:56 +0200 | [diff] [blame] | 76 | syn cluster liquidExempt contains=liquidStatement,liquidExpression,liquidComment,liquidRaw,@liquidStatement,liquidYamlHead |
Bram Moolenaar | 7a32991 | 2010-05-21 12:05:36 +0200 | [diff] [blame] | 77 | syn cluster liquidStatement contains=liquidConditional,liquidRepeat,liquidKeyword,@liquidExpression |
| 78 | syn cluster liquidExpression contains=liquidOperator,liquidString,liquidNumber,liquidFloat,liquidBoolean,liquidNull,liquidEmpty,liquidPipe,liquidForloop |
| 79 | |
| 80 | syn keyword liquidKeyword highlight nextgroup=liquidTypeHighlight skipwhite contained |
| 81 | syn keyword liquidKeyword endhighlight contained |
Bram Moolenaar | 47c532e | 2022-03-19 15:18:53 +0000 | [diff] [blame] | 82 | syn region liquidHighlight start="{%-\=\s*highlight\s\+\w\+\s*-\=%}" end="{%-\= endhighlight -\=%}" keepend |
Bram Moolenaar | 7a32991 | 2010-05-21 12:05:36 +0200 | [diff] [blame] | 83 | |
| 84 | for s:type in g:liquid_highlight_types |
| 85 | exe 'syn match liquidTypeHighlight "\<'.matchstr(s:type,'[^=]*').'\>" contained' |
Bram Moolenaar | 47c532e | 2022-03-19 15:18:53 +0000 | [diff] [blame] | 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') |
Bram Moolenaar | 7a32991 | 2010-05-21 12:05:36 +0200 | [diff] [blame] | 87 | endfor |
| 88 | unlet! s:type |
| 89 | |
| 90 | syn region liquidString matchgroup=liquidQuote start=+"+ end=+"+ contained |
| 91 | syn region liquidString matchgroup=liquidQuote start=+'+ end=+'+ contained |
| 92 | syn match liquidNumber "-\=\<\d\+\>" contained |
| 93 | syn match liquidFloat "-\=\<\d\+\>\.\.\@!\%(\d\+\>\)\=" contained |
| 94 | syn keyword liquidBoolean true false contained |
Bram Moolenaar | 47c532e | 2022-03-19 15:18:53 +0000 | [diff] [blame] | 95 | syn keyword liquidNull null nil blank contained |
Bram Moolenaar | 7a32991 | 2010-05-21 12:05:36 +0200 | [diff] [blame] | 96 | syn match liquidEmpty "\<empty\>" contained |
| 97 | |
| 98 | syn keyword liquidOperator and or not contained |
| 99 | syn match liquidPipe '|' contained skipwhite nextgroup=liquidFilter |
| 100 | |
Bram Moolenaar | 47c532e | 2022-03-19 15:18:53 +0000 | [diff] [blame] | 101 | syn 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 Moolenaar | 7a32991 | 2010-05-21 12:05:36 +0200 | [diff] [blame] | 102 | |
| 103 | syn keyword liquidConditional if elsif else endif unless endunless case when endcase ifchanged endifchanged contained |
Bram Moolenaar | 47c532e | 2022-03-19 15:18:53 +0000 | [diff] [blame] | 104 | syn keyword liquidRepeat for endfor tablerow endtablerow in break continue limit offset reversed contained |
| 105 | syn match liquidRepeat "\%({%-\=\s*\)\@<=empty\>" contained |
| 106 | syn keyword liquidKeyword assign capture endcapture increasement decreasement cycle include with render contained |
Bram Moolenaar | 7a32991 | 2010-05-21 12:05:36 +0200 | [diff] [blame] | 107 | |
| 108 | syn keyword liquidForloop forloop nextgroup=liquidForloopDot contained |
| 109 | syn match liquidForloopDot "\." nextgroup=liquidForloopAttribute contained |
| 110 | syn keyword liquidForloopAttribute length index index0 rindex rindex0 first last contained |
| 111 | |
| 112 | syn keyword liquidTablerowloop tablerowloop nextgroup=liquidTablerowloopDot contained |
| 113 | syn match liquidTablerowloopDot "\." nextgroup=liquidTableForloopAttribute contained |
| 114 | syn keyword liquidTablerowloopAttribute length index index0 col col0 index0 rindex rindex0 first last col_first col_last contained |
| 115 | |
| 116 | hi def link liquidDelimiter PreProc |
| 117 | hi def link liquidComment Comment |
| 118 | hi def link liquidTypeHighlight Type |
| 119 | hi def link liquidConditional Conditional |
| 120 | hi def link liquidRepeat Repeat |
| 121 | hi def link liquidKeyword Keyword |
| 122 | hi def link liquidOperator Operator |
| 123 | hi def link liquidString String |
| 124 | hi def link liquidQuote Delimiter |
| 125 | hi def link liquidNumber Number |
| 126 | hi def link liquidFloat Float |
| 127 | hi def link liquidEmpty liquidNull |
| 128 | hi def link liquidNull liquidBoolean |
| 129 | hi def link liquidBoolean Boolean |
| 130 | hi def link liquidFilter Function |
| 131 | hi def link liquidForloop Identifier |
| 132 | hi def link liquidForloopAttribute Identifier |
| 133 | |
| 134 | let b:current_syntax = 'liquid' |
| 135 | |
| 136 | if exists('main_syntax') && main_syntax == 'liquid' |
| 137 | unlet main_syntax |
| 138 | endif |