mode-d.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. define("ace/mode/doc_comment_highlight_rules",["ace_require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(ace_require, exports, module) {
  2. "use strict";
  3. var oop = ace_require("../lib/oop");
  4. var TextHighlightRules = ace_require("./text_highlight_rules").TextHighlightRules;
  5. var DocCommentHighlightRules = function() {
  6. this.$rules = {
  7. "start" : [ {
  8. token : "comment.doc.tag",
  9. regex : "@[\\w\\d_]+" // TODO: fix email addresses
  10. },
  11. DocCommentHighlightRules.getTagRule(),
  12. {
  13. defaultToken : "comment.doc",
  14. caseInsensitive: true
  15. }]
  16. };
  17. };
  18. oop.inherits(DocCommentHighlightRules, TextHighlightRules);
  19. DocCommentHighlightRules.getTagRule = function(start) {
  20. return {
  21. token : "comment.doc.tag.storage.type",
  22. regex : "\\b(?:TODO|FIXME|XXX|HACK)\\b"
  23. };
  24. };
  25. DocCommentHighlightRules.getStartRule = function(start) {
  26. return {
  27. token : "comment.doc", // doc comment
  28. regex : "\\/\\*(?=\\*)",
  29. next : start
  30. };
  31. };
  32. DocCommentHighlightRules.getEndRule = function (start) {
  33. return {
  34. token : "comment.doc", // closing comment
  35. regex : "\\*\\/",
  36. next : start
  37. };
  38. };
  39. exports.DocCommentHighlightRules = DocCommentHighlightRules;
  40. });
  41. define("ace/mode/d_highlight_rules",["ace_require","exports","module","ace/lib/oop","ace/mode/doc_comment_highlight_rules","ace/mode/text_highlight_rules"], function(ace_require, exports, module) {
  42. "use strict";
  43. var oop = ace_require("../lib/oop");
  44. var DocCommentHighlightRules = ace_require("./doc_comment_highlight_rules").DocCommentHighlightRules;
  45. var TextHighlightRules = ace_require("./text_highlight_rules").TextHighlightRules;
  46. var DHighlightRules = function() {
  47. var keywords = (
  48. "this|super|import|module|body|mixin|__traits|invariant|alias|asm|delete|"+
  49. "typeof|typeid|sizeof|cast|new|in|is|typedef|__vector|__parameters"
  50. );
  51. var keywordControls = (
  52. "break|case|continue|default|do|else|for|foreach|foreach_reverse|goto|if|" +
  53. "return|switch|while|catch|try|throw|finally|version|assert|unittest|with"
  54. );
  55. var types = (
  56. "auto|bool|char|dchar|wchar|byte|ubyte|float|double|real|" +
  57. "cfloat|creal|cdouble|cent|ifloat|ireal|idouble|" +
  58. "int|long|short|void|uint|ulong|ushort|ucent|" +
  59. "function|delegate|string|wstring|dstring|size_t|ptrdiff_t|hash_t|Object"
  60. );
  61. var modifiers = (
  62. "abstract|align|debug|deprecated|export|extern|const|final|in|inout|out|" +
  63. "ref|immutable|lazy|nothrow|override|package|pragma|private|protected|" +
  64. "public|pure|scope|shared|__gshared|synchronized|static|volatile"
  65. );
  66. var storages = (
  67. "class|struct|union|template|interface|enum|macro"
  68. );
  69. var stringEscapesSeq = {
  70. token: "constant.language.escape",
  71. regex: "\\\\(?:(?:x[0-9A-F]{2})|(?:[0-7]{1,3})|(?:['\"\\?0abfnrtv\\\\])|" +
  72. "(?:u[0-9a-fA-F]{4})|(?:U[0-9a-fA-F]{8}))"
  73. };
  74. var builtinConstants = (
  75. "null|true|false|"+
  76. "__DATE__|__EOF__|__TIME__|__TIMESTAMP__|__VENDOR__|__VERSION__|"+
  77. "__FILE__|__MODULE__|__LINE__|__FUNCTION__|__PRETTY_FUNCTION__"
  78. );
  79. var operators = (
  80. "/|/\\=|&|&\\=|&&|\\|\\|\\=|\\|\\||\\-|\\-\\=|\\-\\-|\\+|" +
  81. "\\+\\=|\\+\\+|\\<|\\<\\=|\\<\\<|\\<\\<\\=|\\<\\>|\\<\\>\\=|\\>|\\>\\=|\\>\\>\\=|" +
  82. "\\>\\>\\>\\=|\\>\\>|\\>\\>\\>|\\!|\\!\\=|\\!\\<\\>|\\!\\<\\>\\=|\\!\\<|\\!\\<\\=|" +
  83. "\\!\\>|\\!\\>\\=|\\?|\\$|\\=|\\=\\=|\\*|\\*\\=|%|%\\=|" +
  84. "\\^|\\^\\=|\\^\\^|\\^\\^\\=|~|~\\=|\\=\\>|#"
  85. );
  86. var keywordMapper = this.$keywords = this.createKeywordMapper({
  87. "keyword.modifier" : modifiers,
  88. "keyword.control" : keywordControls,
  89. "keyword.type" : types,
  90. "keyword": keywords,
  91. "keyword.storage": storages,
  92. "punctation": "\\.|\\,|;|\\.\\.|\\.\\.\\.",
  93. "keyword.operator" : operators,
  94. "constant.language": builtinConstants
  95. }, "identifier");
  96. var identifierRe = "[a-zA-Z_\u00a1-\uffff][a-zA-Z\\d_\u00a1-\uffff]*\\b";
  97. this.$rules = {
  98. "start" : [
  99. { //-------------------------------------------------------- COMMENTS
  100. token : "comment",
  101. regex : "\\/\\/.*$"
  102. },
  103. DocCommentHighlightRules.getStartRule("doc-start"),
  104. {
  105. token : "comment", // multi line comment
  106. regex : "\\/\\*",
  107. next : "star-comment"
  108. }, {
  109. token: "comment.shebang",
  110. regex: "^\\s*#!.*"
  111. }, {
  112. token : "comment",
  113. regex : "\\/\\+",
  114. next: "plus-comment"
  115. }, { //-------------------------------------------------------- STRINGS
  116. onMatch: function(value, currentState, state) {
  117. state.unshift(this.next, value.substr(2));
  118. return "string";
  119. },
  120. regex: 'q"(?:[\\[\\(\\{\\<]+)',
  121. next: 'operator-heredoc-string'
  122. }, {
  123. onMatch: function(value, currentState, state) {
  124. state.unshift(this.next, value.substr(2));
  125. return "string";
  126. },
  127. regex: 'q"(?:[a-zA-Z_]+)$',
  128. next: 'identifier-heredoc-string'
  129. }, {
  130. token : "string", // multi line string start
  131. regex : '[xr]?"',
  132. next : "quote-string"
  133. }, {
  134. token : "string", // multi line string start
  135. regex : '[xr]?`',
  136. next : "backtick-string"
  137. }, {
  138. token : "string", // single line
  139. regex : "[xr]?['](?:(?:\\\\.)|(?:[^'\\\\]))*?['][cdw]?"
  140. }, { //-------------------------------------------------------- RULES
  141. token: ["keyword", "text", "paren.lparen"],
  142. regex: /(asm)(\s*)({)/,
  143. next: "d-asm"
  144. }, {
  145. token: ["keyword", "text", "paren.lparen", "constant.language"],
  146. regex: "(__traits)(\\s*)(\\()("+identifierRe+")"
  147. }, { // import|module abc
  148. token: ["keyword", "text", "variable.module"],
  149. regex: "(import|module)(\\s+)((?:"+identifierRe+"\\.?)*)"
  150. }, { // storage Name
  151. token: ["keyword.storage", "text", "entity.name.type"],
  152. regex: "("+storages+")(\\s*)("+identifierRe+")"
  153. }, { // alias|typedef foo bar;
  154. token: ["keyword", "text", "variable.storage", "text"],
  155. regex: "(alias|typedef)(\\s*)("+identifierRe+")(\\s*)"
  156. }, { //-------------------------------------------------------- OTHERS
  157. token : "constant.numeric", // hex
  158. regex : "0[xX][0-9a-fA-F_]+(l|ul|u|f|F|L|U|UL)?\\b"
  159. }, {
  160. token : "constant.numeric", // float
  161. regex : "[+-]?\\d[\\d_]*(?:(?:\\.[\\d_]*)?(?:[eE][+-]?[\\d_]+)?)?(l|ul|u|f|F|L|U|UL)?\\b"
  162. }, {
  163. token: "entity.other.attribute-name",
  164. regex: "@"+identifierRe
  165. }, {
  166. token : keywordMapper,
  167. regex : "[a-zA-Z_][a-zA-Z0-9_]*\\b"
  168. }, {
  169. token : "keyword.operator",
  170. regex : operators
  171. }, {
  172. token : "punctuation.operator",
  173. regex : "\\?|\\:|\\,|\\;|\\.|\\:"
  174. }, {
  175. token : "paren.lparen",
  176. regex : "[[({]"
  177. }, {
  178. token : "paren.rparen",
  179. regex : "[\\])}]"
  180. }, {
  181. token : "text",
  182. regex : "\\s+"
  183. }
  184. ],
  185. "star-comment" : [
  186. {
  187. token : "comment", // closing comment
  188. regex : "\\*\\/",
  189. next : "start"
  190. }, {
  191. defaultToken: 'comment'
  192. }
  193. ],
  194. "plus-comment" : [
  195. {
  196. token : "comment", // closing comment
  197. regex : "\\+\\/",
  198. next : "start"
  199. }, {
  200. defaultToken: 'comment'
  201. }
  202. ],
  203. "quote-string" : [
  204. stringEscapesSeq,
  205. {
  206. token : "string",
  207. regex : '"[cdw]?',
  208. next : "start"
  209. }, {
  210. defaultToken: 'string'
  211. }
  212. ],
  213. "backtick-string" : [
  214. stringEscapesSeq,
  215. {
  216. token : "string",
  217. regex : '`[cdw]?',
  218. next : "start"
  219. }, {
  220. defaultToken: 'string'
  221. }
  222. ],
  223. "operator-heredoc-string": [
  224. {
  225. onMatch: function(value, currentState, state) {
  226. value = value.substring(value.length-2, value.length-1);
  227. var map = {'>':'<',']':'[',')':'(','}':'{'};
  228. if(Object.keys(map).indexOf(value) != -1)
  229. value = map[value];
  230. if(value != state[1]) return "string";
  231. state.shift();
  232. state.shift();
  233. return "string";
  234. },
  235. regex: '(?:[\\]\\)}>]+)"',
  236. next: 'start'
  237. }, {
  238. token: 'string',
  239. regex: '[^\\]\\)}>]+'
  240. }
  241. ],
  242. "identifier-heredoc-string": [
  243. {
  244. onMatch: function(value, currentState, state) {
  245. value = value.substring(0, value.length-1);
  246. if(value != state[1]) return "string";
  247. state.shift();
  248. state.shift();
  249. return "string";
  250. },
  251. regex: '^(?:[A-Za-z_][a-zA-Z0-9]+)"',
  252. next: 'start'
  253. }, {
  254. token: 'string',
  255. regex: '[^\\]\\)}>]+'
  256. }
  257. ],
  258. "d-asm": [
  259. {
  260. token: "paren.rparen",
  261. regex: "\\}",
  262. next: "start"
  263. }, {
  264. token: 'keyword.instruction',
  265. regex: '[a-zA-Z]+',
  266. next: 'd-asm-instruction'
  267. }, {
  268. token: "text",
  269. regex: "\\s+"
  270. }
  271. ],
  272. 'd-asm-instruction': [
  273. {
  274. token: 'constant.language',
  275. regex: /AL|AH|AX|EAX|BL|BH|BX|EBX|CL|CH|CX|ECX|DL|DH|DX|EDX|BP|EBP|SP|ESP|DI|EDI|SI|ESI/i
  276. }, {
  277. token: 'identifier',
  278. regex: '[a-zA-Z]+'
  279. }, {
  280. token: 'string',
  281. regex: '".*"'
  282. }, {
  283. token: 'comment',
  284. regex: '//.*$'
  285. }, {
  286. token: 'constant.numeric',
  287. regex: '[0-9.xA-F]+'
  288. }, {
  289. token: 'punctuation.operator',
  290. regex: '\\,'
  291. }, {
  292. token: 'punctuation.operator',
  293. regex: ';',
  294. next: 'd-asm'
  295. }, {
  296. token: 'text',
  297. regex: '\\s+'
  298. }
  299. ]
  300. };
  301. this.embedRules(DocCommentHighlightRules, "doc-",
  302. [ DocCommentHighlightRules.getEndRule("start") ]);
  303. };
  304. DHighlightRules.metaData = {
  305. comment: 'D language',
  306. fileTypes: [ 'd', 'di' ],
  307. firstLineMatch: '^#!.*\\b[glr]?dmd\\b.',
  308. foldingStartMarker: '(?x)/\\*\\*(?!\\*)|^(?![^{]*?//|[^{]*?/\\*(?!.*?\\*/.*?\\{)).*?\\{\\s*($|//|/\\*(?!.*?\\*/.*\\S))',
  309. foldingStopMarker: '(?<!\\*)\\*\\*/|^\\s*\\}',
  310. keyEquivalent: '^~D',
  311. name: 'D',
  312. scopeName: 'source.d'
  313. };
  314. oop.inherits(DHighlightRules, TextHighlightRules);
  315. exports.DHighlightRules = DHighlightRules;
  316. });
  317. define("ace/mode/folding/cstyle",["ace_require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(ace_require, exports, module) {
  318. "use strict";
  319. var oop = ace_require("../../lib/oop");
  320. var Range = ace_require("../../range").Range;
  321. var BaseFoldMode = ace_require("./fold_mode").FoldMode;
  322. var FoldMode = exports.FoldMode = function(commentRegex) {
  323. if (commentRegex) {
  324. this.foldingStartMarker = new RegExp(
  325. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  326. );
  327. this.foldingStopMarker = new RegExp(
  328. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  329. );
  330. }
  331. };
  332. oop.inherits(FoldMode, BaseFoldMode);
  333. (function() {
  334. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  335. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  336. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  337. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  338. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  339. this._getFoldWidgetBase = this.getFoldWidget;
  340. this.getFoldWidget = function(session, foldStyle, row) {
  341. var line = session.getLine(row);
  342. if (this.singleLineBlockCommentRe.test(line)) {
  343. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  344. return "";
  345. }
  346. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  347. if (!fw && this.startRegionRe.test(line))
  348. return "start"; // lineCommentRegionStart
  349. return fw;
  350. };
  351. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  352. var line = session.getLine(row);
  353. if (this.startRegionRe.test(line))
  354. return this.getCommentRegionBlock(session, line, row);
  355. var match = line.match(this.foldingStartMarker);
  356. if (match) {
  357. var i = match.index;
  358. if (match[1])
  359. return this.openingBracketBlock(session, match[1], row, i);
  360. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  361. if (range && !range.isMultiLine()) {
  362. if (forceMultiline) {
  363. range = this.getSectionRange(session, row);
  364. } else if (foldStyle != "all")
  365. range = null;
  366. }
  367. return range;
  368. }
  369. if (foldStyle === "markbegin")
  370. return;
  371. var match = line.match(this.foldingStopMarker);
  372. if (match) {
  373. var i = match.index + match[0].length;
  374. if (match[1])
  375. return this.closingBracketBlock(session, match[1], row, i);
  376. return session.getCommentFoldRange(row, i, -1);
  377. }
  378. };
  379. this.getSectionRange = function(session, row) {
  380. var line = session.getLine(row);
  381. var startIndent = line.search(/\S/);
  382. var startRow = row;
  383. var startColumn = line.length;
  384. row = row + 1;
  385. var endRow = row;
  386. var maxRow = session.getLength();
  387. while (++row < maxRow) {
  388. line = session.getLine(row);
  389. var indent = line.search(/\S/);
  390. if (indent === -1)
  391. continue;
  392. if (startIndent > indent)
  393. break;
  394. var subRange = this.getFoldWidgetRange(session, "all", row);
  395. if (subRange) {
  396. if (subRange.start.row <= startRow) {
  397. break;
  398. } else if (subRange.isMultiLine()) {
  399. row = subRange.end.row;
  400. } else if (startIndent == indent) {
  401. break;
  402. }
  403. }
  404. endRow = row;
  405. }
  406. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  407. };
  408. this.getCommentRegionBlock = function(session, line, row) {
  409. var startColumn = line.search(/\s*$/);
  410. var maxRow = session.getLength();
  411. var startRow = row;
  412. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  413. var depth = 1;
  414. while (++row < maxRow) {
  415. line = session.getLine(row);
  416. var m = re.exec(line);
  417. if (!m) continue;
  418. if (m[1]) depth--;
  419. else depth++;
  420. if (!depth) break;
  421. }
  422. var endRow = row;
  423. if (endRow > startRow) {
  424. return new Range(startRow, startColumn, endRow, line.length);
  425. }
  426. };
  427. }).call(FoldMode.prototype);
  428. });
  429. define("ace/mode/d",["ace_require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/d_highlight_rules","ace/mode/folding/cstyle"], function(ace_require, exports, module) {
  430. "use strict";
  431. var oop = ace_require("../lib/oop");
  432. var TextMode = ace_require("./text").Mode;
  433. var DHighlightRules = ace_require("./d_highlight_rules").DHighlightRules;
  434. var FoldMode = ace_require("./folding/cstyle").FoldMode;
  435. var Mode = function() {
  436. this.HighlightRules = DHighlightRules;
  437. this.foldingRules = new FoldMode();
  438. this.$behaviour = this.$defaultBehaviour;
  439. };
  440. oop.inherits(Mode, TextMode);
  441. (function() {
  442. this.lineCommentStart = "//";
  443. this.blockComment = {start: "/*", end: "*/"};
  444. this.$id = "ace/mode/d";
  445. }).call(Mode.prototype);
  446. exports.Mode = Mode;
  447. }); (function() {
  448. window.ace_require(["ace/mode/d"], function(m) {
  449. if (typeof module == "object" && typeof exports == "object" && module) {
  450. module.exports = m;
  451. }
  452. });
  453. })();