2218ddba12711e7e7f6aea96015bafa2.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. ace.define("ace/mode/sh_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 reservedKeywords = exports.reservedKeywords = ('!|{|}|case|do|done|elif|else|' +
  5. 'esac|fi|for|if|in|then|until|while|' +
  6. '&|;|export|local|read|typeset|unset|' +
  7. 'elif|select|set|function|declare|readonly');
  8. var languageConstructs = exports.languageConstructs = ('[|]|alias|bg|bind|break|builtin|' +
  9. 'cd|command|compgen|complete|continue|' +
  10. 'dirs|disown|echo|enable|eval|exec|' +
  11. 'exit|fc|fg|getopts|hash|help|history|' +
  12. 'jobs|kill|let|logout|popd|printf|pushd|' +
  13. 'pwd|return|set|shift|shopt|source|' +
  14. 'suspend|test|times|trap|type|ulimit|' +
  15. 'umask|unalias|wait');
  16. var ShHighlightRules = function () {
  17. var keywordMapper = this.createKeywordMapper({
  18. "keyword": reservedKeywords,
  19. "support.function.builtin": languageConstructs,
  20. "invalid.deprecated": "debugger"
  21. }, "identifier");
  22. var integer = "(?:(?:[1-9]\\d*)|(?:0))";
  23. var fraction = "(?:\\.\\d+)";
  24. var intPart = "(?:\\d+)";
  25. var pointFloat = "(?:(?:" + intPart + "?" + fraction + ")|(?:" + intPart + "\\.))";
  26. var exponentFloat = "(?:(?:" + pointFloat + "|" + intPart + ")" + ")";
  27. var floatNumber = "(?:" + exponentFloat + "|" + pointFloat + ")";
  28. var fileDescriptor = "(?:&" + intPart + ")";
  29. var variableName = "[a-zA-Z_][a-zA-Z0-9_]*";
  30. var variable = "(?:" + variableName + "(?==))";
  31. var builtinVariable = "(?:\\$(?:SHLVL|\\$|\\!|\\?))";
  32. var func = "(?:" + variableName + "\\s*\\(\\))";
  33. this.$rules = {
  34. "start": [{
  35. token: "constant",
  36. regex: /\\./
  37. }, {
  38. token: ["text", "comment"],
  39. regex: /(^|\s)(#.*)$/
  40. }, {
  41. token: "string.start",
  42. regex: '"',
  43. push: [{
  44. token: "constant.language.escape",
  45. regex: /\\(?:[$`"\\]|$)/
  46. }, {
  47. include: "variables"
  48. }, {
  49. token: "keyword.operator",
  50. regex: /`/ // TODO highlight `
  51. }, {
  52. token: "string.end",
  53. regex: '"',
  54. next: "pop"
  55. }, {
  56. defaultToken: "string"
  57. }]
  58. }, {
  59. token: "string",
  60. regex: "\\$'",
  61. push: [{
  62. token: "constant.language.escape",
  63. regex: /\\(?:[abeEfnrtv\\'"]|x[a-fA-F\d]{1,2}|u[a-fA-F\d]{4}([a-fA-F\d]{4})?|c.|\d{1,3})/
  64. }, {
  65. token: "string",
  66. regex: "'",
  67. next: "pop"
  68. }, {
  69. defaultToken: "string"
  70. }]
  71. }, {
  72. regex: "<<<",
  73. token: "keyword.operator"
  74. }, {
  75. stateName: "heredoc",
  76. regex: "(<<-?)(\\s*)(['\"`]?)([\\w\\-]+)(['\"`]?)",
  77. onMatch: function (value, currentState, stack) {
  78. var next = value[2] == '-' ? "indentedHeredoc" : "heredoc";
  79. var tokens = value.split(this.splitRegex);
  80. stack.push(next, tokens[4]);
  81. return [
  82. { type: "constant", value: tokens[1] },
  83. { type: "text", value: tokens[2] },
  84. { type: "string", value: tokens[3] },
  85. { type: "support.class", value: tokens[4] },
  86. { type: "string", value: tokens[5] }
  87. ];
  88. },
  89. rules: {
  90. heredoc: [{
  91. onMatch: function (value, currentState, stack) {
  92. if (value === stack[1]) {
  93. stack.shift();
  94. stack.shift();
  95. this.next = stack[0] || "start";
  96. return "support.class";
  97. }
  98. this.next = "";
  99. return "string";
  100. },
  101. regex: ".*$",
  102. next: "start"
  103. }],
  104. indentedHeredoc: [{
  105. token: "string",
  106. regex: "^\t+"
  107. }, {
  108. onMatch: function (value, currentState, stack) {
  109. if (value === stack[1]) {
  110. stack.shift();
  111. stack.shift();
  112. this.next = stack[0] || "start";
  113. return "support.class";
  114. }
  115. this.next = "";
  116. return "string";
  117. },
  118. regex: ".*$",
  119. next: "start"
  120. }]
  121. }
  122. }, {
  123. regex: "$",
  124. token: "empty",
  125. next: function (currentState, stack) {
  126. if (stack[0] === "heredoc" || stack[0] === "indentedHeredoc")
  127. return stack[0];
  128. return currentState;
  129. }
  130. }, {
  131. token: ["keyword", "text", "text", "text", "variable"],
  132. regex: /(declare|local|readonly)(\s+)(?:(-[fixar]+)(\s+))?([a-zA-Z_][a-zA-Z0-9_]*\b)/
  133. }, {
  134. token: "variable.language",
  135. regex: builtinVariable
  136. }, {
  137. token: "variable",
  138. regex: variable
  139. }, {
  140. include: "variables"
  141. }, {
  142. token: "support.function",
  143. regex: func
  144. }, {
  145. token: "support.function",
  146. regex: fileDescriptor
  147. }, {
  148. token: "string",
  149. start: "'", end: "'"
  150. }, {
  151. token: "constant.numeric",
  152. regex: floatNumber
  153. }, {
  154. token: "constant.numeric",
  155. regex: integer + "\\b"
  156. }, {
  157. token: keywordMapper,
  158. regex: "[a-zA-Z_][a-zA-Z0-9_]*\\b"
  159. }, {
  160. token: "keyword.operator",
  161. regex: "\\+|\\-|\\*|\\*\\*|\\/|\\/\\/|~|<|>|<=|=>|=|!=|[%&|`]"
  162. }, {
  163. token: "punctuation.operator",
  164. regex: ";"
  165. }, {
  166. token: "paren.lparen",
  167. regex: "[\\[\\(\\{]"
  168. }, {
  169. token: "paren.rparen",
  170. regex: "[\\]]"
  171. }, {
  172. token: "paren.rparen",
  173. regex: "[\\)\\}]",
  174. next: "pop"
  175. }],
  176. variables: [{
  177. token: "variable",
  178. regex: /(\$)(\w+)/
  179. }, {
  180. token: ["variable", "paren.lparen"],
  181. regex: /(\$)(\()/,
  182. push: "start"
  183. }, {
  184. token: ["variable", "paren.lparen", "keyword.operator", "variable", "keyword.operator"],
  185. regex: /(\$)(\{)([#!]?)(\w+|[*@#?\-$!0_])(:[?+\-=]?|##?|%%?|,,?\/|\^\^?)?/,
  186. push: "start"
  187. }, {
  188. token: "variable",
  189. regex: /\$[*@#?\-$!0_]/
  190. }, {
  191. token: ["variable", "paren.lparen"],
  192. regex: /(\$)(\{)/,
  193. push: "start"
  194. }]
  195. };
  196. this.normalizeRules();
  197. };
  198. oop.inherits(ShHighlightRules, TextHighlightRules);
  199. exports.ShHighlightRules = ShHighlightRules;
  200. });
  201. 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";
  202. var oop = require("../../lib/oop");
  203. var Range = require("../../range").Range;
  204. var BaseFoldMode = require("./fold_mode").FoldMode;
  205. var FoldMode = exports.FoldMode = function (commentRegex) {
  206. if (commentRegex) {
  207. this.foldingStartMarker = new RegExp(this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start));
  208. this.foldingStopMarker = new RegExp(this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end));
  209. }
  210. };
  211. oop.inherits(FoldMode, BaseFoldMode);
  212. (function () {
  213. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  214. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  215. this.singleLineBlockCommentRe = /^\s*(\/\*).*\*\/\s*$/;
  216. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  217. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  218. this._getFoldWidgetBase = this.getFoldWidget;
  219. this.getFoldWidget = function (session, foldStyle, row) {
  220. var line = session.getLine(row);
  221. if (this.singleLineBlockCommentRe.test(line)) {
  222. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  223. return "";
  224. }
  225. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  226. if (!fw && this.startRegionRe.test(line))
  227. return "start"; // lineCommentRegionStart
  228. return fw;
  229. };
  230. this.getFoldWidgetRange = function (session, foldStyle, row, forceMultiline) {
  231. var line = session.getLine(row);
  232. if (this.startRegionRe.test(line))
  233. return this.getCommentRegionBlock(session, line, row);
  234. var match = line.match(this.foldingStartMarker);
  235. if (match) {
  236. var i = match.index;
  237. if (match[1])
  238. return this.openingBracketBlock(session, match[1], row, i);
  239. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  240. if (range && !range.isMultiLine()) {
  241. if (forceMultiline) {
  242. range = this.getSectionRange(session, row);
  243. }
  244. else if (foldStyle != "all")
  245. range = null;
  246. }
  247. return range;
  248. }
  249. if (foldStyle === "markbegin")
  250. return;
  251. var match = line.match(this.foldingStopMarker);
  252. if (match) {
  253. var i = match.index + match[0].length;
  254. if (match[1])
  255. return this.closingBracketBlock(session, match[1], row, i);
  256. return session.getCommentFoldRange(row, i, -1);
  257. }
  258. };
  259. this.getSectionRange = function (session, row) {
  260. var line = session.getLine(row);
  261. var startIndent = line.search(/\S/);
  262. var startRow = row;
  263. var startColumn = line.length;
  264. row = row + 1;
  265. var endRow = row;
  266. var maxRow = session.getLength();
  267. while (++row < maxRow) {
  268. line = session.getLine(row);
  269. var indent = line.search(/\S/);
  270. if (indent === -1)
  271. continue;
  272. if (startIndent > indent)
  273. break;
  274. var subRange = this.getFoldWidgetRange(session, "all", row);
  275. if (subRange) {
  276. if (subRange.start.row <= startRow) {
  277. break;
  278. }
  279. else if (subRange.isMultiLine()) {
  280. row = subRange.end.row;
  281. }
  282. else if (startIndent == indent) {
  283. break;
  284. }
  285. }
  286. endRow = row;
  287. }
  288. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  289. };
  290. this.getCommentRegionBlock = function (session, line, row) {
  291. var startColumn = line.search(/\s*$/);
  292. var maxRow = session.getLength();
  293. var startRow = row;
  294. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  295. var depth = 1;
  296. while (++row < maxRow) {
  297. line = session.getLine(row);
  298. var m = re.exec(line);
  299. if (!m)
  300. continue;
  301. if (m[1])
  302. depth--;
  303. else
  304. depth++;
  305. if (!depth)
  306. break;
  307. }
  308. var endRow = row;
  309. if (endRow > startRow) {
  310. return new Range(startRow, startColumn, endRow, line.length);
  311. }
  312. };
  313. }).call(FoldMode.prototype);
  314. });
  315. ace.define("ace/mode/sh",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/sh_highlight_rules","ace/range","ace/mode/folding/cstyle","ace/mode/behaviour/cstyle"], function(require, exports, module){"use strict";
  316. var oop = require("../lib/oop");
  317. var TextMode = require("./text").Mode;
  318. var ShHighlightRules = require("./sh_highlight_rules").ShHighlightRules;
  319. var Range = require("../range").Range;
  320. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  321. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  322. var Mode = function () {
  323. this.HighlightRules = ShHighlightRules;
  324. this.foldingRules = new CStyleFoldMode();
  325. this.$behaviour = new CstyleBehaviour();
  326. };
  327. oop.inherits(Mode, TextMode);
  328. (function () {
  329. this.lineCommentStart = "#";
  330. this.getNextLineIndent = function (state, line, tab) {
  331. var indent = this.$getIndent(line);
  332. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  333. var tokens = tokenizedLine.tokens;
  334. if (tokens.length && tokens[tokens.length - 1].type == "comment") {
  335. return indent;
  336. }
  337. if (state == "start") {
  338. var match = line.match(/^.*[\{\(\[:]\s*$/);
  339. if (match) {
  340. indent += tab;
  341. }
  342. }
  343. return indent;
  344. };
  345. var outdents = {
  346. "pass": 1,
  347. "return": 1,
  348. "raise": 1,
  349. "break": 1,
  350. "continue": 1
  351. };
  352. this.checkOutdent = function (state, line, input) {
  353. if (input !== "\r\n" && input !== "\r" && input !== "\n")
  354. return false;
  355. var tokens = this.getTokenizer().getLineTokens(line.trim(), state).tokens;
  356. if (!tokens)
  357. return false;
  358. do {
  359. var last = tokens.pop();
  360. } while (last && (last.type == "comment" || (last.type == "text" && last.value.match(/^\s+$/))));
  361. if (!last)
  362. return false;
  363. return (last.type == "keyword" && outdents[last.value]);
  364. };
  365. this.autoOutdent = function (state, doc, row) {
  366. row += 1;
  367. var indent = this.$getIndent(doc.getLine(row));
  368. var tab = doc.getTabString();
  369. if (indent.slice(-tab.length) == tab)
  370. doc.remove(new Range(row, indent.length - tab.length, row, indent.length));
  371. };
  372. this.$id = "ace/mode/sh";
  373. this.snippetFileId = "ace/snippets/sh";
  374. }).call(Mode.prototype);
  375. exports.Mode = Mode;
  376. });
  377. ace.define("ace/mode/dockerfile_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/sh_highlight_rules"], function(require, exports, module){"use strict";
  378. var oop = require("../lib/oop");
  379. var ShHighlightRules = require("./sh_highlight_rules").ShHighlightRules;
  380. var DockerfileHighlightRules = function () {
  381. ShHighlightRules.call(this);
  382. var startRules = this.$rules.start;
  383. for (var i = 0; i < startRules.length; i++) {
  384. if (startRules[i].token == "variable.language") {
  385. startRules.splice(i, 0, {
  386. token: "constant.language",
  387. regex: "(?:^(?:FROM|MAINTAINER|RUN|CMD|EXPOSE|ENV|ADD|ENTRYPOINT|VOLUME|USER|WORKDIR|ONBUILD|COPY|LABEL)\\b)",
  388. caseInsensitive: true
  389. });
  390. break;
  391. }
  392. }
  393. };
  394. oop.inherits(DockerfileHighlightRules, ShHighlightRules);
  395. exports.DockerfileHighlightRules = DockerfileHighlightRules;
  396. });
  397. ace.define("ace/mode/dockerfile",["require","exports","module","ace/lib/oop","ace/mode/sh","ace/mode/dockerfile_highlight_rules","ace/mode/folding/cstyle"], function(require, exports, module){"use strict";
  398. var oop = require("../lib/oop");
  399. var ShMode = require("./sh").Mode;
  400. var DockerfileHighlightRules = require("./dockerfile_highlight_rules").DockerfileHighlightRules;
  401. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  402. var Mode = function () {
  403. ShMode.call(this);
  404. this.HighlightRules = DockerfileHighlightRules;
  405. this.foldingRules = new CStyleFoldMode();
  406. };
  407. oop.inherits(Mode, ShMode);
  408. (function () {
  409. this.$id = "ace/mode/dockerfile";
  410. }).call(Mode.prototype);
  411. exports.Mode = Mode;
  412. }); (function() {
  413. ace.require(["ace/mode/dockerfile"], function(m) {
  414. if (typeof module == "object" && typeof exports == "object" && module) {
  415. module.exports = m;
  416. }
  417. });
  418. })();