Nav apraksta
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

mode-dockerfile.js 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  1. ace.define("ace/mode/sh_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 reservedKeywords = exports.reservedKeywords = (
  6. '!|{|}|case|do|done|elif|else|'+
  7. 'esac|fi|for|if|in|then|until|while|'+
  8. '&|;|export|local|read|typeset|unset|'+
  9. 'elif|select|set'
  10. );
  11. var languageConstructs = exports.languageConstructs = (
  12. '[|]|alias|bg|bind|break|builtin|'+
  13. 'cd|command|compgen|complete|continue|'+
  14. 'dirs|disown|echo|enable|eval|exec|'+
  15. 'exit|fc|fg|getopts|hash|help|history|'+
  16. 'jobs|kill|let|logout|popd|printf|pushd|'+
  17. 'pwd|return|set|shift|shopt|source|'+
  18. 'suspend|test|times|trap|type|ulimit|'+
  19. 'umask|unalias|wait'
  20. );
  21. var ShHighlightRules = function() {
  22. var keywordMapper = this.createKeywordMapper({
  23. "keyword": reservedKeywords,
  24. "support.function.builtin": languageConstructs,
  25. "invalid.deprecated": "debugger"
  26. }, "identifier");
  27. var integer = "(?:(?:[1-9]\\d*)|(?:0))";
  28. var fraction = "(?:\\.\\d+)";
  29. var intPart = "(?:\\d+)";
  30. var pointFloat = "(?:(?:" + intPart + "?" + fraction + ")|(?:" + intPart + "\\.))";
  31. var exponentFloat = "(?:(?:" + pointFloat + "|" + intPart + ")" + ")";
  32. var floatNumber = "(?:" + exponentFloat + "|" + pointFloat + ")";
  33. var fileDescriptor = "(?:&" + intPart + ")";
  34. var variableName = "[a-zA-Z_][a-zA-Z0-9_]*";
  35. var variable = "(?:(?:\\$" + variableName + ")|(?:" + variableName + "=))";
  36. var builtinVariable = "(?:\\$(?:SHLVL|\\$|\\!|\\?))";
  37. var func = "(?:" + variableName + "\\s*\\(\\))";
  38. this.$rules = {
  39. "start" : [{
  40. token : "constant",
  41. regex : /\\./
  42. }, {
  43. token : ["text", "comment"],
  44. regex : /(^|\s)(#.*)$/
  45. }, {
  46. token : "string",
  47. regex : '"',
  48. push : [{
  49. token : "constant.language.escape",
  50. regex : /\\(?:[$abeEfnrtv\\'"]|x[a-fA-F\d]{1,2}|u[a-fA-F\d]{4}([a-fA-F\d]{4})?|c.|\d{1,3})/
  51. }, {
  52. token : "constant",
  53. regex : /\$\w+/
  54. }, {
  55. token : "string",
  56. regex : '"',
  57. next: "pop"
  58. }, {
  59. defaultToken: "string"
  60. }]
  61. }, {
  62. regex : "<<<",
  63. token : "keyword.operator"
  64. }, {
  65. stateName: "heredoc",
  66. regex : "(<<)(\\s*)(['\"`]?)([\\w\\-]+)(['\"`]?)",
  67. onMatch : function(value, currentState, stack) {
  68. var next = value[2] == '-' ? "indentedHeredoc" : "heredoc";
  69. var tokens = value.split(this.splitRegex);
  70. stack.push(next, tokens[4]);
  71. return [
  72. {type:"constant", value: tokens[1]},
  73. {type:"text", value: tokens[2]},
  74. {type:"string", value: tokens[3]},
  75. {type:"support.class", value: tokens[4]},
  76. {type:"string", value: tokens[5]}
  77. ];
  78. },
  79. rules: {
  80. heredoc: [{
  81. onMatch: function(value, currentState, stack) {
  82. if (value === stack[1]) {
  83. stack.shift();
  84. stack.shift();
  85. this.next = stack[0] || "start";
  86. return "support.class";
  87. }
  88. this.next = "";
  89. return "string";
  90. },
  91. regex: ".*$",
  92. next: "start"
  93. }],
  94. indentedHeredoc: [{
  95. token: "string",
  96. regex: "^\t+"
  97. }, {
  98. onMatch: function(value, currentState, stack) {
  99. if (value === stack[1]) {
  100. stack.shift();
  101. stack.shift();
  102. this.next = stack[0] || "start";
  103. return "support.class";
  104. }
  105. this.next = "";
  106. return "string";
  107. },
  108. regex: ".*$",
  109. next: "start"
  110. }]
  111. }
  112. }, {
  113. regex : "$",
  114. token : "empty",
  115. next : function(currentState, stack) {
  116. if (stack[0] === "heredoc" || stack[0] === "indentedHeredoc")
  117. return stack[0];
  118. return currentState;
  119. }
  120. }, {
  121. token : "variable.language",
  122. regex : builtinVariable
  123. }, {
  124. token : "variable",
  125. regex : variable
  126. }, {
  127. token : "support.function",
  128. regex : func
  129. }, {
  130. token : "support.function",
  131. regex : fileDescriptor
  132. }, {
  133. token : "string", // ' string
  134. start : "'", end : "'"
  135. }, {
  136. token : "constant.numeric", // float
  137. regex : floatNumber
  138. }, {
  139. token : "constant.numeric", // integer
  140. regex : integer + "\\b"
  141. }, {
  142. token : keywordMapper,
  143. regex : "[a-zA-Z_][a-zA-Z0-9_]*\\b"
  144. }, {
  145. token : "keyword.operator",
  146. regex : "\\+|\\-|\\*|\\*\\*|\\/|\\/\\/|~|<|>|<=|=>|=|!="
  147. }, {
  148. token : "paren.lparen",
  149. regex : "[\\[\\(\\{]"
  150. }, {
  151. token : "paren.rparen",
  152. regex : "[\\]\\)\\}]"
  153. } ]
  154. };
  155. this.normalizeRules();
  156. };
  157. oop.inherits(ShHighlightRules, TextHighlightRules);
  158. exports.ShHighlightRules = ShHighlightRules;
  159. });
  160. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  161. "use strict";
  162. var oop = require("../../lib/oop");
  163. var Range = require("../../range").Range;
  164. var BaseFoldMode = require("./fold_mode").FoldMode;
  165. var FoldMode = exports.FoldMode = function(commentRegex) {
  166. if (commentRegex) {
  167. this.foldingStartMarker = new RegExp(
  168. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  169. );
  170. this.foldingStopMarker = new RegExp(
  171. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  172. );
  173. }
  174. };
  175. oop.inherits(FoldMode, BaseFoldMode);
  176. (function() {
  177. this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
  178. this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
  179. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  180. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  181. this.startRegionRe = /^\s*(\/\*|\/\/)#region\b/;
  182. this._getFoldWidgetBase = this.getFoldWidget;
  183. this.getFoldWidget = function(session, foldStyle, row) {
  184. var line = session.getLine(row);
  185. if (this.singleLineBlockCommentRe.test(line)) {
  186. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  187. return "";
  188. }
  189. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  190. if (!fw && this.startRegionRe.test(line))
  191. return "start"; // lineCommentRegionStart
  192. return fw;
  193. };
  194. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  195. var line = session.getLine(row);
  196. if (this.startRegionRe.test(line))
  197. return this.getCommentRegionBlock(session, line, row);
  198. var match = line.match(this.foldingStartMarker);
  199. if (match) {
  200. var i = match.index;
  201. if (match[1])
  202. return this.openingBracketBlock(session, match[1], row, i);
  203. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  204. if (range && !range.isMultiLine()) {
  205. if (forceMultiline) {
  206. range = this.getSectionRange(session, row);
  207. } else if (foldStyle != "all")
  208. range = null;
  209. }
  210. return range;
  211. }
  212. if (foldStyle === "markbegin")
  213. return;
  214. var match = line.match(this.foldingStopMarker);
  215. if (match) {
  216. var i = match.index + match[0].length;
  217. if (match[1])
  218. return this.closingBracketBlock(session, match[1], row, i);
  219. return session.getCommentFoldRange(row, i, -1);
  220. }
  221. };
  222. this.getSectionRange = function(session, row) {
  223. var line = session.getLine(row);
  224. var startIndent = line.search(/\S/);
  225. var startRow = row;
  226. var startColumn = line.length;
  227. row = row + 1;
  228. var endRow = row;
  229. var maxRow = session.getLength();
  230. while (++row < maxRow) {
  231. line = session.getLine(row);
  232. var indent = line.search(/\S/);
  233. if (indent === -1)
  234. continue;
  235. if (startIndent > indent)
  236. break;
  237. var subRange = this.getFoldWidgetRange(session, "all", row);
  238. if (subRange) {
  239. if (subRange.start.row <= startRow) {
  240. break;
  241. } else if (subRange.isMultiLine()) {
  242. row = subRange.end.row;
  243. } else if (startIndent == indent) {
  244. break;
  245. }
  246. }
  247. endRow = row;
  248. }
  249. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  250. };
  251. this.getCommentRegionBlock = function(session, line, row) {
  252. var startColumn = line.search(/\s*$/);
  253. var maxRow = session.getLength();
  254. var startRow = row;
  255. var re = /^\s*(?:\/\*|\/\/)#(end)?region\b/;
  256. var depth = 1;
  257. while (++row < maxRow) {
  258. line = session.getLine(row);
  259. var m = re.exec(line);
  260. if (!m) continue;
  261. if (m[1]) depth--;
  262. else depth++;
  263. if (!depth) break;
  264. }
  265. var endRow = row;
  266. if (endRow > startRow) {
  267. return new Range(startRow, startColumn, endRow, line.length);
  268. }
  269. };
  270. }).call(FoldMode.prototype);
  271. });
  272. ace.define("ace/mode/behaviour/cstyle",["require","exports","module","ace/lib/oop","ace/mode/behaviour","ace/token_iterator","ace/lib/lang"], function(require, exports, module) {
  273. "use strict";
  274. var oop = require("../../lib/oop");
  275. var Behaviour = require("../behaviour").Behaviour;
  276. var TokenIterator = require("../../token_iterator").TokenIterator;
  277. var lang = require("../../lib/lang");
  278. var SAFE_INSERT_IN_TOKENS =
  279. ["text", "paren.rparen", "punctuation.operator"];
  280. var SAFE_INSERT_BEFORE_TOKENS =
  281. ["text", "paren.rparen", "punctuation.operator", "comment"];
  282. var context;
  283. var contextCache = {};
  284. var initContext = function(editor) {
  285. var id = -1;
  286. if (editor.multiSelect) {
  287. id = editor.selection.index;
  288. if (contextCache.rangeCount != editor.multiSelect.rangeCount)
  289. contextCache = {rangeCount: editor.multiSelect.rangeCount};
  290. }
  291. if (contextCache[id])
  292. return context = contextCache[id];
  293. context = contextCache[id] = {
  294. autoInsertedBrackets: 0,
  295. autoInsertedRow: -1,
  296. autoInsertedLineEnd: "",
  297. maybeInsertedBrackets: 0,
  298. maybeInsertedRow: -1,
  299. maybeInsertedLineStart: "",
  300. maybeInsertedLineEnd: ""
  301. };
  302. };
  303. var CstyleBehaviour = function() {
  304. this.add("braces", "insertion", function(state, action, editor, session, text) {
  305. var cursor = editor.getCursorPosition();
  306. var line = session.doc.getLine(cursor.row);
  307. if (text == '{') {
  308. initContext(editor);
  309. var selection = editor.getSelectionRange();
  310. var selected = session.doc.getTextRange(selection);
  311. if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
  312. return {
  313. text: '{' + selected + '}',
  314. selection: false
  315. };
  316. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  317. if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode) {
  318. CstyleBehaviour.recordAutoInsert(editor, session, "}");
  319. return {
  320. text: '{}',
  321. selection: [1, 1]
  322. };
  323. } else {
  324. CstyleBehaviour.recordMaybeInsert(editor, session, "{");
  325. return {
  326. text: '{',
  327. selection: [1, 1]
  328. };
  329. }
  330. }
  331. } else if (text == '}') {
  332. initContext(editor);
  333. var rightChar = line.substring(cursor.column, cursor.column + 1);
  334. if (rightChar == '}') {
  335. var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
  336. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  337. CstyleBehaviour.popAutoInsertedClosing();
  338. return {
  339. text: '',
  340. selection: [1, 1]
  341. };
  342. }
  343. }
  344. } else if (text == "\n" || text == "\r\n") {
  345. initContext(editor);
  346. var closing = "";
  347. if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
  348. closing = lang.stringRepeat("}", context.maybeInsertedBrackets);
  349. CstyleBehaviour.clearMaybeInsertedClosing();
  350. }
  351. var rightChar = line.substring(cursor.column, cursor.column + 1);
  352. if (rightChar === '}') {
  353. var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column+1}, '}');
  354. if (!openBracePos)
  355. return null;
  356. var next_indent = this.$getIndent(session.getLine(openBracePos.row));
  357. } else if (closing) {
  358. var next_indent = this.$getIndent(line);
  359. } else {
  360. CstyleBehaviour.clearMaybeInsertedClosing();
  361. return;
  362. }
  363. var indent = next_indent + session.getTabString();
  364. return {
  365. text: '\n' + indent + '\n' + next_indent + closing,
  366. selection: [1, indent.length, 1, indent.length]
  367. };
  368. } else {
  369. CstyleBehaviour.clearMaybeInsertedClosing();
  370. }
  371. });
  372. this.add("braces", "deletion", function(state, action, editor, session, range) {
  373. var selected = session.doc.getTextRange(range);
  374. if (!range.isMultiLine() && selected == '{') {
  375. initContext(editor);
  376. var line = session.doc.getLine(range.start.row);
  377. var rightChar = line.substring(range.end.column, range.end.column + 1);
  378. if (rightChar == '}') {
  379. range.end.column++;
  380. return range;
  381. } else {
  382. context.maybeInsertedBrackets--;
  383. }
  384. }
  385. });
  386. this.add("parens", "insertion", function(state, action, editor, session, text) {
  387. if (text == '(') {
  388. initContext(editor);
  389. var selection = editor.getSelectionRange();
  390. var selected = session.doc.getTextRange(selection);
  391. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  392. return {
  393. text: '(' + selected + ')',
  394. selection: false
  395. };
  396. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  397. CstyleBehaviour.recordAutoInsert(editor, session, ")");
  398. return {
  399. text: '()',
  400. selection: [1, 1]
  401. };
  402. }
  403. } else if (text == ')') {
  404. initContext(editor);
  405. var cursor = editor.getCursorPosition();
  406. var line = session.doc.getLine(cursor.row);
  407. var rightChar = line.substring(cursor.column, cursor.column + 1);
  408. if (rightChar == ')') {
  409. var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
  410. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  411. CstyleBehaviour.popAutoInsertedClosing();
  412. return {
  413. text: '',
  414. selection: [1, 1]
  415. };
  416. }
  417. }
  418. }
  419. });
  420. this.add("parens", "deletion", function(state, action, editor, session, range) {
  421. var selected = session.doc.getTextRange(range);
  422. if (!range.isMultiLine() && selected == '(') {
  423. initContext(editor);
  424. var line = session.doc.getLine(range.start.row);
  425. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  426. if (rightChar == ')') {
  427. range.end.column++;
  428. return range;
  429. }
  430. }
  431. });
  432. this.add("brackets", "insertion", function(state, action, editor, session, text) {
  433. if (text == '[') {
  434. initContext(editor);
  435. var selection = editor.getSelectionRange();
  436. var selected = session.doc.getTextRange(selection);
  437. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  438. return {
  439. text: '[' + selected + ']',
  440. selection: false
  441. };
  442. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  443. CstyleBehaviour.recordAutoInsert(editor, session, "]");
  444. return {
  445. text: '[]',
  446. selection: [1, 1]
  447. };
  448. }
  449. } else if (text == ']') {
  450. initContext(editor);
  451. var cursor = editor.getCursorPosition();
  452. var line = session.doc.getLine(cursor.row);
  453. var rightChar = line.substring(cursor.column, cursor.column + 1);
  454. if (rightChar == ']') {
  455. var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
  456. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  457. CstyleBehaviour.popAutoInsertedClosing();
  458. return {
  459. text: '',
  460. selection: [1, 1]
  461. };
  462. }
  463. }
  464. }
  465. });
  466. this.add("brackets", "deletion", function(state, action, editor, session, range) {
  467. var selected = session.doc.getTextRange(range);
  468. if (!range.isMultiLine() && selected == '[') {
  469. initContext(editor);
  470. var line = session.doc.getLine(range.start.row);
  471. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  472. if (rightChar == ']') {
  473. range.end.column++;
  474. return range;
  475. }
  476. }
  477. });
  478. this.add("string_dquotes", "insertion", function(state, action, editor, session, text) {
  479. if (text == '"' || text == "'") {
  480. initContext(editor);
  481. var quote = text;
  482. var selection = editor.getSelectionRange();
  483. var selected = session.doc.getTextRange(selection);
  484. if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
  485. return {
  486. text: quote + selected + quote,
  487. selection: false
  488. };
  489. } else {
  490. var cursor = editor.getCursorPosition();
  491. var line = session.doc.getLine(cursor.row);
  492. var leftChar = line.substring(cursor.column-1, cursor.column);
  493. var rightChar = line.substring(cursor.column, cursor.column + 1);
  494. var token = session.getTokenAt(cursor.row, cursor.column);
  495. var rightToken = session.getTokenAt(cursor.row, cursor.column + 1);
  496. if (leftChar == "\\" && token && /escape/.test(token.type))
  497. return null;
  498. var stringBefore = token && /string/.test(token.type);
  499. var stringAfter = !rightToken || /string/.test(rightToken.type);
  500. var pair;
  501. if (rightChar == quote) {
  502. pair = stringBefore !== stringAfter;
  503. } else {
  504. if (stringBefore && !stringAfter)
  505. return null; // wrap string with different quote
  506. if (stringBefore && stringAfter)
  507. return null; // do not pair quotes inside strings
  508. var wordRe = session.$mode.tokenRe;
  509. wordRe.lastIndex = 0;
  510. var isWordBefore = wordRe.test(leftChar);
  511. wordRe.lastIndex = 0;
  512. var isWordAfter = wordRe.test(leftChar);
  513. if (isWordBefore || isWordAfter)
  514. return null; // before or after alphanumeric
  515. if (rightChar && !/[\s;,.})\]\\]/.test(rightChar))
  516. return null; // there is rightChar and it isn't closing
  517. pair = true;
  518. }
  519. return {
  520. text: pair ? quote + quote : "",
  521. selection: [1,1]
  522. };
  523. }
  524. }
  525. });
  526. this.add("string_dquotes", "deletion", function(state, action, editor, session, range) {
  527. var selected = session.doc.getTextRange(range);
  528. if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
  529. initContext(editor);
  530. var line = session.doc.getLine(range.start.row);
  531. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  532. if (rightChar == selected) {
  533. range.end.column++;
  534. return range;
  535. }
  536. }
  537. });
  538. };
  539. CstyleBehaviour.isSaneInsertion = function(editor, session) {
  540. var cursor = editor.getCursorPosition();
  541. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  542. if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
  543. var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
  544. if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
  545. return false;
  546. }
  547. iterator.stepForward();
  548. return iterator.getCurrentTokenRow() !== cursor.row ||
  549. this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
  550. };
  551. CstyleBehaviour.$matchTokenType = function(token, types) {
  552. return types.indexOf(token.type || token) > -1;
  553. };
  554. CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
  555. var cursor = editor.getCursorPosition();
  556. var line = session.doc.getLine(cursor.row);
  557. if (!this.isAutoInsertedClosing(cursor, line, context.autoInsertedLineEnd[0]))
  558. context.autoInsertedBrackets = 0;
  559. context.autoInsertedRow = cursor.row;
  560. context.autoInsertedLineEnd = bracket + line.substr(cursor.column);
  561. context.autoInsertedBrackets++;
  562. };
  563. CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
  564. var cursor = editor.getCursorPosition();
  565. var line = session.doc.getLine(cursor.row);
  566. if (!this.isMaybeInsertedClosing(cursor, line))
  567. context.maybeInsertedBrackets = 0;
  568. context.maybeInsertedRow = cursor.row;
  569. context.maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
  570. context.maybeInsertedLineEnd = line.substr(cursor.column);
  571. context.maybeInsertedBrackets++;
  572. };
  573. CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
  574. return context.autoInsertedBrackets > 0 &&
  575. cursor.row === context.autoInsertedRow &&
  576. bracket === context.autoInsertedLineEnd[0] &&
  577. line.substr(cursor.column) === context.autoInsertedLineEnd;
  578. };
  579. CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
  580. return context.maybeInsertedBrackets > 0 &&
  581. cursor.row === context.maybeInsertedRow &&
  582. line.substr(cursor.column) === context.maybeInsertedLineEnd &&
  583. line.substr(0, cursor.column) == context.maybeInsertedLineStart;
  584. };
  585. CstyleBehaviour.popAutoInsertedClosing = function() {
  586. context.autoInsertedLineEnd = context.autoInsertedLineEnd.substr(1);
  587. context.autoInsertedBrackets--;
  588. };
  589. CstyleBehaviour.clearMaybeInsertedClosing = function() {
  590. if (context) {
  591. context.maybeInsertedBrackets = 0;
  592. context.maybeInsertedRow = -1;
  593. }
  594. };
  595. oop.inherits(CstyleBehaviour, Behaviour);
  596. exports.CstyleBehaviour = CstyleBehaviour;
  597. });
  598. 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) {
  599. "use strict";
  600. var oop = require("../lib/oop");
  601. var TextMode = require("./text").Mode;
  602. var ShHighlightRules = require("./sh_highlight_rules").ShHighlightRules;
  603. var Range = require("../range").Range;
  604. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  605. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  606. var Mode = function() {
  607. this.HighlightRules = ShHighlightRules;
  608. this.foldingRules = new CStyleFoldMode();
  609. this.$behaviour = new CstyleBehaviour();
  610. };
  611. oop.inherits(Mode, TextMode);
  612. (function() {
  613. this.lineCommentStart = "#";
  614. this.getNextLineIndent = function(state, line, tab) {
  615. var indent = this.$getIndent(line);
  616. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  617. var tokens = tokenizedLine.tokens;
  618. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  619. return indent;
  620. }
  621. if (state == "start") {
  622. var match = line.match(/^.*[\{\(\[\:]\s*$/);
  623. if (match) {
  624. indent += tab;
  625. }
  626. }
  627. return indent;
  628. };
  629. var outdents = {
  630. "pass": 1,
  631. "return": 1,
  632. "raise": 1,
  633. "break": 1,
  634. "continue": 1
  635. };
  636. this.checkOutdent = function(state, line, input) {
  637. if (input !== "\r\n" && input !== "\r" && input !== "\n")
  638. return false;
  639. var tokens = this.getTokenizer().getLineTokens(line.trim(), state).tokens;
  640. if (!tokens)
  641. return false;
  642. do {
  643. var last = tokens.pop();
  644. } while (last && (last.type == "comment" || (last.type == "text" && last.value.match(/^\s+$/))));
  645. if (!last)
  646. return false;
  647. return (last.type == "keyword" && outdents[last.value]);
  648. };
  649. this.autoOutdent = function(state, doc, row) {
  650. row += 1;
  651. var indent = this.$getIndent(doc.getLine(row));
  652. var tab = doc.getTabString();
  653. if (indent.slice(-tab.length) == tab)
  654. doc.remove(new Range(row, indent.length-tab.length, row, indent.length));
  655. };
  656. this.$id = "ace/mode/sh";
  657. }).call(Mode.prototype);
  658. exports.Mode = Mode;
  659. });
  660. ace.define("ace/mode/dockerfile_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/sh_highlight_rules"], function(require, exports, module) {
  661. "use strict";
  662. var oop = require("../lib/oop");
  663. var ShHighlightRules = require("./sh_highlight_rules").ShHighlightRules;
  664. var DockerfileHighlightRules = function() {
  665. ShHighlightRules.call(this);
  666. var startRules = this.$rules.start;
  667. for (var i = 0; i < startRules.length; i++) {
  668. if (startRules[i].token == "variable.language") {
  669. startRules.splice(i, 0, {
  670. token: "constant.language",
  671. regex: "(?:^(?:FROM|MAINTAINER|RUN|CMD|EXPOSE|ENV|ADD|ENTRYPOINT|VOLUME|USER|WORKDIR|ONBUILD|COPY)\\b)",
  672. caseInsensitive: true
  673. });
  674. break;
  675. }
  676. }
  677. };
  678. oop.inherits(DockerfileHighlightRules, ShHighlightRules);
  679. exports.DockerfileHighlightRules = DockerfileHighlightRules;
  680. });
  681. 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) {
  682. "use strict";
  683. var oop = require("../lib/oop");
  684. var ShMode = require("./sh").Mode;
  685. var DockerfileHighlightRules = require("./dockerfile_highlight_rules").DockerfileHighlightRules;
  686. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  687. var Mode = function() {
  688. ShMode.call(this);
  689. this.HighlightRules = DockerfileHighlightRules;
  690. this.foldingRules = new CStyleFoldMode();
  691. };
  692. oop.inherits(Mode, ShMode);
  693. (function() {
  694. this.$id = "ace/mode/dockerfile";
  695. }).call(Mode.prototype);
  696. exports.Mode = Mode;
  697. });