cde6284f9404fcf0323362f4c28285bd.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. ace.define("ace/mode/doc_comment_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module){"use strict";
  2. var oop = require("../lib/oop");
  3. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  4. var DocCommentHighlightRules = function () {
  5. this.$rules = {
  6. "start": [{
  7. token: "comment.doc.tag",
  8. regex: "@[\\w\\d_]+" // TODO: fix email addresses
  9. },
  10. DocCommentHighlightRules.getTagRule(),
  11. {
  12. defaultToken: "comment.doc",
  13. caseInsensitive: true
  14. }]
  15. };
  16. };
  17. oop.inherits(DocCommentHighlightRules, TextHighlightRules);
  18. DocCommentHighlightRules.getTagRule = function (start) {
  19. return {
  20. token: "comment.doc.tag.storage.type",
  21. regex: "\\b(?:TODO|FIXME|XXX|HACK)\\b"
  22. };
  23. };
  24. DocCommentHighlightRules.getStartRule = function (start) {
  25. return {
  26. token: "comment.doc",
  27. regex: "\\/\\*(?=\\*)",
  28. next: start
  29. };
  30. };
  31. DocCommentHighlightRules.getEndRule = function (start) {
  32. return {
  33. token: "comment.doc",
  34. regex: "\\*\\/",
  35. next: start
  36. };
  37. };
  38. exports.DocCommentHighlightRules = DocCommentHighlightRules;
  39. });
  40. ace.define("ace/mode/golang_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/doc_comment_highlight_rules","ace/mode/text_highlight_rules"], function(require, exports, module){var oop = require("../lib/oop");
  41. var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
  42. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  43. var GolangHighlightRules = function () {
  44. var keywords = ("else|break|case|return|goto|if|const|select|" +
  45. "continue|struct|default|switch|for|range|" +
  46. "func|import|package|chan|defer|fallthrough|go|interface|map|range|" +
  47. "select|type|var");
  48. var builtinTypes = ("string|uint8|uint16|uint32|uint64|int8|int16|int32|int64|float32|" +
  49. "float64|complex64|complex128|byte|rune|uint|int|uintptr|bool|error");
  50. var builtinFunctions = ("new|close|cap|copy|panic|panicln|print|println|len|make|delete|real|recover|imag|append");
  51. var builtinConstants = ("nil|true|false|iota");
  52. var keywordMapper = this.createKeywordMapper({
  53. "keyword": keywords,
  54. "constant.language": builtinConstants,
  55. "support.function": builtinFunctions,
  56. "support.type": builtinTypes
  57. }, "");
  58. var stringEscapeRe = "\\\\(?:[0-7]{3}|x\\h{2}|u{4}|U\\h{6}|[abfnrtv'\"\\\\])".replace(/\\h/g, "[a-fA-F\\d]");
  59. this.$rules = {
  60. "start": [
  61. {
  62. token: "comment",
  63. regex: "\\/\\/.*$"
  64. },
  65. DocCommentHighlightRules.getStartRule("doc-start"),
  66. {
  67. token: "comment.start",
  68. regex: "\\/\\*",
  69. next: "comment"
  70. }, {
  71. token: "string",
  72. regex: /"(?:[^"\\]|\\.)*?"/
  73. }, {
  74. token: "string",
  75. regex: '`',
  76. next: "bqstring"
  77. }, {
  78. token: "constant.numeric",
  79. regex: "'(?:[^\\'\uD800-\uDBFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|" + stringEscapeRe.replace('"', '') + ")'"
  80. }, {
  81. token: "constant.numeric",
  82. regex: "0[xX][0-9a-fA-F]+\\b"
  83. }, {
  84. token: "constant.numeric",
  85. regex: "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
  86. }, {
  87. token: ["keyword", "text", "entity.name.function"],
  88. regex: "(func)(\\s+)([a-zA-Z_$][a-zA-Z0-9_$]*)\\b"
  89. }, {
  90. token: function (val) {
  91. if (val[val.length - 1] == "(") {
  92. return [{
  93. type: keywordMapper(val.slice(0, -1)) || "support.function",
  94. value: val.slice(0, -1)
  95. }, {
  96. type: "paren.lparen",
  97. value: val.slice(-1)
  98. }];
  99. }
  100. return keywordMapper(val) || "identifier";
  101. },
  102. regex: "[a-zA-Z_$][a-zA-Z0-9_$]*\\b\\(?"
  103. }, {
  104. token: "keyword.operator",
  105. regex: "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|==|=|!=|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^="
  106. }, {
  107. token: "punctuation.operator",
  108. regex: "\\?|\\:|\\,|\\;|\\."
  109. }, {
  110. token: "paren.lparen",
  111. regex: "[[({]"
  112. }, {
  113. token: "paren.rparen",
  114. regex: "[\\])}]"
  115. }, {
  116. token: "text",
  117. regex: "\\s+"
  118. }
  119. ],
  120. "comment": [
  121. {
  122. token: "comment.end",
  123. regex: "\\*\\/",
  124. next: "start"
  125. }, {
  126. defaultToken: "comment"
  127. }
  128. ],
  129. "bqstring": [
  130. {
  131. token: "string",
  132. regex: '`',
  133. next: "start"
  134. }, {
  135. defaultToken: "string"
  136. }
  137. ]
  138. };
  139. this.embedRules(DocCommentHighlightRules, "doc-", [DocCommentHighlightRules.getEndRule("start")]);
  140. };
  141. oop.inherits(GolangHighlightRules, TextHighlightRules);
  142. exports.GolangHighlightRules = GolangHighlightRules;
  143. });
  144. ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module){"use strict";
  145. var Range = require("../range").Range;
  146. var MatchingBraceOutdent = function () { };
  147. (function () {
  148. this.checkOutdent = function (line, input) {
  149. if (!/^\s+$/.test(line))
  150. return false;
  151. return /^\s*\}/.test(input);
  152. };
  153. this.autoOutdent = function (doc, row) {
  154. var line = doc.getLine(row);
  155. var match = line.match(/^(\s*\})/);
  156. if (!match)
  157. return 0;
  158. var column = match[1].length;
  159. var openBracePos = doc.findMatchingBracket({ row: row, column: column });
  160. if (!openBracePos || openBracePos.row == row)
  161. return 0;
  162. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  163. doc.replace(new Range(row, 0, row, column - 1), indent);
  164. };
  165. this.$getIndent = function (line) {
  166. return line.match(/^\s*/)[0];
  167. };
  168. }).call(MatchingBraceOutdent.prototype);
  169. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  170. });
  171. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module){"use strict";
  172. var oop = require("../../lib/oop");
  173. var Range = require("../../range").Range;
  174. var BaseFoldMode = require("./fold_mode").FoldMode;
  175. var FoldMode = exports.FoldMode = function (commentRegex) {
  176. if (commentRegex) {
  177. this.foldingStartMarker = new RegExp(this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start));
  178. this.foldingStopMarker = new RegExp(this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end));
  179. }
  180. };
  181. oop.inherits(FoldMode, BaseFoldMode);
  182. (function () {
  183. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  184. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  185. this.singleLineBlockCommentRe = /^\s*(\/\*).*\*\/\s*$/;
  186. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  187. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  188. this._getFoldWidgetBase = this.getFoldWidget;
  189. this.getFoldWidget = function (session, foldStyle, row) {
  190. var line = session.getLine(row);
  191. if (this.singleLineBlockCommentRe.test(line)) {
  192. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  193. return "";
  194. }
  195. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  196. if (!fw && this.startRegionRe.test(line))
  197. return "start"; // lineCommentRegionStart
  198. return fw;
  199. };
  200. this.getFoldWidgetRange = function (session, foldStyle, row, forceMultiline) {
  201. var line = session.getLine(row);
  202. if (this.startRegionRe.test(line))
  203. return this.getCommentRegionBlock(session, line, row);
  204. var match = line.match(this.foldingStartMarker);
  205. if (match) {
  206. var i = match.index;
  207. if (match[1])
  208. return this.openingBracketBlock(session, match[1], row, i);
  209. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  210. if (range && !range.isMultiLine()) {
  211. if (forceMultiline) {
  212. range = this.getSectionRange(session, row);
  213. }
  214. else if (foldStyle != "all")
  215. range = null;
  216. }
  217. return range;
  218. }
  219. if (foldStyle === "markbegin")
  220. return;
  221. var match = line.match(this.foldingStopMarker);
  222. if (match) {
  223. var i = match.index + match[0].length;
  224. if (match[1])
  225. return this.closingBracketBlock(session, match[1], row, i);
  226. return session.getCommentFoldRange(row, i, -1);
  227. }
  228. };
  229. this.getSectionRange = function (session, row) {
  230. var line = session.getLine(row);
  231. var startIndent = line.search(/\S/);
  232. var startRow = row;
  233. var startColumn = line.length;
  234. row = row + 1;
  235. var endRow = row;
  236. var maxRow = session.getLength();
  237. while (++row < maxRow) {
  238. line = session.getLine(row);
  239. var indent = line.search(/\S/);
  240. if (indent === -1)
  241. continue;
  242. if (startIndent > indent)
  243. break;
  244. var subRange = this.getFoldWidgetRange(session, "all", row);
  245. if (subRange) {
  246. if (subRange.start.row <= startRow) {
  247. break;
  248. }
  249. else if (subRange.isMultiLine()) {
  250. row = subRange.end.row;
  251. }
  252. else if (startIndent == indent) {
  253. break;
  254. }
  255. }
  256. endRow = row;
  257. }
  258. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  259. };
  260. this.getCommentRegionBlock = function (session, line, row) {
  261. var startColumn = line.search(/\s*$/);
  262. var maxRow = session.getLength();
  263. var startRow = row;
  264. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  265. var depth = 1;
  266. while (++row < maxRow) {
  267. line = session.getLine(row);
  268. var m = re.exec(line);
  269. if (!m)
  270. continue;
  271. if (m[1])
  272. depth--;
  273. else
  274. depth++;
  275. if (!depth)
  276. break;
  277. }
  278. var endRow = row;
  279. if (endRow > startRow) {
  280. return new Range(startRow, startColumn, endRow, line.length);
  281. }
  282. };
  283. }).call(FoldMode.prototype);
  284. });
  285. ace.define("ace/mode/golang",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/golang_highlight_rules","ace/mode/matching_brace_outdent","ace/mode/behaviour/cstyle","ace/mode/folding/cstyle"], function(require, exports, module){var oop = require("../lib/oop");
  286. var TextMode = require("./text").Mode;
  287. var GolangHighlightRules = require("./golang_highlight_rules").GolangHighlightRules;
  288. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  289. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  290. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  291. var Mode = function () {
  292. this.HighlightRules = GolangHighlightRules;
  293. this.$outdent = new MatchingBraceOutdent();
  294. this.foldingRules = new CStyleFoldMode();
  295. this.$behaviour = new CstyleBehaviour();
  296. };
  297. oop.inherits(Mode, TextMode);
  298. (function () {
  299. this.lineCommentStart = "//";
  300. this.blockComment = { start: "/*", end: "*/" };
  301. this.getNextLineIndent = function (state, line, tab) {
  302. var indent = this.$getIndent(line);
  303. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  304. var tokens = tokenizedLine.tokens;
  305. var endState = tokenizedLine.state;
  306. if (tokens.length && tokens[tokens.length - 1].type == "comment") {
  307. return indent;
  308. }
  309. if (state == "start") {
  310. var match = line.match(/^.*[\{\(\[]\s*$/);
  311. if (match) {
  312. indent += tab;
  313. }
  314. }
  315. return indent;
  316. }; //end getNextLineIndent
  317. this.checkOutdent = function (state, line, input) {
  318. return this.$outdent.checkOutdent(line, input);
  319. };
  320. this.autoOutdent = function (state, doc, row) {
  321. this.$outdent.autoOutdent(doc, row);
  322. };
  323. this.$id = "ace/mode/golang";
  324. }).call(Mode.prototype);
  325. exports.Mode = Mode;
  326. }); (function() {
  327. ace.require(["ace/mode/golang"], function(m) {
  328. if (typeof module == "object" && typeof exports == "object" && module) {
  329. module.exports = m;
  330. }
  331. });
  332. })();