mode-dot.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module) {
  2. "use strict";
  3. var Range = require("../range").Range;
  4. var MatchingBraceOutdent = function() {};
  5. (function() {
  6. this.checkOutdent = function(line, input) {
  7. if (! /^\s+$/.test(line))
  8. return false;
  9. return /^\s*\}/.test(input);
  10. };
  11. this.autoOutdent = function(doc, row) {
  12. var line = doc.getLine(row);
  13. var match = line.match(/^(\s*\})/);
  14. if (!match) return 0;
  15. var column = match[1].length;
  16. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  17. if (!openBracePos || openBracePos.row == row) return 0;
  18. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  19. doc.replace(new Range(row, 0, row, column-1), indent);
  20. };
  21. this.$getIndent = function(line) {
  22. return line.match(/^\s*/)[0];
  23. };
  24. }).call(MatchingBraceOutdent.prototype);
  25. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  26. });
  27. ace.define("ace/mode/doc_comment_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module) {
  28. "use strict";
  29. var oop = require("../lib/oop");
  30. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  31. var DocCommentHighlightRules = function() {
  32. this.$rules = {
  33. "start" : [ {
  34. token : "comment.doc.tag",
  35. regex : "@[\\w\\d_]+" // TODO: fix email addresses
  36. },
  37. DocCommentHighlightRules.getTagRule(),
  38. {
  39. defaultToken : "comment.doc",
  40. caseInsensitive: true
  41. }]
  42. };
  43. };
  44. oop.inherits(DocCommentHighlightRules, TextHighlightRules);
  45. DocCommentHighlightRules.getTagRule = function(start) {
  46. return {
  47. token : "comment.doc.tag.storage.type",
  48. regex : "\\b(?:TODO|FIXME|XXX|HACK)\\b"
  49. };
  50. }
  51. DocCommentHighlightRules.getStartRule = function(start) {
  52. return {
  53. token : "comment.doc", // doc comment
  54. regex : "\\/\\*(?=\\*)",
  55. next : start
  56. };
  57. };
  58. DocCommentHighlightRules.getEndRule = function (start) {
  59. return {
  60. token : "comment.doc", // closing comment
  61. regex : "\\*\\/",
  62. next : start
  63. };
  64. };
  65. exports.DocCommentHighlightRules = DocCommentHighlightRules;
  66. });
  67. ace.define("ace/mode/dot_highlight_rules",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/mode/text_highlight_rules","ace/mode/doc_comment_highlight_rules"], function(require, exports, module) {
  68. "use strict";
  69. var oop = require("../lib/oop");
  70. var lang = require("../lib/lang");
  71. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  72. var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
  73. var DotHighlightRules = function() {
  74. var keywords = lang.arrayToMap(
  75. ("strict|node|edge|graph|digraph|subgraph").split("|")
  76. );
  77. var attributes = lang.arrayToMap(
  78. ("damping|k|url|area|arrowhead|arrowsize|arrowtail|aspect|bb|bgcolor|center|charset|clusterrank|color|colorscheme|comment|compound|concentrate|constraint|decorate|defaultdist|dim|dimen|dir|diredgeconstraints|distortion|dpi|edgeurl|edgehref|edgetarget|edgetooltip|epsilon|esep|fillcolor|fixedsize|fontcolor|fontname|fontnames|fontpath|fontsize|forcelabels|gradientangle|group|headurl|head_lp|headclip|headhref|headlabel|headport|headtarget|headtooltip|height|href|id|image|imagepath|imagescale|label|labelurl|label_scheme|labelangle|labeldistance|labelfloat|labelfontcolor|labelfontname|labelfontsize|labelhref|labeljust|labelloc|labeltarget|labeltooltip|landscape|layer|layerlistsep|layers|layerselect|layersep|layout|len|levels|levelsgap|lhead|lheight|lp|ltail|lwidth|margin|maxiter|mclimit|mindist|minlen|mode|model|mosek|nodesep|nojustify|normalize|nslimit|nslimit1|ordering|orientation|outputorder|overlap|overlap_scaling|pack|packmode|pad|page|pagedir|pencolor|penwidth|peripheries|pin|pos|quadtree|quantum|rank|rankdir|ranksep|ratio|rects|regular|remincross|repulsiveforce|resolution|root|rotate|rotation|samehead|sametail|samplepoints|scale|searchsize|sep|shape|shapefile|showboxes|sides|size|skew|smoothing|sortv|splines|start|style|stylesheet|tailurl|tail_lp|tailclip|tailhref|taillabel|tailport|tailtarget|tailtooltip|target|tooltip|truecolor|vertices|viewport|voro_margin|weight|width|xlabel|xlp|z").split("|")
  79. );
  80. this.$rules = {
  81. "start" : [
  82. {
  83. token : "comment",
  84. regex : /\/\/.*$/
  85. }, {
  86. token : "comment",
  87. regex : /#.*$/
  88. }, {
  89. token : "comment", // multi line comment
  90. merge : true,
  91. regex : /\/\*/,
  92. next : "comment"
  93. }, {
  94. token : "string",
  95. regex : "'(?=.)",
  96. next : "qstring"
  97. }, {
  98. token : "string",
  99. regex : '"(?=.)',
  100. next : "qqstring"
  101. }, {
  102. token : "constant.numeric",
  103. regex : /[+\-]?\d+(?:(?:\.\d*)?(?:[eE][+\-]?\d+)?)?\b/
  104. }, {
  105. token : "keyword.operator",
  106. regex : /\+|=|\->/
  107. }, {
  108. token : "punctuation.operator",
  109. regex : /,|;/
  110. }, {
  111. token : "paren.lparen",
  112. regex : /[\[{]/
  113. }, {
  114. token : "paren.rparen",
  115. regex : /[\]}]/
  116. }, {
  117. token: "comment",
  118. regex: /^#!.*$/
  119. }, {
  120. token: function(value) {
  121. if (keywords.hasOwnProperty(value.toLowerCase())) {
  122. return "keyword";
  123. }
  124. else if (attributes.hasOwnProperty(value.toLowerCase())) {
  125. return "variable";
  126. }
  127. else {
  128. return "text";
  129. }
  130. },
  131. regex: "\\-?[a-zA-Z_][a-zA-Z0-9_\\-]*"
  132. }
  133. ],
  134. "comment" : [
  135. {
  136. token : "comment", // closing comment
  137. regex : ".*?\\*\\/",
  138. merge : true,
  139. next : "start"
  140. }, {
  141. token : "comment", // comment spanning whole line
  142. merge : true,
  143. regex : ".+"
  144. }
  145. ],
  146. "qqstring" : [
  147. {
  148. token : "string",
  149. regex : '[^"\\\\]+',
  150. merge : true
  151. }, {
  152. token : "string",
  153. regex : "\\\\$",
  154. next : "qqstring",
  155. merge : true
  156. }, {
  157. token : "string",
  158. regex : '"|$',
  159. next : "start",
  160. merge : true
  161. }
  162. ],
  163. "qstring" : [
  164. {
  165. token : "string",
  166. regex : "[^'\\\\]+",
  167. merge : true
  168. }, {
  169. token : "string",
  170. regex : "\\\\$",
  171. next : "qstring",
  172. merge : true
  173. }, {
  174. token : "string",
  175. regex : "'|$",
  176. next : "start",
  177. merge : true
  178. }
  179. ]
  180. };
  181. };
  182. oop.inherits(DotHighlightRules, TextHighlightRules);
  183. exports.DotHighlightRules = DotHighlightRules;
  184. });
  185. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  186. "use strict";
  187. var oop = require("../../lib/oop");
  188. var Range = require("../../range").Range;
  189. var BaseFoldMode = require("./fold_mode").FoldMode;
  190. var FoldMode = exports.FoldMode = function(commentRegex) {
  191. if (commentRegex) {
  192. this.foldingStartMarker = new RegExp(
  193. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  194. );
  195. this.foldingStopMarker = new RegExp(
  196. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  197. );
  198. }
  199. };
  200. oop.inherits(FoldMode, BaseFoldMode);
  201. (function() {
  202. this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
  203. this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
  204. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  205. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  206. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  207. this._getFoldWidgetBase = this.getFoldWidget;
  208. this.getFoldWidget = function(session, foldStyle, row) {
  209. var line = session.getLine(row);
  210. if (this.singleLineBlockCommentRe.test(line)) {
  211. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  212. return "";
  213. }
  214. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  215. if (!fw && this.startRegionRe.test(line))
  216. return "start"; // lineCommentRegionStart
  217. return fw;
  218. };
  219. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  220. var line = session.getLine(row);
  221. if (this.startRegionRe.test(line))
  222. return this.getCommentRegionBlock(session, line, row);
  223. var match = line.match(this.foldingStartMarker);
  224. if (match) {
  225. var i = match.index;
  226. if (match[1])
  227. return this.openingBracketBlock(session, match[1], row, i);
  228. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  229. if (range && !range.isMultiLine()) {
  230. if (forceMultiline) {
  231. range = this.getSectionRange(session, row);
  232. } else if (foldStyle != "all")
  233. range = null;
  234. }
  235. return range;
  236. }
  237. if (foldStyle === "markbegin")
  238. return;
  239. var match = line.match(this.foldingStopMarker);
  240. if (match) {
  241. var i = match.index + match[0].length;
  242. if (match[1])
  243. return this.closingBracketBlock(session, match[1], row, i);
  244. return session.getCommentFoldRange(row, i, -1);
  245. }
  246. };
  247. this.getSectionRange = function(session, row) {
  248. var line = session.getLine(row);
  249. var startIndent = line.search(/\S/);
  250. var startRow = row;
  251. var startColumn = line.length;
  252. row = row + 1;
  253. var endRow = row;
  254. var maxRow = session.getLength();
  255. while (++row < maxRow) {
  256. line = session.getLine(row);
  257. var indent = line.search(/\S/);
  258. if (indent === -1)
  259. continue;
  260. if (startIndent > indent)
  261. break;
  262. var subRange = this.getFoldWidgetRange(session, "all", row);
  263. if (subRange) {
  264. if (subRange.start.row <= startRow) {
  265. break;
  266. } else if (subRange.isMultiLine()) {
  267. row = subRange.end.row;
  268. } else if (startIndent == indent) {
  269. break;
  270. }
  271. }
  272. endRow = row;
  273. }
  274. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  275. };
  276. this.getCommentRegionBlock = function(session, line, row) {
  277. var startColumn = line.search(/\s*$/);
  278. var maxRow = session.getLength();
  279. var startRow = row;
  280. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  281. var depth = 1;
  282. while (++row < maxRow) {
  283. line = session.getLine(row);
  284. var m = re.exec(line);
  285. if (!m) continue;
  286. if (m[1]) depth--;
  287. else depth++;
  288. if (!depth) break;
  289. }
  290. var endRow = row;
  291. if (endRow > startRow) {
  292. return new Range(startRow, startColumn, endRow, line.length);
  293. }
  294. };
  295. }).call(FoldMode.prototype);
  296. });
  297. ace.define("ace/mode/dot",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/matching_brace_outdent","ace/mode/dot_highlight_rules","ace/mode/folding/cstyle"], function(require, exports, module) {
  298. "use strict";
  299. var oop = require("../lib/oop");
  300. var TextMode = require("./text").Mode;
  301. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  302. var DotHighlightRules = require("./dot_highlight_rules").DotHighlightRules;
  303. var DotFoldMode = require("./folding/cstyle").FoldMode;
  304. var Mode = function() {
  305. this.HighlightRules = DotHighlightRules;
  306. this.$outdent = new MatchingBraceOutdent();
  307. this.foldingRules = new DotFoldMode();
  308. this.$behaviour = this.$defaultBehaviour;
  309. };
  310. oop.inherits(Mode, TextMode);
  311. (function() {
  312. this.lineCommentStart = ["//", "#"];
  313. this.blockComment = {start: "/*", end: "*/"};
  314. this.getNextLineIndent = function(state, line, tab) {
  315. var indent = this.$getIndent(line);
  316. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  317. var tokens = tokenizedLine.tokens;
  318. var endState = tokenizedLine.state;
  319. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  320. return indent;
  321. }
  322. if (state == "start") {
  323. var match = line.match(/^.*(?:\bcase\b.*:|[\{\(\[])\s*$/);
  324. if (match) {
  325. indent += tab;
  326. }
  327. }
  328. return indent;
  329. };
  330. this.checkOutdent = function(state, line, input) {
  331. return this.$outdent.checkOutdent(line, input);
  332. };
  333. this.autoOutdent = function(state, doc, row) {
  334. this.$outdent.autoOutdent(doc, row);
  335. };
  336. this.$id = "ace/mode/dot";
  337. }).call(Mode.prototype);
  338. exports.Mode = Mode;
  339. });