latte.vim (4636B)
1 " Vim syntax file 2 " Language: Latte Templates 3 " Maintainer: Martin Janiczek <martin@janiczek.cz> 4 " Latest Revision: 11 March 2012 5 " URL: http://forum.nette.org/cs/10222-latte-vim-syntax-highlighter 6 " URL: https://github.com/janiczek/vim-latte 7 8 " ============================================================ 9 " ================================ INCLUDES AND WHATNOT ====== 10 " ============================================================ 11 12 " check if we loaded this file before 13 if exists('b:current_syntax') && b:current_syntax == 'latte' 14 finish 15 endif 16 17 " we want to highlight PHP, HTML, CSS, JS 18 runtime! syntax/php.vim 19 20 " ============================================================ 21 " ========================================= DEFINITIONS ====== 22 " ============================================================ 23 24 " TODO: should we recognize things like => , : or not? 25 " TODO: more specifically, should we allow only the macros 26 " that really are in Latte? like: 27 " {link Presenter:action} <-- good 28 " {link} <-- bad 29 " TODO: is this style (#blocks same color as $phpVars) ok? 30 " (n:attrs different color than attrs) 31 " TODO: macros inside <a> links 32 33 " ------------------------------------------------------------ 34 " ------------------------------------------- n:attribs ------ 35 " ------------------------------------------------------------ 36 37 " Commented out because it breaks highlighting of inline CSS and JS. 38 " TODO? 39 40 "" n:attrib: <tag n:foo="$bar"> 41 "syn match latteAttribute contained /n:[a-zA-Z]\+\>/ 42 43 "" for attributes: 44 "syn region htmlTag start=+<[^/]+ end=+>+ 45 " \ contains=htmlTagN,htmlString,htmlArg,htmlValue,htmlTagError,htmlEvent,htmlCssDefinition,@htmlPreproc,@htmlArgCluster,latteAttribute 46 47 " ------------------------------------------------------------ 48 " ---------------------------------------------- macros ------ 49 " ------------------------------------------------------------ 50 51 " macro: {a macro} 52 syn region latteMacro start="{\S" end="}" 53 \ contains=latteBlockName,latteString,latteVariable 54 55 " block name: #blockName 56 syn match latteBlockName /#[$_a-zA-Z0-9]\+\>/ contained 57 58 " string: 'abcdÄ™' 59 syn region latteString start=+'+ end=+'+ contained 60 \ contains=latteVariable 61 62 syn region latteString start=+"+ end=+"+ contained 63 \ contains=latteVariable 64 65 " ------------------------------------------------------------ 66 " -------------------------------------------- comments ------ 67 " ------------------------------------------------------------ 68 69 " comments: {* a basic comment *} 70 syn region latteComment start="{\*" end="\*}" 71 \ contains=latteTodo 72 73 " todo: {* TODO something *} 74 syn keyword latteTodo contained TODO FIXME XXX 75 76 " ------------------------------------------------------------ 77 " ----------------------------------------- annotations ------ 78 " ------------------------------------------------------------ 79 80 " annotation comments: {** an @annotation comment *} 81 syn region latteAnnotationComment start="{\*\*" end="\*}" 82 \ contains=latteTodo,latteAnnotation,latteVariable,latteType 83 84 " annotation: @param 85 syn match latteAnnotation /@[$_a-zA-Z][$_a-zA-Z0-9]*\>/ contained 86 87 " variable: $myVar 88 syn match latteVariable /$[_a-zA-Z][_a-zA-Z0-9]*\>/ contained 89 90 " type: string 91 syn keyword latteType contained boolean integer float double 92 \ string array object resource NULL 93 94 " ------------------------------------------------------------ 95 " ---------------------------------------- HTML strings ------ 96 " ------------------------------------------------------------ 97 " (so we can highlight things inside them too ;) ) 98 99 " for values: 100 syn region htmlString contained start=+"+ end=+"+ 101 \ contains=htmlSpecialChar,javaScriptExpression,@htmlPreproc,latteMacro,latteVariable 102 103 syn region htmlString contained start=+'+ end=+'+ 104 \ contains=htmlSpecialChar,javaScriptExpression,@htmlPreproc,latteMacro,latteVariable 105 106 " ============================================================ 107 " =========================================== WIRING ;) ====== 108 " ============================================================ 109 110 " finally, use the definitions! 111 112 "hi def link latteAttribute Type 113 114 hi def link latteMacro PreProc 115 hi def link latteBlockName Identifier 116 hi def link latteString String 117 118 hi def link latteComment Comment 119 hi def link latteTodo Todo 120 121 hi def link latteAnnotationComment Comment 122 hi def link latteAnnotation PreProc 123 hi def link latteVariable Identifier 124 hi def link latteType Type 125 126 " prevent the file from loading again (see top) 127 let b:current_syntax = 'latte'