liquid.vim 6.0 KB

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