tcl_highlight_rules.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Distributed under the BSD license:
  3. *
  4. * Copyright (c) 2010, 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. define(function(require, exports, module) {
  31. "use strict";
  32. var oop = require("../lib/oop");
  33. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  34. var TclHighlightRules = function() {
  35. //TODO var builtinFunctions = "";
  36. this.$rules = {
  37. "start" : [
  38. {
  39. token : "comment",
  40. regex : "#.*\\\\$",
  41. next : "commentfollow"
  42. }, {
  43. token : "comment",
  44. regex : "#.*$"
  45. }, {
  46. token : "support.function",
  47. regex : '[\\\\]$',
  48. next : "splitlineStart"
  49. }, {
  50. token : "text",
  51. regex : '[\\\\](?:["]|[{]|[}]|[[]|[]]|[$]|[\])'
  52. }, {
  53. token : "text", // last value before command
  54. regex : '^|[^{][;][^}]|[/\r/]',
  55. next : "commandItem"
  56. }, {
  57. token : "string", // single line
  58. regex : '[ ]*["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  59. }, {
  60. token : "string", // multi line """ string start
  61. regex : '[ ]*["]',
  62. next : "qqstring"
  63. }, {
  64. token : "variable.instance",
  65. regex : "[$]",
  66. next : "variable"
  67. }, {
  68. token : "support.function",
  69. regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|{\\*}|;|::"
  70. }, {
  71. token : "identifier",
  72. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  73. }, {
  74. token : "paren.lparen",
  75. regex : "[[{]",
  76. next : "commandItem"
  77. }, {
  78. token : "paren.lparen",
  79. regex : "[(]"
  80. }, {
  81. token : "paren.rparen",
  82. regex : "[\\])}]"
  83. }, {
  84. token : "text",
  85. regex : "\\s+"
  86. }
  87. ],
  88. "commandItem" : [
  89. {
  90. token : "comment",
  91. regex : "#.*\\\\$",
  92. next : "commentfollow"
  93. }, {
  94. token : "comment",
  95. regex : "#.*$",
  96. next : "start"
  97. }, {
  98. token : "string", // single line
  99. regex : '[ ]*["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  100. }, {
  101. token : "variable.instance",
  102. regex : "[$]",
  103. next : "variable"
  104. }, {
  105. token : "support.function",
  106. regex : "(?:[:][:])[a-zA-Z0-9_/]+(?:[:][:])",
  107. next : "commandItem"
  108. }, {
  109. token : "support.function",
  110. regex : "[a-zA-Z0-9_/]+(?:[:][:])",
  111. next : "commandItem"
  112. }, {
  113. token : "support.function",
  114. regex : "(?:[:][:])",
  115. next : "commandItem"
  116. }, {
  117. token : "paren.rparen",
  118. regex : "[\\])}]"
  119. }, {
  120. token : "support.function",
  121. regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|{\\*}|;|::"
  122. }, {
  123. token : "keyword",
  124. regex : "[a-zA-Z0-9_/]+",
  125. next : "start"
  126. } ],
  127. "commentfollow" : [
  128. {
  129. token : "comment",
  130. regex : ".*\\\\$",
  131. next : "commentfollow"
  132. }, {
  133. token : "comment",
  134. regex : '.+',
  135. next : "start"
  136. } ],
  137. "splitlineStart" : [
  138. {
  139. token : "text",
  140. regex : "^.",
  141. next : "start"
  142. }],
  143. "variable" : [
  144. {
  145. token : "variable.instance", // variable tcl
  146. regex : "[a-zA-Z_\\d]+(?:[(][a-zA-Z_\\d]+[)])?",
  147. next : "start"
  148. }, {
  149. token : "variable.instance", // variable tcl with braces
  150. regex : "{?[a-zA-Z_\\d]+}?",
  151. next : "start"
  152. }],
  153. "qqstring" : [ {
  154. token : "string", // multi line """ string end
  155. regex : '(?:[^\\\\]|\\\\.)*?["]',
  156. next : "start"
  157. }, {
  158. token : "string",
  159. regex : '.+'
  160. } ]
  161. };
  162. };
  163. oop.inherits(TclHighlightRules, TextHighlightRules);
  164. exports.TclHighlightRules = TclHighlightRules;
  165. });