1
0

latte.vim 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. " ================================ INCLUDES AND WHATNOT ======
  9. " ============================================================
  10. " check if we loaded this file before
  11. if exists('b:current_syntax') && b:current_syntax == 'latte'
  12. finish
  13. endif
  14. " we want to highlight PHP, HTML, CSS, JS
  15. runtime! syntax/php.vim
  16. " ============================================================
  17. " ========================================= DEFINITIONS ======
  18. " ============================================================
  19. " TODO: should we recognize things like => , : or not?
  20. " TODO: more specifically, should we allow only the macros
  21. " that really are in Latte? like:
  22. " {link Presenter:action} <-- good
  23. " {link} <-- bad
  24. " TODO: is this style (#blocks same color as $phpVars) ok?
  25. " (n:attrs different color than attrs)
  26. " TODO: macros inside <a> links
  27. " ------------------------------------------------------------
  28. " ------------------------------------------- n:attribs ------
  29. " ------------------------------------------------------------
  30. " Commented out because it breaks highlighting of inline CSS and JS.
  31. " TODO?
  32. "" n:attrib: <tag n:foo="$bar">
  33. "syn match latteAttribute contained /n:[a-zA-Z]\+\>/
  34. "" for attributes:
  35. "syn region htmlTag start=+<[^/]+ end=+>+
  36. " \ contains=htmlTagN,htmlString,htmlArg,htmlValue,htmlTagError,htmlEvent,htmlCssDefinition,@htmlPreproc,@htmlArgCluster,latteAttribute
  37. " ------------------------------------------------------------
  38. " ---------------------------------------------- macros ------
  39. " ------------------------------------------------------------
  40. " macro: {a macro}
  41. syn region latteMacro start="{\S" end="}"
  42. \ contains=latteBlockName,latteString,latteVariable
  43. " block name: #blockName
  44. syn match latteBlockName /#[$_a-zA-Z0-9]\+\>/ contained
  45. " string: 'abcdę'
  46. syn region latteString start=+'+ end=+'+ contained
  47. \ contains=latteVariable
  48. syn region latteString start=+"+ end=+"+ contained
  49. \ contains=latteVariable
  50. " ------------------------------------------------------------
  51. " -------------------------------------------- comments ------
  52. " ------------------------------------------------------------
  53. " comments: {* a basic comment *}
  54. syn region latteComment start="{\*" end="\*}"
  55. \ contains=latteTodo
  56. " todo: {* TODO something *}
  57. syn keyword latteTodo contained TODO FIXME XXX
  58. " ------------------------------------------------------------
  59. " ----------------------------------------- annotations ------
  60. " ------------------------------------------------------------
  61. " annotation comments: {** an @annotation comment *}
  62. syn region latteAnnotationComment start="{\*\*" end="\*}"
  63. \ contains=latteTodo,latteAnnotation,latteVariable,latteType
  64. " annotation: @param
  65. syn match latteAnnotation /@[$_a-zA-Z][$_a-zA-Z0-9]*\>/ contained
  66. " variable: $myVar
  67. syn match latteVariable /$[_a-zA-Z][_a-zA-Z0-9]*\>/ contained
  68. " type: string
  69. syn keyword latteType contained boolean integer float double
  70. \ string array object resource NULL
  71. " ------------------------------------------------------------
  72. " ---------------------------------------- HTML strings ------
  73. " ------------------------------------------------------------
  74. " (so we can highlight things inside them too ;) )
  75. " for values:
  76. syn region htmlString contained start=+"+ end=+"+
  77. \ contains=htmlSpecialChar,javaScriptExpression,@htmlPreproc,latteMacro,latteVariable
  78. syn region htmlString contained start=+'+ end=+'+
  79. \ contains=htmlSpecialChar,javaScriptExpression,@htmlPreproc,latteMacro,latteVariable
  80. " ============================================================
  81. " =========================================== WIRING ;) ======
  82. " ============================================================
  83. " finally, use the definitions!
  84. "hi def link latteAttribute Type
  85. hi def link latteMacro PreProc
  86. hi def link latteBlockName Identifier
  87. hi def link latteString String
  88. hi def link latteComment Comment
  89. hi def link latteTodo Todo
  90. hi def link latteAnnotationComment Comment
  91. hi def link latteAnnotation PreProc
  92. hi def link latteVariable Identifier
  93. hi def link latteType Type
  94. " prevent the file from loading again (see top)
  95. let b:current_syntax = 'latte'