PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/files/ace/1.1.5/noconflict/mode-d.js

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