mode-batchfile.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. define("ace/mode/batchfile_highlight_rules",["ace_require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(ace_require, exports, module) {
  2. "use strict";
  3. var oop = ace_require("../lib/oop");
  4. var TextHighlightRules = ace_require("./text_highlight_rules").TextHighlightRules;
  5. var BatchFileHighlightRules = function() {
  6. this.$rules = { start:
  7. [ { token: 'keyword.command.dosbatch',
  8. regex: '\\b(?:append|assoc|at|attrib|break|cacls|cd|chcp|chdir|chkdsk|chkntfs|cls|cmd|color|comp|compact|convert|copy|date|del|dir|diskcomp|diskcopy|doskey|echo|endlocal|erase|fc|find|findstr|format|ftype|graftabl|help|keyb|label|md|mkdir|mode|more|move|path|pause|popd|print|prompt|pushd|rd|recover|ren|rename|replace|restore|rmdir|set|setlocal|shift|sort|start|subst|time|title|tree|type|ver|verify|vol|xcopy)\\b',
  9. caseInsensitive: true },
  10. { token: 'keyword.control.statement.dosbatch',
  11. regex: '\\b(?:goto|call|exit)\\b',
  12. caseInsensitive: true },
  13. { token: 'keyword.control.conditional.if.dosbatch',
  14. regex: '\\bif\\s+not\\s+(?:exist|defined|errorlevel|cmdextversion)\\b',
  15. caseInsensitive: true },
  16. { token: 'keyword.control.conditional.dosbatch',
  17. regex: '\\b(?:if|else)\\b',
  18. caseInsensitive: true },
  19. { token: 'keyword.control.repeat.dosbatch',
  20. regex: '\\bfor\\b',
  21. caseInsensitive: true },
  22. { token: 'keyword.operator.dosbatch',
  23. regex: '\\b(?:EQU|NEQ|LSS|LEQ|GTR|GEQ)\\b' },
  24. { token: ['doc.comment', 'comment'],
  25. regex: '(?:^|\\b)(rem)($|\\s.*$)',
  26. caseInsensitive: true },
  27. { token: 'comment.line.colons.dosbatch',
  28. regex: '::.*$' },
  29. { include: 'variable' },
  30. { token: 'punctuation.definition.string.begin.shell',
  31. regex: '"',
  32. push: [
  33. { token: 'punctuation.definition.string.end.shell', regex: '"', next: 'pop' },
  34. { include: 'variable' },
  35. { defaultToken: 'string.quoted.double.dosbatch' } ] },
  36. { token: 'keyword.operator.pipe.dosbatch', regex: '[|]' },
  37. { token: 'keyword.operator.redirect.shell',
  38. regex: '&>|\\d*>&\\d*|\\d*(?:>>|>|<)|\\d*<&|\\d*<>' } ],
  39. variable: [
  40. { token: 'constant.numeric', regex: '%%\\w+|%[*\\d]|%\\w+%'},
  41. { token: 'constant.numeric', regex: '%~\\d+'},
  42. { token: ['markup.list', 'constant.other', 'markup.list'],
  43. regex: '(%)(\\w+)(%?)' }]};
  44. this.normalizeRules();
  45. };
  46. BatchFileHighlightRules.metaData = { name: 'Batch File',
  47. scopeName: 'source.dosbatch',
  48. fileTypes: [ 'bat' ] };
  49. oop.inherits(BatchFileHighlightRules, TextHighlightRules);
  50. exports.BatchFileHighlightRules = BatchFileHighlightRules;
  51. });
  52. define("ace/mode/folding/cstyle",["ace_require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(ace_require, exports, module) {
  53. "use strict";
  54. var oop = ace_require("../../lib/oop");
  55. var Range = ace_require("../../range").Range;
  56. var BaseFoldMode = ace_require("./fold_mode").FoldMode;
  57. var FoldMode = exports.FoldMode = function(commentRegex) {
  58. if (commentRegex) {
  59. this.foldingStartMarker = new RegExp(
  60. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  61. );
  62. this.foldingStopMarker = new RegExp(
  63. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  64. );
  65. }
  66. };
  67. oop.inherits(FoldMode, BaseFoldMode);
  68. (function() {
  69. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  70. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  71. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  72. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  73. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  74. this._getFoldWidgetBase = this.getFoldWidget;
  75. this.getFoldWidget = function(session, foldStyle, row) {
  76. var line = session.getLine(row);
  77. if (this.singleLineBlockCommentRe.test(line)) {
  78. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  79. return "";
  80. }
  81. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  82. if (!fw && this.startRegionRe.test(line))
  83. return "start"; // lineCommentRegionStart
  84. return fw;
  85. };
  86. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  87. var line = session.getLine(row);
  88. if (this.startRegionRe.test(line))
  89. return this.getCommentRegionBlock(session, line, row);
  90. var match = line.match(this.foldingStartMarker);
  91. if (match) {
  92. var i = match.index;
  93. if (match[1])
  94. return this.openingBracketBlock(session, match[1], row, i);
  95. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  96. if (range && !range.isMultiLine()) {
  97. if (forceMultiline) {
  98. range = this.getSectionRange(session, row);
  99. } else if (foldStyle != "all")
  100. range = null;
  101. }
  102. return range;
  103. }
  104. if (foldStyle === "markbegin")
  105. return;
  106. var match = line.match(this.foldingStopMarker);
  107. if (match) {
  108. var i = match.index + match[0].length;
  109. if (match[1])
  110. return this.closingBracketBlock(session, match[1], row, i);
  111. return session.getCommentFoldRange(row, i, -1);
  112. }
  113. };
  114. this.getSectionRange = function(session, row) {
  115. var line = session.getLine(row);
  116. var startIndent = line.search(/\S/);
  117. var startRow = row;
  118. var startColumn = line.length;
  119. row = row + 1;
  120. var endRow = row;
  121. var maxRow = session.getLength();
  122. while (++row < maxRow) {
  123. line = session.getLine(row);
  124. var indent = line.search(/\S/);
  125. if (indent === -1)
  126. continue;
  127. if (startIndent > indent)
  128. break;
  129. var subRange = this.getFoldWidgetRange(session, "all", row);
  130. if (subRange) {
  131. if (subRange.start.row <= startRow) {
  132. break;
  133. } else if (subRange.isMultiLine()) {
  134. row = subRange.end.row;
  135. } else if (startIndent == indent) {
  136. break;
  137. }
  138. }
  139. endRow = row;
  140. }
  141. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  142. };
  143. this.getCommentRegionBlock = function(session, line, row) {
  144. var startColumn = line.search(/\s*$/);
  145. var maxRow = session.getLength();
  146. var startRow = row;
  147. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  148. var depth = 1;
  149. while (++row < maxRow) {
  150. line = session.getLine(row);
  151. var m = re.exec(line);
  152. if (!m) continue;
  153. if (m[1]) depth--;
  154. else depth++;
  155. if (!depth) break;
  156. }
  157. var endRow = row;
  158. if (endRow > startRow) {
  159. return new Range(startRow, startColumn, endRow, line.length);
  160. }
  161. };
  162. }).call(FoldMode.prototype);
  163. });
  164. define("ace/mode/batchfile",["ace_require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/batchfile_highlight_rules","ace/mode/folding/cstyle"], function(ace_require, exports, module) {
  165. "use strict";
  166. var oop = ace_require("../lib/oop");
  167. var TextMode = ace_require("./text").Mode;
  168. var BatchFileHighlightRules = ace_require("./batchfile_highlight_rules").BatchFileHighlightRules;
  169. var FoldMode = ace_require("./folding/cstyle").FoldMode;
  170. var Mode = function() {
  171. this.HighlightRules = BatchFileHighlightRules;
  172. this.foldingRules = new FoldMode();
  173. this.$behaviour = this.$defaultBehaviour;
  174. };
  175. oop.inherits(Mode, TextMode);
  176. (function() {
  177. this.lineCommentStart = "::";
  178. this.blockComment = "";
  179. this.$id = "ace/mode/batchfile";
  180. }).call(Mode.prototype);
  181. exports.Mode = Mode;
  182. }); (function() {
  183. window.ace_require(["ace/mode/batchfile"], function(m) {
  184. if (typeof module == "object" && typeof exports == "object" && module) {
  185. module.exports = m;
  186. }
  187. });
  188. })();