neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

tt2.vim (7955B)


      1 " Vim syntax file
      2 " Language:      TT2 (Perl Template Toolkit)
      3 " Maintainer:    vim-perl <vim-perl@googlegroups.com> (need to be subscribed to post)
      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 
     48 if !exists("b:tt2_syn_tags")
     49    let b:tt2_syn_tags = '\[% %]'
     50    "let b:tt2_syn_tags = '\[% %] \[\* \*]'
     51 endif
     52 
     53 if !exists("b:tt2_syn_inc_perl")
     54    let b:tt2_syn_inc_perl = 1
     55 endif
     56 
     57 if exists("b:current_syntax")
     58  finish
     59 endif
     60 
     61 let s:cpo_save = &cpo
     62 set cpo&vim
     63 
     64 syn case match
     65 
     66 syn cluster tt2_top_cluster contains=tt2_perlcode,tt2_tag_region
     67 
     68 " TT2 TAG Region
     69 if 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
     97            syn include @Perl syntax/perl.vim
     98            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 
    108 else
    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
    124        syn include @Perl syntax/perl.vim
    125        syn region tt2_perlcode
    126                    \ start=+\(\(RAW\)\=PERL\s*[-]\=%]\(\n\)\=\)\@<=+
    127                    \ end=+\[%[-]\=\s*END+me=s-1
    128                    \ contains=@Perl keepend
    129    endif
    130 endif
    131 
    132 " Directive
    133 syn 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
    141 syn match   tt2_directive +|+ contained
    142 syn keyword tt2_directive contained nextgroup=tt2_string_q,tt2_string_qq,tt2_blockname skipwhite skipempty
    143            \ INSERT INCLUDE PROCESS WRAPPER FILTER
    144            \ THROW CATCH
    145 syn keyword tt2_directive contained nextgroup=tt2_def_tag skipwhite skipempty
    146            \ TAGS
    147 
    148 syn match   tt2_def_tag "\S\+\s\+\S\+\|\<\w\+\>" contained
    149 
    150 syn match   tt2_variable  +\I\w*+                           contained
    151 syn match   tt2_operator  "[+*/%:?-]"                       contained
    152 syn match   tt2_operator  "\<\(mod\|div\|or\|and\|not\)\>"  contained
    153 syn match   tt2_operator  "[!=<>]=\=\|&&\|||"               contained
    154 syn match   tt2_operator  "\(\s\)\@<=_\(\s\)\@="            contained
    155 syn match   tt2_operator  "=>\|,"                           contained
    156 syn match   tt2_deref     "\([[:alnum:]_)\]}]\s*\)\@<=\."   contained
    157 syn match   tt2_comment   +#.*$+                            contained
    158 syn match   tt2_func      +\<\I\w*\(\s*(\)\@=+              contained nextgroup=tt2_bracket_r skipempty skipwhite
    159 "
    160 syn region  tt2_bracket_r  start=+(+ end=+)+                contained contains=@tt2_statement_cluster keepend extend
    161 syn region  tt2_bracket_b start=+\[+ end=+]+                contained contains=@tt2_statement_cluster keepend extend
    162 syn region  tt2_bracket_b start=+{+  end=+}+                contained contains=@tt2_statement_cluster keepend extend
    163 
    164 syn region  tt2_string_qq start=+"+ end=+"+ skip=+\\"+      contained contains=tt2_ivariable keepend extend
    165 syn region  tt2_string_q  start=+'+ end=+'+ skip=+\\'+      contained keepend extend
    166 
    167 syn match   tt2_ivariable  +\$\I\w*\>\(\.\I\w*\>\)*+        contained
    168 syn match   tt2_ivariable  +\${\I\w*\>\(\.\I\w*\>\)*}+      contained
    169 
    170 syn match   tt2_number    "\d\+"        contained
    171 syn match   tt2_number    "\d\+\.\d\+"  contained
    172 syn match   tt2_number    "0x\x\+"      contained
    173 syn match   tt2_number    "0\o\+"       contained
    174 
    175 syn match   tt2_blockname "\f\+"                       contained                        nextgroup=tt2_blockname_joint skipwhite skipempty
    176 syn match   tt2_blockname "$\w\+"                      contained contains=tt2_ivariable nextgroup=tt2_blockname_joint skipwhite skipempty
    177 syn region  tt2_blockname start=+"+ end=+"+ skip=+\\"+ contained contains=tt2_ivariable nextgroup=tt2_blockname_joint keepend skipwhite skipempty
    178 syn region  tt2_blockname start=+'+ end=+'+ skip=+\\'+ contained                        nextgroup=tt2_blockname_joint keepend skipwhite skipempty
    179 syn match   tt2_blockname_joint "+"                    contained                        nextgroup=tt2_blockname skipwhite skipempty
    180 
    181 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
    182 
    183 " Synchronizing
    184 syn sync minlines=50
    185 
    186 hi def link tt2_tag         Type
    187 hi def link tt2_tag_region  Type
    188 hi def link tt2_commentblock_region Comment
    189 hi def link tt2_directive   Statement
    190 hi def link tt2_variable    Identifier
    191 hi def link tt2_ivariable   Identifier
    192 hi def link tt2_operator    Statement
    193 hi def link tt2_string_qq   String
    194 hi def link tt2_string_q    String
    195 hi def link tt2_blockname   String
    196 hi def link tt2_comment     Comment
    197 hi def link tt2_func        Function
    198 hi def link tt2_number      Number
    199 
    200 if exists("b:tt2_syn_tags")
    201    unlet b:tt2_syn_tags
    202 endif
    203 
    204 let b:current_syntax = "tt2"
    205 
    206 let &cpo = s:cpo_save
    207 unlet s:cpo_save
    208 
    209 " vim:ts=4:sw=4