mode-julia.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. ace.define("ace/mode/julia_highlight_rules",[], function(require, exports, module) {
  2. "use strict";
  3. var oop = require("../lib/oop");
  4. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  5. var JuliaHighlightRules = function() {
  6. this.$rules = { start:
  7. [ { include: '#function_decl' },
  8. { include: '#function_call' },
  9. { include: '#type_decl' },
  10. { include: '#keyword' },
  11. { include: '#operator' },
  12. { include: '#number' },
  13. { include: '#string' },
  14. { include: '#comment' } ],
  15. '#bracket':
  16. [ { token: 'keyword.bracket.julia',
  17. regex: '\\(|\\)|\\[|\\]|\\{|\\}|,' } ],
  18. '#comment':
  19. [ { token:
  20. [ 'punctuation.definition.comment.julia',
  21. 'comment.line.number-sign.julia' ],
  22. regex: '(#)(?!\\{)(.*$)'} ],
  23. '#function_call':
  24. [ { token: [ 'support.function.julia', 'text' ],
  25. regex: '([a-zA-Z0-9_]+!?)([\\w\\xff-\\u218e\\u2455-\\uffff]*\\()'} ],
  26. '#function_decl':
  27. [ { token: [ 'keyword.other.julia', 'meta.function.julia',
  28. 'entity.name.function.julia', 'meta.function.julia','text' ],
  29. regex: '(function|macro)(\\s*)([a-zA-Z0-9_\\{]+!?)([\\w\\xff-\\u218e\\u2455-\\uffff]*)([(\\\\{])'} ],
  30. '#keyword':
  31. [ { token: 'keyword.other.julia',
  32. regex: '\\b(?:function|type|immutable|macro|quote|abstract|bitstype|typealias|module|baremodule|new)\\b' },
  33. { token: 'keyword.control.julia',
  34. regex: '\\b(?:if|else|elseif|while|for|in|begin|let|end|do|try|catch|finally|return|break|continue)\\b' },
  35. { token: 'storage.modifier.variable.julia',
  36. regex: '\\b(?:global|local|const|export|import|importall|using)\\b' },
  37. { token: 'variable.macro.julia', regex: '@[\\w\\xff-\\u218e\\u2455-\\uffff]+\\b' } ],
  38. '#number':
  39. [ { token: 'constant.numeric.julia',
  40. 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' } ],
  41. '#operator':
  42. [ { token: 'keyword.operator.update.julia',
  43. regex: '=|:=|\\+=|-=|\\*=|/=|//=|\\.//=|\\.\\*=|\\\\=|\\.\\\\=|^=|\\.^=|%=|\\|=|&=|\\$=|<<=|>>=' },
  44. { token: 'keyword.operator.ternary.julia', regex: '\\?|:' },
  45. { token: 'keyword.operator.boolean.julia',
  46. regex: '\\|\\||&&|!' },
  47. { token: 'keyword.operator.arrow.julia', regex: '->|<-|-->' },
  48. { token: 'keyword.operator.relation.julia',
  49. regex: '>|<|>=|<=|==|!=|\\.>|\\.<|\\.>=|\\.>=|\\.==|\\.!=|\\.=|\\.!|<:|:>' },
  50. { token: 'keyword.operator.range.julia', regex: ':' },
  51. { token: 'keyword.operator.shift.julia', regex: '<<|>>' },
  52. { token: 'keyword.operator.bitwise.julia', regex: '\\||\\&|~' },
  53. { token: 'keyword.operator.arithmetic.julia',
  54. regex: '\\+|-|\\*|\\.\\*|/|\\./|//|\\.//|%|\\.%|\\\\|\\.\\\\|\\^|\\.\\^' },
  55. { token: 'keyword.operator.isa.julia', regex: '::' },
  56. { token: 'keyword.operator.dots.julia',
  57. regex: '\\.(?=[a-zA-Z])|\\.\\.+' },
  58. { token: 'keyword.operator.interpolation.julia',
  59. regex: '\\$#?(?=.)' },
  60. { token: [ 'variable', 'keyword.operator.transposed-variable.julia' ],
  61. regex: '([\\w\\xff-\\u218e\\u2455-\\uffff]+)((?:\'|\\.\')*\\.?\')' },
  62. { token: 'text',
  63. regex: '\\[|\\('},
  64. { token: [ 'text', 'keyword.operator.transposed-matrix.julia' ],
  65. regex: "([\\]\\)])((?:'|\\.')*\\.?')"} ],
  66. '#string':
  67. [ { token: 'punctuation.definition.string.begin.julia',
  68. regex: '\'',
  69. push:
  70. [ { token: 'punctuation.definition.string.end.julia',
  71. regex: '\'',
  72. next: 'pop' },
  73. { include: '#string_escaped_char' },
  74. { defaultToken: 'string.quoted.single.julia' } ] },
  75. { token: 'punctuation.definition.string.begin.julia',
  76. regex: '"',
  77. push:
  78. [ { token: 'punctuation.definition.string.end.julia',
  79. regex: '"',
  80. next: 'pop' },
  81. { include: '#string_escaped_char' },
  82. { defaultToken: 'string.quoted.double.julia' } ] },
  83. { token: 'punctuation.definition.string.begin.julia',
  84. regex: '\\b[\\w\\xff-\\u218e\\u2455-\\uffff]+"',
  85. push:
  86. [ { token: 'punctuation.definition.string.end.julia',
  87. regex: '"[\\w\\xff-\\u218e\\u2455-\\uffff]*',
  88. next: 'pop' },
  89. { include: '#string_custom_escaped_char' },
  90. { defaultToken: 'string.quoted.custom-double.julia' } ] },
  91. { token: 'punctuation.definition.string.begin.julia',
  92. regex: '`',
  93. push:
  94. [ { token: 'punctuation.definition.string.end.julia',
  95. regex: '`',
  96. next: 'pop' },
  97. { include: '#string_escaped_char' },
  98. { defaultToken: 'string.quoted.backtick.julia' } ] } ],
  99. '#string_custom_escaped_char': [ { token: 'constant.character.escape.julia', regex: '\\\\"' } ],
  100. '#string_escaped_char':
  101. [ { token: 'constant.character.escape.julia',
  102. 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}|.)' } ],
  103. '#type_decl':
  104. [ { token:
  105. [ 'keyword.control.type.julia',
  106. 'meta.type.julia',
  107. 'entity.name.type.julia',
  108. 'entity.other.inherited-class.julia',
  109. 'punctuation.separator.inheritance.julia',
  110. 'entity.other.inherited-class.julia' ],
  111. regex: '(type|immutable)(\\s+)([a-zA-Z0-9_]+)(?:(\\s*)(<:)(\\s*[.a-zA-Z0-9_:]+))?' },
  112. { token: [ 'other.typed-variable.julia', 'support.type.julia' ],
  113. regex: '([a-zA-Z0-9_]+)(::[a-zA-Z0-9_{}]+)' } ] };
  114. this.normalizeRules();
  115. };
  116. JuliaHighlightRules.metaData = { fileTypes: [ 'jl' ],
  117. firstLineMatch: '^#!.*\\bjulia\\s*$',
  118. foldingStartMarker: '^\\s*(?:if|while|for|begin|function|macro|module|baremodule|type|immutable|let)\\b(?!.*\\bend\\b).*$',
  119. foldingStopMarker: '^\\s*(?:end)\\b.*$',
  120. name: 'Julia',
  121. scopeName: 'source.julia' };
  122. oop.inherits(JuliaHighlightRules, TextHighlightRules);
  123. exports.JuliaHighlightRules = JuliaHighlightRules;
  124. });
  125. ace.define("ace/mode/folding/cstyle",[], function(require, exports, module) {
  126. "use strict";
  127. var oop = require("../../lib/oop");
  128. var Range = require("../../range").Range;
  129. var BaseFoldMode = require("./fold_mode").FoldMode;
  130. var FoldMode = exports.FoldMode = function(commentRegex) {
  131. if (commentRegex) {
  132. this.foldingStartMarker = new RegExp(
  133. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  134. );
  135. this.foldingStopMarker = new RegExp(
  136. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  137. );
  138. }
  139. };
  140. oop.inherits(FoldMode, BaseFoldMode);
  141. (function() {
  142. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  143. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  144. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  145. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  146. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  147. this._getFoldWidgetBase = this.getFoldWidget;
  148. this.getFoldWidget = function(session, foldStyle, row) {
  149. var line = session.getLine(row);
  150. if (this.singleLineBlockCommentRe.test(line)) {
  151. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  152. return "";
  153. }
  154. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  155. if (!fw && this.startRegionRe.test(line))
  156. return "start"; // lineCommentRegionStart
  157. return fw;
  158. };
  159. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  160. var line = session.getLine(row);
  161. if (this.startRegionRe.test(line))
  162. return this.getCommentRegionBlock(session, line, row);
  163. var match = line.match(this.foldingStartMarker);
  164. if (match) {
  165. var i = match.index;
  166. if (match[1])
  167. return this.openingBracketBlock(session, match[1], row, i);
  168. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  169. if (range && !range.isMultiLine()) {
  170. if (forceMultiline) {
  171. range = this.getSectionRange(session, row);
  172. } else if (foldStyle != "all")
  173. range = null;
  174. }
  175. return range;
  176. }
  177. if (foldStyle === "markbegin")
  178. return;
  179. var match = line.match(this.foldingStopMarker);
  180. if (match) {
  181. var i = match.index + match[0].length;
  182. if (match[1])
  183. return this.closingBracketBlock(session, match[1], row, i);
  184. return session.getCommentFoldRange(row, i, -1);
  185. }
  186. };
  187. this.getSectionRange = function(session, row) {
  188. var line = session.getLine(row);
  189. var startIndent = line.search(/\S/);
  190. var startRow = row;
  191. var startColumn = line.length;
  192. row = row + 1;
  193. var endRow = row;
  194. var maxRow = session.getLength();
  195. while (++row < maxRow) {
  196. line = session.getLine(row);
  197. var indent = line.search(/\S/);
  198. if (indent === -1)
  199. continue;
  200. if (startIndent > indent)
  201. break;
  202. var subRange = this.getFoldWidgetRange(session, "all", row);
  203. if (subRange) {
  204. if (subRange.start.row <= startRow) {
  205. break;
  206. } else if (subRange.isMultiLine()) {
  207. row = subRange.end.row;
  208. } else if (startIndent == indent) {
  209. break;
  210. }
  211. }
  212. endRow = row;
  213. }
  214. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  215. };
  216. this.getCommentRegionBlock = function(session, line, row) {
  217. var startColumn = line.search(/\s*$/);
  218. var maxRow = session.getLength();
  219. var startRow = row;
  220. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  221. var depth = 1;
  222. while (++row < maxRow) {
  223. line = session.getLine(row);
  224. var m = re.exec(line);
  225. if (!m) continue;
  226. if (m[1]) depth--;
  227. else depth++;
  228. if (!depth) break;
  229. }
  230. var endRow = row;
  231. if (endRow > startRow) {
  232. return new Range(startRow, startColumn, endRow, line.length);
  233. }
  234. };
  235. }).call(FoldMode.prototype);
  236. });
  237. ace.define("ace/mode/julia",[], function(require, exports, module) {
  238. "use strict";
  239. var oop = require("../lib/oop");
  240. var TextMode = require("./text").Mode;
  241. var JuliaHighlightRules = require("./julia_highlight_rules").JuliaHighlightRules;
  242. var FoldMode = require("./folding/cstyle").FoldMode;
  243. var Mode = function() {
  244. this.HighlightRules = JuliaHighlightRules;
  245. this.foldingRules = new FoldMode();
  246. this.$behaviour = this.$defaultBehaviour;
  247. };
  248. oop.inherits(Mode, TextMode);
  249. (function() {
  250. this.lineCommentStart = "#";
  251. this.blockComment = "";
  252. this.$id = "ace/mode/julia";
  253. }).call(Mode.prototype);
  254. exports.Mode = Mode;
  255. });
  256. (function() {
  257. ace.require(["ace/mode/julia"], function(m) {
  258. if (typeof module == "object" && typeof exports == "object" && module) {
  259. module.exports = m;
  260. }
  261. });
  262. })();