Nessuna descrizione
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mode-makefile.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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/makefile_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules","ace/mode/sh_highlight_rules"], function(require, exports, module) {
  161. "use strict";
  162. var oop = require("../lib/oop");
  163. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  164. var ShHighlightFile = require("./sh_highlight_rules");
  165. var MakefileHighlightRules = function() {
  166. var keywordMapper = this.createKeywordMapper({
  167. "keyword": ShHighlightFile.reservedKeywords,
  168. "support.function.builtin": ShHighlightFile.languageConstructs,
  169. "invalid.deprecated": "debugger"
  170. }, "string");
  171. this.$rules =
  172. {
  173. "start": [
  174. {
  175. token: "string.interpolated.backtick.makefile",
  176. regex: "`",
  177. next: "shell-start"
  178. },
  179. {
  180. token: "punctuation.definition.comment.makefile",
  181. regex: /#(?=.)/,
  182. next: "comment"
  183. },
  184. {
  185. token: [ "keyword.control.makefile"],
  186. regex: "^(?:\\s*\\b)(\\-??include|ifeq|ifneq|ifdef|ifndef|else|endif|vpath|export|unexport|define|endef|override)(?:\\b)"
  187. },
  188. {// ^([^\t ]+(\s[^\t ]+)*:(?!\=))\s*.*
  189. token: ["entity.name.function.makefile", "text"],
  190. regex: "^([^\\t ]+(?:\\s[^\\t ]+)*:)(\\s*.*)"
  191. }
  192. ],
  193. "comment": [
  194. {
  195. token : "punctuation.definition.comment.makefile",
  196. regex : /.+\\/
  197. },
  198. {
  199. token : "punctuation.definition.comment.makefile",
  200. regex : ".+",
  201. next : "start"
  202. }
  203. ],
  204. "shell-start": [
  205. {
  206. token: keywordMapper,
  207. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  208. },
  209. {
  210. token: "string",
  211. regex : "\\w+"
  212. },
  213. {
  214. token : "string.interpolated.backtick.makefile",
  215. regex : "`",
  216. next : "start"
  217. }
  218. ]
  219. }
  220. };
  221. oop.inherits(MakefileHighlightRules, TextHighlightRules);
  222. exports.MakefileHighlightRules = MakefileHighlightRules;
  223. });
  224. ace.define("ace/mode/folding/coffee",["require","exports","module","ace/lib/oop","ace/mode/folding/fold_mode","ace/range"], function(require, exports, module) {
  225. "use strict";
  226. var oop = require("../../lib/oop");
  227. var BaseFoldMode = require("./fold_mode").FoldMode;
  228. var Range = require("../../range").Range;
  229. var FoldMode = exports.FoldMode = function() {};
  230. oop.inherits(FoldMode, BaseFoldMode);
  231. (function() {
  232. this.getFoldWidgetRange = function(session, foldStyle, row) {
  233. var range = this.indentationBlock(session, row);
  234. if (range)
  235. return range;
  236. var re = /\S/;
  237. var line = session.getLine(row);
  238. var startLevel = line.search(re);
  239. if (startLevel == -1 || line[startLevel] != "#")
  240. return;
  241. var startColumn = line.length;
  242. var maxRow = session.getLength();
  243. var startRow = row;
  244. var endRow = row;
  245. while (++row < maxRow) {
  246. line = session.getLine(row);
  247. var level = line.search(re);
  248. if (level == -1)
  249. continue;
  250. if (line[level] != "#")
  251. break;
  252. endRow = row;
  253. }
  254. if (endRow > startRow) {
  255. var endColumn = session.getLine(endRow).length;
  256. return new Range(startRow, startColumn, endRow, endColumn);
  257. }
  258. };
  259. this.getFoldWidget = function(session, foldStyle, row) {
  260. var line = session.getLine(row);
  261. var indent = line.search(/\S/);
  262. var next = session.getLine(row + 1);
  263. var prev = session.getLine(row - 1);
  264. var prevIndent = prev.search(/\S/);
  265. var nextIndent = next.search(/\S/);
  266. if (indent == -1) {
  267. session.foldWidgets[row - 1] = prevIndent!= -1 && prevIndent < nextIndent ? "start" : "";
  268. return "";
  269. }
  270. if (prevIndent == -1) {
  271. if (indent == nextIndent && line[indent] == "#" && next[indent] == "#") {
  272. session.foldWidgets[row - 1] = "";
  273. session.foldWidgets[row + 1] = "";
  274. return "start";
  275. }
  276. } else if (prevIndent == indent && line[indent] == "#" && prev[indent] == "#") {
  277. if (session.getLine(row - 2).search(/\S/) == -1) {
  278. session.foldWidgets[row - 1] = "start";
  279. session.foldWidgets[row + 1] = "";
  280. return "";
  281. }
  282. }
  283. if (prevIndent!= -1 && prevIndent < indent)
  284. session.foldWidgets[row - 1] = "start";
  285. else
  286. session.foldWidgets[row - 1] = "";
  287. if (indent < nextIndent)
  288. return "start";
  289. else
  290. return "";
  291. };
  292. }).call(FoldMode.prototype);
  293. });
  294. ace.define("ace/mode/makefile",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/makefile_highlight_rules","ace/mode/folding/coffee"], function(require, exports, module) {
  295. "use strict";
  296. var oop = require("../lib/oop");
  297. var TextMode = require("./text").Mode;
  298. var MakefileHighlightRules = require("./makefile_highlight_rules").MakefileHighlightRules;
  299. var FoldMode = require("./folding/coffee").FoldMode;
  300. var Mode = function() {
  301. this.HighlightRules = MakefileHighlightRules;
  302. this.foldingRules = new FoldMode();
  303. };
  304. oop.inherits(Mode, TextMode);
  305. (function() {
  306. this.lineCommentStart = "#";
  307. this.$indentWithTabs = true;
  308. this.$id = "ace/mode/makefile";
  309. }).call(Mode.prototype);
  310. exports.Mode = Mode;
  311. });