smarty_highlight_rules.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Distributed under the BSD license:
  3. *
  4. * Copyright (c) 2012, Ajax.org B.V.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * * Neither the name of Ajax.org B.V. nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * ***** END LICENSE BLOCK ***** */
  30. /* This file was autogenerated from https://raw.github.com/amitsnyderman/sublime-smarty/master/Syntaxes/Smarty.tmLanguage (uuid: ) */
  31. /****************************************************************************************
  32. * IT MIGHT NOT BE PERFECT ...But it's a good start from an existing *.tmlanguage file. *
  33. * fileTypes *
  34. ****************************************************************************************/
  35. define(function(require, exports, module) {
  36. "use strict";
  37. var oop = require("../lib/oop");
  38. var HtmlHighlightRules = require("./html_highlight_rules").HtmlHighlightRules;
  39. var SmartyHighlightRules = function() {
  40. HtmlHighlightRules.call(this);
  41. var smartyRules = { start:
  42. [ { include: '#comments' },
  43. { include: '#blocks' } ],
  44. '#blocks':
  45. [ { token: 'punctuation.section.embedded.begin.smarty',
  46. regex: '\\{%?',
  47. push:
  48. [ { token: 'punctuation.section.embedded.end.smarty',
  49. regex: '%?\\}',
  50. next: 'pop' },
  51. { include: '#strings' },
  52. { include: '#variables' },
  53. { include: '#lang' },
  54. { defaultToken: 'source.smarty' } ] } ],
  55. '#comments':
  56. [ { token:
  57. [ 'punctuation.definition.comment.smarty',
  58. 'comment.block.smarty' ],
  59. regex: '(\\{%?)(\\*)',
  60. push:
  61. [ { token: 'comment.block.smarty', regex: '\\*%?\\}', next: 'pop' },
  62. { defaultToken: 'comment.block.smarty' } ] } ],
  63. '#lang':
  64. [ { token: 'keyword.operator.smarty',
  65. regex: '(?:!=|!|<=|>=|<|>|===|==|%|&&|\\|\\|)|\\b(?:and|or|eq|neq|ne|gte|gt|ge|lte|lt|le|not|mod)\\b' },
  66. { token: 'constant.language.smarty',
  67. regex: '\\b(?:TRUE|FALSE|true|false)\\b' },
  68. { token: 'keyword.control.smarty',
  69. regex: '\\b(?:if|else|elseif|foreach|foreachelse|section|switch|case|break|default)\\b' },
  70. { token: 'variable.parameter.smarty', regex: '\\b[a-zA-Z]+=' },
  71. { token: 'support.function.built-in.smarty',
  72. regex: '\\b(?:capture|config_load|counter|cycle|debug|eval|fetch|include_php|include|insert|literal|math|strip|rdelim|ldelim|assign|constant|block|html_[a-z_]*)\\b' },
  73. { token: 'support.function.variable-modifier.smarty',
  74. regex: '\\|(?:capitalize|cat|count_characters|count_paragraphs|count_sentences|count_words|date_format|default|escape|indent|lower|nl2br|regex_replace|replace|spacify|string_format|strip_tags|strip|truncate|upper|wordwrap)' } ],
  75. '#strings':
  76. [ { token: 'punctuation.definition.string.begin.smarty',
  77. regex: '\'',
  78. push:
  79. [ { token: 'punctuation.definition.string.end.smarty',
  80. regex: '\'',
  81. next: 'pop' },
  82. { token: 'constant.character.escape.smarty', regex: '\\\\.' },
  83. { defaultToken: 'string.quoted.single.smarty' } ] },
  84. { token: 'punctuation.definition.string.begin.smarty',
  85. regex: '"',
  86. push:
  87. [ { token: 'punctuation.definition.string.end.smarty',
  88. regex: '"',
  89. next: 'pop' },
  90. { token: 'constant.character.escape.smarty', regex: '\\\\.' },
  91. { defaultToken: 'string.quoted.double.smarty' } ] } ],
  92. '#variables':
  93. [ { token:
  94. [ 'punctuation.definition.variable.smarty',
  95. 'variable.other.global.smarty' ],
  96. regex: '\\b(\\$)(Smarty\\.)' },
  97. { token:
  98. [ 'punctuation.definition.variable.smarty',
  99. 'variable.other.smarty' ],
  100. regex: '(\\$)([a-zA-Z_][a-zA-Z0-9_]*)\\b' },
  101. { token: [ 'keyword.operator.smarty', 'variable.other.property.smarty' ],
  102. regex: '(->)([a-zA-Z_][a-zA-Z0-9_]*)\\b' },
  103. { token:
  104. [ 'keyword.operator.smarty',
  105. 'meta.function-call.object.smarty',
  106. 'punctuation.definition.variable.smarty',
  107. 'variable.other.smarty',
  108. 'punctuation.definition.variable.smarty' ],
  109. regex: '(->)([a-zA-Z_][a-zA-Z0-9_]*)(\\()(.*?)(\\))' } ] }
  110. var smartyStart = smartyRules.start;
  111. for (var rule in this.$rules) {
  112. this.$rules[rule].unshift.apply(this.$rules[rule], smartyStart);
  113. }
  114. Object.keys(smartyRules).forEach(function(x) {
  115. if (!this.$rules[x])
  116. this.$rules[x] = smartyRules[x];
  117. }, this);
  118. this.normalizeRules();
  119. };
  120. SmartyHighlightRules.metaData = { fileTypes: [ 'tpl' ],
  121. foldingStartMarker: '\\{%?',
  122. foldingStopMarker: '%?\\}',
  123. name: 'Smarty',
  124. scopeName: 'text.html.smarty' }
  125. oop.inherits(SmartyHighlightRules, HtmlHighlightRules);
  126. exports.SmartyHighlightRules = SmartyHighlightRules;
  127. });