blob: 6826fb158197a63cfc36cdcb23c82d84dc231cda [file] [log] [blame]
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +01001" Vim syntax file
Bram Moolenaar543b7ef2013-06-01 14:50:56 +02002" Language: TT2 (Perl Template Toolkit)
3" Maintainer: vim-perl <vim-perl@googlegroups.com>
4" Author: Moriki, Atsushi <4woods+vim@gmail.com>
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +01005" 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
Bram Moolenaar543b7ef2013-06-01 14:50:56 +02009"
Bram Moolenaar37c64c72017-09-19 22:06:03 +020010" Installation:
11" put tt2.vim and tt2html.vim in to your syntax directory.
Bram Moolenaar543b7ef2013-06-01 14:50:56 +020012"
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
Bram Moolenaar543b7ef2013-06-01 14:50:56 +020047
48if !exists("b:tt2_syn_tags")
49 let b:tt2_syn_tags = '\[% %]'
50 "let b:tt2_syn_tags = '\[% %] \[\* \*]'
51endif
52
53if !exists("b:tt2_syn_inc_perl")
54 let b:tt2_syn_inc_perl = 1
55endif
56
57if exists("b:current_syntax")
58 finish
59endif
60
61let s:cpo_save = &cpo
62set cpo&vim
63
64syn case match
65
66syn cluster tt2_top_cluster contains=tt2_perlcode,tt2_tag_region
67
68" TT2 TAG Region
69if exists("b:tt2_syn_tags")
70
71 let s:str = b:tt2_syn_tags . ' '
72 let s:str = substitute(s:str,'^ \+','','g')
73 let s:str = substitute(s:str,' \+',' ','g')
74
75 while stridx(s:str,' ') > 0
76
77 let s:st = strpart(s:str,0,stridx(s:str,' '))
78 let s:str = substitute(s:str,'[^ ]* ','',"")
79
80 let s:ed = strpart(s:str,0,stridx(s:str,' '))
81 let s:str = substitute(s:str,'[^ ]* ','',"")
82
83 exec 'syn region tt2_tag_region '.
84 \ 'matchgroup=tt2_tag '.
85 \ 'start=+\(' . s:st .'\)[-]\=+ '.
86 \ 'end=+[-]\=\(' . s:ed . '\)+ '.
87 \ 'contains=@tt2_statement_cluster keepend extend'
88
89 exec 'syn region tt2_commentblock_region '.
90 \ 'matchgroup=tt2_tag '.
91 \ 'start=+\(' . s:st .'\)[-]\=\(#\)\@=+ '.
92 \ 'end=+[-]\=\(' . s:ed . '\)+ '.
93 \ 'keepend extend'
94
95 "Include Perl syntax when 'PERL' 'RAWPERL' block
96 if b:tt2_syn_inc_perl
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010097 syn include @Perl syntax/perl.vim
Bram Moolenaar543b7ef2013-06-01 14:50:56 +020098 exec 'syn region tt2_perlcode '.
99 \ 'start=+\(\(RAW\)\=PERL\s*[-]\=' . s:ed . '\(\n\)\=\)\@<=+ ' .
100 \ 'end=+' . s:st . '[-]\=\s*END+me=s-1 contains=@Perl keepend'
101 endif
102
103 "echo 'TAGS ' . s:st . ' ' . s:ed
104 unlet s:st
105 unlet s:ed
106 endwhile
107
108else
109
110 syn region tt2_tag_region
111 \ matchgroup=tt2_tag
112 \ start=+\(\[%\)[-]\=+
113 \ end=+[-]\=%\]+
114 \ contains=@tt2_statement_cluster keepend extend
115
116 syn region tt2_commentblock_region
117 \ matchgroup=tt2_tag
118 \ start=+\(\[%\)[-]\=#+
119 \ end=+[-]\=%\]+
120 \ keepend extend
121
122 "Include Perl syntax when 'PERL' 'RAWPERL' block
123 if b:tt2_syn_inc_perl
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +0100124 syn include @Perl syntax/perl.vim
Bram Moolenaar543b7ef2013-06-01 14:50:56 +0200125 syn region tt2_perlcode
126 \ start=+\(\(RAW\)\=PERL\s*[-]\=%]\(\n\)\=\)\@<=+
127 \ end=+\[%[-]\=\s*END+me=s-1
128 \ contains=@Perl keepend
129 endif
130endif
131
132" Directive
133syn keyword tt2_directive contained
134 \ GET CALL SET DEFAULT DEBUG
135 \ LAST NEXT BREAK STOP BLOCK
136 \ IF IN UNLESS ELSIF FOR FOREACH WHILE SWITCH CASE
137 \ USE PLUGIN MACRO META
138 \ TRY FINAL RETURN LAST
139 \ CLEAR TO STEP AND OR NOT MOD DIV
140 \ ELSE PERL RAWPERL END
141syn match tt2_directive +|+ contained
142syn keyword tt2_directive contained nextgroup=tt2_string_q,tt2_string_qq,tt2_blockname skipwhite skipempty
143 \ INSERT INCLUDE PROCESS WRAPPER FILTER
144 \ THROW CATCH
145syn keyword tt2_directive contained nextgroup=tt2_def_tag skipwhite skipempty
146 \ TAGS
147
148syn match tt2_def_tag "\S\+\s\+\S\+\|\<\w\+\>" contained
149
150syn match tt2_variable +\I\w*+ contained
151syn match tt2_operator "[+*/%:?-]" contained
152syn match tt2_operator "\<\(mod\|div\|or\|and\|not\)\>" contained
153syn match tt2_operator "[!=<>]=\=\|&&\|||" contained
154syn match tt2_operator "\(\s\)\@<=_\(\s\)\@=" contained
155syn match tt2_operator "=>\|," contained
156syn match tt2_deref "\([[:alnum:]_)\]}]\s*\)\@<=\." contained
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +0100157syn match tt2_comment +#.*$+ contained
Bram Moolenaar543b7ef2013-06-01 14:50:56 +0200158syn match tt2_func +\<\I\w*\(\s*(\)\@=+ contained nextgroup=tt2_bracket_r skipempty skipwhite
159"
160syn region tt2_bracket_r start=+(+ end=+)+ contained contains=@tt2_statement_cluster keepend extend
161syn region tt2_bracket_b start=+\[+ end=+]+ contained contains=@tt2_statement_cluster keepend extend
162syn region tt2_bracket_b start=+{+ end=+}+ contained contains=@tt2_statement_cluster keepend extend
163
164syn region tt2_string_qq start=+"+ end=+"+ skip=+\\"+ contained contains=tt2_ivariable keepend extend
165syn region tt2_string_q start=+'+ end=+'+ skip=+\\'+ contained keepend extend
166
167syn match tt2_ivariable +\$\I\w*\>\(\.\I\w*\>\)*+ contained
168syn match tt2_ivariable +\${\I\w*\>\(\.\I\w*\>\)*}+ contained
169
170syn match tt2_number "\d\+" contained
171syn match tt2_number "\d\+\.\d\+" contained
172syn match tt2_number "0x\x\+" contained
173syn match tt2_number "0\o\+" contained
174
175syn match tt2_blockname "\f\+" contained nextgroup=tt2_blockname_joint skipwhite skipempty
176syn match tt2_blockname "$\w\+" contained contains=tt2_ivariable nextgroup=tt2_blockname_joint skipwhite skipempty
177syn region tt2_blockname start=+"+ end=+"+ skip=+\\"+ contained contains=tt2_ivariable nextgroup=tt2_blockname_joint keepend skipwhite skipempty
178syn region tt2_blockname start=+'+ end=+'+ skip=+\\'+ contained nextgroup=tt2_blockname_joint keepend skipwhite skipempty
179syn match tt2_blockname_joint "+" contained nextgroup=tt2_blockname skipwhite skipempty
180
181syn 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
182
183" Synchronizing
184syn sync minlines=50
185
186hi def link tt2_tag Type
187hi def link tt2_tag_region Type
188hi def link tt2_commentblock_region Comment
189hi def link tt2_directive Statement
190hi def link tt2_variable Identifier
191hi def link tt2_ivariable Identifier
192hi def link tt2_operator Statement
193hi def link tt2_string_qq String
194hi def link tt2_string_q String
195hi def link tt2_blockname String
196hi def link tt2_comment Comment
197hi def link tt2_func Function
198hi def link tt2_number Number
199
200if exists("b:tt2_syn_tags")
201 unlet b:tt2_syn_tags
202endif
203
204let b:current_syntax = "tt2"
205
206let &cpo = s:cpo_save
207unlet s:cpo_save
208
209" vim:ts=4:sw=4