julia_highlight_rules.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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/JuliaLang/julia/master/contrib/Julia.tmbundle/Syntaxes/Julia.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 TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  39. var JuliaHighlightRules = function() {
  40. // regexp must not have capturing parentheses. Use (?:) instead.
  41. // regexps are ordered -> the first match is used
  42. this.$rules = { start:
  43. [ { include: '#function_decl' },
  44. { include: '#function_call' },
  45. { include: '#type_decl' },
  46. { include: '#keyword' },
  47. { include: '#operator' },
  48. { include: '#number' },
  49. { include: '#string' },
  50. { include: '#comment' } ],
  51. '#bracket':
  52. [ { token: 'keyword.bracket.julia',
  53. regex: '\\(|\\)|\\[|\\]|\\{|\\}|,' } ],
  54. '#comment':
  55. [ { token:
  56. [ 'punctuation.definition.comment.julia',
  57. 'comment.line.number-sign.julia' ],
  58. regex: '(#)(?!\\{)(.*$)'} ],
  59. '#function_call':
  60. [ { token: [ 'support.function.julia', 'text' ],
  61. regex: '([a-zA-Z0-9_]+!?)([\\w\\xff-\\u218e\\u2455-\\uffff]*\\()'} ],
  62. '#function_decl':
  63. [ { token: [ 'keyword.other.julia', 'meta.function.julia',
  64. 'entity.name.function.julia', 'meta.function.julia','text' ],
  65. regex: '(function|macro)(\\s*)([a-zA-Z0-9_\\{]+!?)([\\w\\xff-\\u218e\\u2455-\\uffff]*)([(\\\\{])'} ],
  66. '#keyword':
  67. [ { token: 'keyword.other.julia',
  68. regex: '\\b(?:function|type|immutable|macro|quote|abstract|bitstype|typealias|module|baremodule|new)\\b' },
  69. { token: 'keyword.control.julia',
  70. regex: '\\b(?:if|else|elseif|while|for|in|begin|let|end|do|try|catch|finally|return|break|continue)\\b' },
  71. { token: 'storage.modifier.variable.julia',
  72. regex: '\\b(?:global|local|const|export|import|importall|using)\\b' },
  73. { token: 'variable.macro.julia', regex: '@[\\w\\xff-\\u218e\\u2455-\\uffff]+\\b' } ],
  74. '#number':
  75. [ { token: 'constant.numeric.julia',
  76. regex: '\\b0(?:x|X)[0-9a-fA-F]*|(?:\\b[0-9]+\\.?[0-9]*|\\.[0-9]+)(?:(?:e|E)(?:\\+|-)?[0-9]*)?(?:im)?|\\bInf(?:32)?\\b|\\bNaN(?:32)?\\b|\\btrue\\b|\\bfalse\\b' } ],
  77. '#operator':
  78. [ { token: 'keyword.operator.update.julia',
  79. regex: '=|:=|\\+=|-=|\\*=|/=|//=|\\.//=|\\.\\*=|\\\\=|\\.\\\\=|^=|\\.^=|%=|\\|=|&=|\\$=|<<=|>>=' },
  80. { token: 'keyword.operator.ternary.julia', regex: '\\?|:' },
  81. { token: 'keyword.operator.boolean.julia',
  82. regex: '\\|\\||&&|!' },
  83. { token: 'keyword.operator.arrow.julia', regex: '->|<-|-->' },
  84. { token: 'keyword.operator.relation.julia',
  85. regex: '>|<|>=|<=|==|!=|\\.>|\\.<|\\.>=|\\.>=|\\.==|\\.!=|\\.=|\\.!|<:|:>' },
  86. { token: 'keyword.operator.range.julia', regex: ':' },
  87. { token: 'keyword.operator.shift.julia', regex: '<<|>>' },
  88. { token: 'keyword.operator.bitwise.julia', regex: '\\||\\&|~' },
  89. { token: 'keyword.operator.arithmetic.julia',
  90. regex: '\\+|-|\\*|\\.\\*|/|\\./|//|\\.//|%|\\.%|\\\\|\\.\\\\|\\^|\\.\\^' },
  91. { token: 'keyword.operator.isa.julia', regex: '::' },
  92. { token: 'keyword.operator.dots.julia',
  93. regex: '\\.(?=[a-zA-Z])|\\.\\.+' },
  94. { token: 'keyword.operator.interpolation.julia',
  95. regex: '\\$#?(?=.)' },
  96. { token: [ 'variable', 'keyword.operator.transposed-variable.julia' ],
  97. regex: '([\\w\\xff-\\u218e\\u2455-\\uffff]+)((?:\'|\\.\')*\\.?\')' },
  98. { token: 'text',
  99. regex: '\\[|\\('},
  100. { token: [ 'text', 'keyword.operator.transposed-matrix.julia' ],
  101. regex: "([\\]\\)])((?:'|\\.')*\\.?')"} ],
  102. '#string':
  103. [ { token: 'punctuation.definition.string.begin.julia',
  104. regex: '\'',
  105. push:
  106. [ { token: 'punctuation.definition.string.end.julia',
  107. regex: '\'',
  108. next: 'pop' },
  109. { include: '#string_escaped_char' },
  110. { defaultToken: 'string.quoted.single.julia' } ] },
  111. { token: 'punctuation.definition.string.begin.julia',
  112. regex: '"',
  113. push:
  114. [ { token: 'punctuation.definition.string.end.julia',
  115. regex: '"',
  116. next: 'pop' },
  117. { include: '#string_escaped_char' },
  118. { defaultToken: 'string.quoted.double.julia' } ] },
  119. { token: 'punctuation.definition.string.begin.julia',
  120. regex: '\\b[\\w\\xff-\\u218e\\u2455-\\uffff]+"',
  121. push:
  122. [ { token: 'punctuation.definition.string.end.julia',
  123. regex: '"[\\w\\xff-\\u218e\\u2455-\\uffff]*',
  124. next: 'pop' },
  125. { include: '#string_custom_escaped_char' },
  126. { defaultToken: 'string.quoted.custom-double.julia' } ] },
  127. { token: 'punctuation.definition.string.begin.julia',
  128. regex: '`',
  129. push:
  130. [ { token: 'punctuation.definition.string.end.julia',
  131. regex: '`',
  132. next: 'pop' },
  133. { include: '#string_escaped_char' },
  134. { defaultToken: 'string.quoted.backtick.julia' } ] } ],
  135. '#string_custom_escaped_char': [ { token: 'constant.character.escape.julia', regex: '\\\\"' } ],
  136. '#string_escaped_char':
  137. [ { token: 'constant.character.escape.julia',
  138. regex: '\\\\(?:\\\\|[0-3]\\d{,2}|[4-7]\\d?|x[a-fA-F0-9]{,2}|u[a-fA-F0-9]{,4}|U[a-fA-F0-9]{,8}|.)' } ],
  139. '#type_decl':
  140. [ { token:
  141. [ 'keyword.control.type.julia',
  142. 'meta.type.julia',
  143. 'entity.name.type.julia',
  144. 'entity.other.inherited-class.julia',
  145. 'punctuation.separator.inheritance.julia',
  146. 'entity.other.inherited-class.julia' ],
  147. regex: '(type|immutable)(\\s+)([a-zA-Z0-9_]+)(?:(\\s*)(<:)(\\s*[.a-zA-Z0-9_:]+))?' },
  148. { token: [ 'other.typed-variable.julia', 'support.type.julia' ],
  149. regex: '([a-zA-Z0-9_]+)(::[a-zA-Z0-9_{}]+)' } ] }
  150. this.normalizeRules();
  151. };
  152. JuliaHighlightRules.metaData = { fileTypes: [ 'jl' ],
  153. firstLineMatch: '^#!.*\\bjulia\\s*$',
  154. foldingStartMarker: '^\\s*(?:if|while|for|begin|function|macro|module|baremodule|type|immutable|let)\\b(?!.*\\bend\\b).*$',
  155. foldingStopMarker: '^\\s*(?:end)\\b.*$',
  156. name: 'Julia',
  157. scopeName: 'source.julia' }
  158. oop.inherits(JuliaHighlightRules, TextHighlightRules);
  159. exports.JuliaHighlightRules = JuliaHighlightRules;
  160. });