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