Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim syntax file |
| 2 | " Language: Mason (Perl embedded in HTML) |
| 3 | " Maintainer: Andrew Smith <andrewdsmith@yahoo.com> |
| 4 | " Last change: 2003 May 11 |
| 5 | " URL: http://www.masonhq.com/editors/mason.vim |
| 6 | " |
| 7 | " This seems to work satisfactorily with html.vim and perl.vim for version 5.5. |
| 8 | " Please mail any fixes or improvements to the above address. Things that need |
| 9 | " doing include: |
| 10 | " |
| 11 | " - Add match for component names in <& &> blocks. |
| 12 | " - Add match for component names in <%def> and <%method> block delimiters. |
| 13 | " - Fix <%text> blocks to show HTML tags but ignore Mason tags. |
| 14 | " |
| 15 | |
| 16 | " Clear previous syntax settings unless this is v6 or above, in which case just |
| 17 | " exit without doing anything. |
| 18 | " |
| 19 | if version < 600 |
| 20 | syn clear |
| 21 | elseif exists("b:current_syntax") |
| 22 | finish |
| 23 | endif |
| 24 | |
| 25 | " The HTML syntax file included below uses this variable. |
| 26 | " |
| 27 | if !exists("main_syntax") |
| 28 | let main_syntax = 'mason' |
| 29 | endif |
| 30 | |
| 31 | " First pull in the HTML syntax. |
| 32 | " |
| 33 | if version < 600 |
| 34 | so <sfile>:p:h/html.vim |
| 35 | else |
| 36 | runtime! syntax/html.vim |
| 37 | unlet b:current_syntax |
| 38 | endif |
| 39 | |
| 40 | syn cluster htmlPreproc add=@masonTop |
| 41 | |
| 42 | " Now pull in the Perl syntax. |
| 43 | " |
| 44 | if version < 600 |
| 45 | syn include @perlTop <sfile>:p:h/perl.vim |
| 46 | else |
| 47 | syn include @perlTop syntax/perl.vim |
| 48 | endif |
| 49 | |
| 50 | " It's hard to reduce down to the correct sub-set of Perl to highlight in some |
| 51 | " of these cases so I've taken the safe option of just using perlTop in all of |
| 52 | " them. If you have any suggestions, please let me know. |
| 53 | " |
| 54 | syn region masonLine matchgroup=Delimiter start="^%" end="$" contains=@perlTop |
| 55 | syn region masonExpr matchgroup=Delimiter start="<%" end="%>" contains=@perlTop |
| 56 | syn region masonPerl matchgroup=Delimiter start="<%perl>" end="</%perl>" contains=@perlTop |
| 57 | syn region masonComp keepend matchgroup=Delimiter start="<&" end="&>" contains=@perlTop |
| 58 | |
| 59 | syn region masonArgs matchgroup=Delimiter start="<%args>" end="</%args>" contains=@perlTop |
| 60 | |
| 61 | syn region masonInit matchgroup=Delimiter start="<%init>" end="</%init>" contains=@perlTop |
| 62 | syn region masonCleanup matchgroup=Delimiter start="<%cleanup>" end="</%cleanup>" contains=@perlTop |
| 63 | syn region masonOnce matchgroup=Delimiter start="<%once>" end="</%once>" contains=@perlTop |
| 64 | syn region masonShared matchgroup=Delimiter start="<%shared>" end="</%shared>" contains=@perlTop |
| 65 | |
| 66 | syn region masonDef matchgroup=Delimiter start="<%def[^>]*>" end="</%def>" contains=@htmlTop |
| 67 | syn region masonMethod matchgroup=Delimiter start="<%method[^>]*>" end="</%method>" contains=@htmlTop |
| 68 | |
| 69 | syn region masonFlags matchgroup=Delimiter start="<%flags>" end="</%flags>" contains=@perlTop |
| 70 | syn region masonAttr matchgroup=Delimiter start="<%attr>" end="</%attr>" contains=@perlTop |
| 71 | |
| 72 | syn region masonFilter matchgroup=Delimiter start="<%filter>" end="</%filter>" contains=@perlTop |
| 73 | |
| 74 | syn region masonDoc matchgroup=Delimiter start="<%doc>" end="</%doc>" |
| 75 | syn region masonText matchgroup=Delimiter start="<%text>" end="</%text>" |
| 76 | |
| 77 | syn cluster masonTop contains=masonLine,masonExpr,masonPerl,masonComp,masonArgs,masonInit,masonCleanup,masonOnce,masonShared,masonDef,masonMethod,masonFlags,masonAttr,masonFilter,masonDoc,masonText |
| 78 | |
| 79 | " Set up default highlighting. Almost all of this is done in the included |
| 80 | " syntax files. |
| 81 | " |
| 82 | if version >= 508 || !exists("did_mason_syn_inits") |
| 83 | if version < 508 |
| 84 | let did_mason_syn_inits = 1 |
| 85 | com -nargs=+ HiLink hi link <args> |
| 86 | else |
| 87 | com -nargs=+ HiLink hi def link <args> |
| 88 | endif |
| 89 | |
| 90 | HiLink masonDoc Comment |
| 91 | |
| 92 | delc HiLink |
| 93 | endif |
| 94 | |
| 95 | let b:current_syntax = "mason" |
| 96 | |
| 97 | if main_syntax == 'mason' |
| 98 | unlet main_syntax |
| 99 | endif |