tt2.vim 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. " Vim syntax file
  2. " Language: TT2 (Perl Template Toolkit)
  3. " Maintainer: vim-perl <vim-perl@googlegroups.com>
  4. " Author: Moriki, Atsushi <4woods+vim@gmail.com>
  5. " Homepage: https://github.com/vim-perl/vim-perl
  6. " Bugs/requests: https://github.com/vim-perl/vim-perl/issues
  7. " License: Vim License (see :help license)
  8. " Last Change: 2018 Mar 28
  9. "
  10. " Installation:
  11. " put tt2.vim and tt2html.vim in to your syntax directory.
  12. "
  13. " add below in your filetype.vim.
  14. " au BufNewFile,BufRead *.tt2 setf tt2
  15. " or
  16. " au BufNewFile,BufRead *.tt2
  17. " \ if ( getline(1) . getline(2) . getline(3) =~ '<\chtml' |
  18. " \ && getline(1) . getline(2) . getline(3) !~ '<[%?]' ) |
  19. " \ || getline(1) =~ '<!DOCTYPE HTML' |
  20. " \ setf tt2html |
  21. " \ else |
  22. " \ setf tt2 |
  23. " \ endif
  24. "
  25. " define START_TAG, END_TAG
  26. " "ASP"
  27. " :let b:tt2_syn_tags = '<% %>'
  28. " "PHP"
  29. " :let b:tt2_syn_tags = '<? ?>'
  30. " "TT2 and HTML"
  31. " :let b:tt2_syn_tags = '\[% %] <!-- -->'
  32. "
  33. " Changes:
  34. " 0.1.3
  35. " Changed fileformat from 'dos' to 'unix'
  36. " Deleted 'echo' that print obstructive message
  37. " 0.1.2
  38. " Added block comment syntax
  39. " e.g. [%# COMMENT
  40. " COMMENT TOO %]
  41. " [%# IT'S SAFE %] HERE IS OUTSIDE OF TT2 DIRECTIVE
  42. " [% # WRONG!! %] HERE STILL BE COMMENT
  43. " 0.1.1
  44. " Release
  45. " 0.1.0
  46. " Internal
  47. if !exists("b:tt2_syn_tags")
  48. let b:tt2_syn_tags = '\[% %]'
  49. "let b:tt2_syn_tags = '\[% %] \[\* \*]'
  50. endif
  51. if !exists("b:tt2_syn_inc_perl")
  52. let b:tt2_syn_inc_perl = 1
  53. endif
  54. if exists("b:current_syntax")
  55. finish
  56. endif
  57. let s:cpo_save = &cpo
  58. set cpo&vim
  59. syn case match
  60. syn cluster tt2_top_cluster contains=tt2_perlcode,tt2_tag_region
  61. " TT2 TAG Region
  62. if exists("b:tt2_syn_tags")
  63. let s:str = b:tt2_syn_tags . ' '
  64. let s:str = substitute(s:str,'^ \+','','g')
  65. let s:str = substitute(s:str,' \+',' ','g')
  66. while stridx(s:str,' ') > 0
  67. let s:st = strpart(s:str,0,stridx(s:str,' '))
  68. let s:str = substitute(s:str,'[^ ]* ','',"")
  69. let s:ed = strpart(s:str,0,stridx(s:str,' '))
  70. let s:str = substitute(s:str,'[^ ]* ','',"")
  71. exec 'syn region tt2_tag_region '.
  72. \ 'matchgroup=tt2_tag '.
  73. \ 'start=+\(' . s:st .'\)[-]\=+ '.
  74. \ 'end=+[-]\=\(' . s:ed . '\)+ '.
  75. \ 'contains=@tt2_statement_cluster keepend extend'
  76. exec 'syn region tt2_commentblock_region '.
  77. \ 'matchgroup=tt2_tag '.
  78. \ 'start=+\(' . s:st .'\)[-]\=\(#\)\@=+ '.
  79. \ 'end=+[-]\=\(' . s:ed . '\)+ '.
  80. \ 'keepend extend'
  81. "Include Perl syntax when 'PERL' 'RAWPERL' block
  82. if b:tt2_syn_inc_perl
  83. syn include @Perl syntax/perl.vim
  84. exec 'syn region tt2_perlcode '.
  85. \ 'start=+\(\(RAW\)\=PERL\s*[-]\=' . s:ed . '\(\n\)\=\)\@<=+ ' .
  86. \ 'end=+' . s:st . '[-]\=\s*END+me=s-1 contains=@Perl keepend'
  87. endif
  88. "echo 'TAGS ' . s:st . ' ' . s:ed
  89. unlet s:st
  90. unlet s:ed
  91. endwhile
  92. else
  93. syn region tt2_tag_region
  94. \ matchgroup=tt2_tag
  95. \ start=+\(\[%\)[-]\=+
  96. \ end=+[-]\=%\]+
  97. \ contains=@tt2_statement_cluster keepend extend
  98. syn region tt2_commentblock_region
  99. \ matchgroup=tt2_tag
  100. \ start=+\(\[%\)[-]\=#+
  101. \ end=+[-]\=%\]+
  102. \ keepend extend
  103. "Include Perl syntax when 'PERL' 'RAWPERL' block
  104. if b:tt2_syn_inc_perl
  105. syn include @Perl syntax/perl.vim
  106. syn region tt2_perlcode
  107. \ start=+\(\(RAW\)\=PERL\s*[-]\=%]\(\n\)\=\)\@<=+
  108. \ end=+\[%[-]\=\s*END+me=s-1
  109. \ contains=@Perl keepend
  110. endif
  111. endif
  112. " Directive
  113. syn keyword tt2_directive contained
  114. \ GET CALL SET DEFAULT DEBUG
  115. \ LAST NEXT BREAK STOP BLOCK
  116. \ IF IN UNLESS ELSIF FOR FOREACH WHILE SWITCH CASE
  117. \ USE PLUGIN MACRO META
  118. \ TRY FINAL RETURN LAST
  119. \ CLEAR TO STEP AND OR NOT MOD DIV
  120. \ ELSE PERL RAWPERL END
  121. syn match tt2_directive +|+ contained
  122. syn keyword tt2_directive contained nextgroup=tt2_string_q,tt2_string_qq,tt2_blockname skipwhite skipempty
  123. \ INSERT INCLUDE PROCESS WRAPPER FILTER
  124. \ THROW CATCH
  125. syn keyword tt2_directive contained nextgroup=tt2_def_tag skipwhite skipempty
  126. \ TAGS
  127. syn match tt2_def_tag "\S\+\s\+\S\+\|\<\w\+\>" contained
  128. syn match tt2_variable +\I\w*+ contained
  129. syn match tt2_operator "[+*/%:?-]" contained
  130. syn match tt2_operator "\<\(mod\|div\|or\|and\|not\)\>" contained
  131. syn match tt2_operator "[!=<>]=\=\|&&\|||" contained
  132. syn match tt2_operator "\(\s\)\@<=_\(\s\)\@=" contained
  133. syn match tt2_operator "=>\|," contained
  134. syn match tt2_deref "\([[:alnum:]_)\]}]\s*\)\@<=\." contained
  135. syn match tt2_comment +#.*$+ contained
  136. syn match tt2_func +\<\I\w*\(\s*(\)\@=+ contained nextgroup=tt2_bracket_r skipempty skipwhite
  137. "
  138. syn region tt2_bracket_r start=+(+ end=+)+ contained contains=@tt2_statement_cluster keepend extend
  139. syn region tt2_bracket_b start=+\[+ end=+]+ contained contains=@tt2_statement_cluster keepend extend
  140. syn region tt2_bracket_b start=+{+ end=+}+ contained contains=@tt2_statement_cluster keepend extend
  141. syn region tt2_string_qq start=+"+ end=+"+ skip=+\\"+ contained contains=tt2_ivariable keepend extend
  142. syn region tt2_string_q start=+'+ end=+'+ skip=+\\'+ contained keepend extend
  143. syn match tt2_ivariable +\$\I\w*\>\(\.\I\w*\>\)*+ contained
  144. syn match tt2_ivariable +\${\I\w*\>\(\.\I\w*\>\)*}+ contained
  145. syn match tt2_number "\d\+" contained
  146. syn match tt2_number "\d\+\.\d\+" contained
  147. syn match tt2_number "0x\x\+" contained
  148. syn match tt2_number "0\o\+" contained
  149. syn match tt2_blockname "\f\+" contained nextgroup=tt2_blockname_joint skipwhite skipempty
  150. syn match tt2_blockname "$\w\+" contained contains=tt2_ivariable nextgroup=tt2_blockname_joint skipwhite skipempty
  151. syn region tt2_blockname start=+"+ end=+"+ skip=+\\"+ contained contains=tt2_ivariable nextgroup=tt2_blockname_joint keepend skipwhite skipempty
  152. syn region tt2_blockname start=+'+ end=+'+ skip=+\\'+ contained nextgroup=tt2_blockname_joint keepend skipwhite skipempty
  153. syn match tt2_blockname_joint "+" contained nextgroup=tt2_blockname skipwhite skipempty
  154. syn cluster tt2_statement_cluster contains=tt2_directive,tt2_variable,tt2_operator,tt2_string_q,tt2_string_qq,tt2_deref,tt2_comment,tt2_func,tt2_bracket_b,tt2_bracket_r,tt2_number
  155. " Synchronizing
  156. syn sync minlines=50
  157. hi def link tt2_tag Type
  158. hi def link tt2_tag_region Type
  159. hi def link tt2_commentblock_region Comment
  160. hi def link tt2_directive Statement
  161. hi def link tt2_variable Identifier
  162. hi def link tt2_ivariable Identifier
  163. hi def link tt2_operator Statement
  164. hi def link tt2_string_qq String
  165. hi def link tt2_string_q String
  166. hi def link tt2_blockname String
  167. hi def link tt2_comment Comment
  168. hi def link tt2_func Function
  169. hi def link tt2_number Number
  170. if exists("b:tt2_syn_tags")
  171. unlet b:tt2_syn_tags
  172. endif
  173. let b:current_syntax = "tt2"
  174. let &cpo = s:cpo_save
  175. unlet s:cpo_save
  176. " vim:ts=4:sw=4