mode-makefile.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  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|function|declare|readonly'
  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 + "=)";
  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.start",
  47. regex : '"',
  48. push : [{
  49. token : "constant.language.escape",
  50. regex : /\\(?:[$`"\\]|$)/
  51. }, {
  52. include : "variables"
  53. }, {
  54. token : "keyword.operator",
  55. regex : /`/ // TODO highlight `
  56. }, {
  57. token : "string.end",
  58. regex : '"',
  59. next: "pop"
  60. }, {
  61. defaultToken: "string"
  62. }]
  63. }, {
  64. token : "string",
  65. regex : "\\$'",
  66. push : [{
  67. token : "constant.language.escape",
  68. regex : /\\(?:[abeEfnrtv\\'"]|x[a-fA-F\d]{1,2}|u[a-fA-F\d]{4}([a-fA-F\d]{4})?|c.|\d{1,3})/
  69. }, {
  70. token : "string",
  71. regex : "'",
  72. next: "pop"
  73. }, {
  74. defaultToken: "string"
  75. }]
  76. }, {
  77. regex : "<<<",
  78. token : "keyword.operator"
  79. }, {
  80. stateName: "heredoc",
  81. regex : "(<<-?)(\\s*)(['\"`]?)([\\w\\-]+)(['\"`]?)",
  82. onMatch : function(value, currentState, stack) {
  83. var next = value[2] == '-' ? "indentedHeredoc" : "heredoc";
  84. var tokens = value.split(this.splitRegex);
  85. stack.push(next, tokens[4]);
  86. return [
  87. {type:"constant", value: tokens[1]},
  88. {type:"text", value: tokens[2]},
  89. {type:"string", value: tokens[3]},
  90. {type:"support.class", value: tokens[4]},
  91. {type:"string", value: tokens[5]}
  92. ];
  93. },
  94. rules: {
  95. heredoc: [{
  96. onMatch: function(value, currentState, stack) {
  97. if (value === stack[1]) {
  98. stack.shift();
  99. stack.shift();
  100. this.next = stack[0] || "start";
  101. return "support.class";
  102. }
  103. this.next = "";
  104. return "string";
  105. },
  106. regex: ".*$",
  107. next: "start"
  108. }],
  109. indentedHeredoc: [{
  110. token: "string",
  111. regex: "^\t+"
  112. }, {
  113. onMatch: function(value, currentState, stack) {
  114. if (value === stack[1]) {
  115. stack.shift();
  116. stack.shift();
  117. this.next = stack[0] || "start";
  118. return "support.class";
  119. }
  120. this.next = "";
  121. return "string";
  122. },
  123. regex: ".*$",
  124. next: "start"
  125. }]
  126. }
  127. }, {
  128. regex : "$",
  129. token : "empty",
  130. next : function(currentState, stack) {
  131. if (stack[0] === "heredoc" || stack[0] === "indentedHeredoc")
  132. return stack[0];
  133. return currentState;
  134. }
  135. }, {
  136. token : ["keyword", "text", "text", "text", "variable"],
  137. regex : /(declare|local|readonly)(\s+)(?:(-[fixar]+)(\s+))?([a-zA-Z_][a-zA-Z0-9_]*\b)/
  138. }, {
  139. token : "variable.language",
  140. regex : builtinVariable
  141. }, {
  142. token : "variable",
  143. regex : variable
  144. }, {
  145. include : "variables"
  146. }, {
  147. token : "support.function",
  148. regex : func
  149. }, {
  150. token : "support.function",
  151. regex : fileDescriptor
  152. }, {
  153. token : "string", // ' string
  154. start : "'", end : "'"
  155. }, {
  156. token : "constant.numeric", // float
  157. regex : floatNumber
  158. }, {
  159. token : "constant.numeric", // integer
  160. regex : integer + "\\b"
  161. }, {
  162. token : keywordMapper,
  163. regex : "[a-zA-Z_][a-zA-Z0-9_]*\\b"
  164. }, {
  165. token : "keyword.operator",
  166. regex : "\\+|\\-|\\*|\\*\\*|\\/|\\/\\/|~|<|>|<=|=>|=|!=|[%&|`]"
  167. }, {
  168. token : "punctuation.operator",
  169. regex : ";"
  170. }, {
  171. token : "paren.lparen",
  172. regex : "[\\[\\(\\{]"
  173. }, {
  174. token : "paren.rparen",
  175. regex : "[\\]]"
  176. }, {
  177. token : "paren.rparen",
  178. regex : "[\\)\\}]",
  179. next : "pop"
  180. }],
  181. variables: [{
  182. token : "variable",
  183. regex : /(\$)(\w+)/
  184. }, {
  185. token : ["variable", "paren.lparen"],
  186. regex : /(\$)(\()/,
  187. push : "start"
  188. }, {
  189. token : ["variable", "paren.lparen", "keyword.operator", "variable", "keyword.operator"],
  190. regex : /(\$)(\{)([#!]?)(\w+|[*@#?\-$!0_])(:[?+\-=]?|##?|%%?|,,?\/|\^\^?)?/,
  191. push : "start"
  192. }, {
  193. token : "variable",
  194. regex : /\$[*@#?\-$!0_]/
  195. }, {
  196. token : ["variable", "paren.lparen"],
  197. regex : /(\$)(\{)/,
  198. push : "start"
  199. }]
  200. };
  201. this.normalizeRules();
  202. };
  203. oop.inherits(ShHighlightRules, TextHighlightRules);
  204. exports.ShHighlightRules = ShHighlightRules;
  205. });
  206. 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) {
  207. "use strict";
  208. var oop = require("../lib/oop");
  209. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  210. var ShHighlightFile = require("./sh_highlight_rules");
  211. var MakefileHighlightRules = function() {
  212. var keywordMapper = this.createKeywordMapper({
  213. "keyword": ShHighlightFile.reservedKeywords,
  214. "support.function.builtin": ShHighlightFile.languageConstructs,
  215. "invalid.deprecated": "debugger"
  216. }, "string");
  217. this.$rules =
  218. {
  219. "start": [
  220. {
  221. token: "string.interpolated.backtick.makefile",
  222. regex: "`",
  223. next: "shell-start"
  224. },
  225. {
  226. token: "punctuation.definition.comment.makefile",
  227. regex: /#(?=.)/,
  228. next: "comment"
  229. },
  230. {
  231. token: [ "keyword.control.makefile"],
  232. regex: "^(?:\\s*\\b)(\\-??include|ifeq|ifneq|ifdef|ifndef|else|endif|vpath|export|unexport|define|endef|override)(?:\\b)"
  233. },
  234. {// ^([^\t ]+(\s[^\t ]+)*:(?!\=))\s*.*
  235. token: ["entity.name.function.makefile", "text"],
  236. regex: "^([^\\t ]+(?:\\s[^\\t ]+)*:)(\\s*.*)"
  237. }
  238. ],
  239. "comment": [
  240. {
  241. token : "punctuation.definition.comment.makefile",
  242. regex : /.+\\/
  243. },
  244. {
  245. token : "punctuation.definition.comment.makefile",
  246. regex : ".+",
  247. next : "start"
  248. }
  249. ],
  250. "shell-start": [
  251. {
  252. token: keywordMapper,
  253. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  254. },
  255. {
  256. token: "string",
  257. regex : "\\w+"
  258. },
  259. {
  260. token : "string.interpolated.backtick.makefile",
  261. regex : "`",
  262. next : "start"
  263. }
  264. ]
  265. }
  266. };
  267. oop.inherits(MakefileHighlightRules, TextHighlightRules);
  268. exports.MakefileHighlightRules = MakefileHighlightRules;
  269. });
  270. ace.define("ace/mode/folding/coffee",["require","exports","module","ace/lib/oop","ace/mode/folding/fold_mode","ace/range"], function(require, exports, module) {
  271. "use strict";
  272. var oop = require("../../lib/oop");
  273. var BaseFoldMode = require("./fold_mode").FoldMode;
  274. var Range = require("../../range").Range;
  275. var FoldMode = exports.FoldMode = function() {};
  276. oop.inherits(FoldMode, BaseFoldMode);
  277. (function() {
  278. this.getFoldWidgetRange = function(session, foldStyle, row) {
  279. var range = this.indentationBlock(session, row);
  280. if (range)
  281. return range;
  282. var re = /\S/;
  283. var line = session.getLine(row);
  284. var startLevel = line.search(re);
  285. if (startLevel == -1 || line[startLevel] != "#")
  286. return;
  287. var startColumn = line.length;
  288. var maxRow = session.getLength();
  289. var startRow = row;
  290. var endRow = row;
  291. while (++row < maxRow) {
  292. line = session.getLine(row);
  293. var level = line.search(re);
  294. if (level == -1)
  295. continue;
  296. if (line[level] != "#")
  297. break;
  298. endRow = row;
  299. }
  300. if (endRow > startRow) {
  301. var endColumn = session.getLine(endRow).length;
  302. return new Range(startRow, startColumn, endRow, endColumn);
  303. }
  304. };
  305. this.getFoldWidget = function(session, foldStyle, row) {
  306. var line = session.getLine(row);
  307. var indent = line.search(/\S/);
  308. var next = session.getLine(row + 1);
  309. var prev = session.getLine(row - 1);
  310. var prevIndent = prev.search(/\S/);
  311. var nextIndent = next.search(/\S/);
  312. if (indent == -1) {
  313. session.foldWidgets[row - 1] = prevIndent!= -1 && prevIndent < nextIndent ? "start" : "";
  314. return "";
  315. }
  316. if (prevIndent == -1) {
  317. if (indent == nextIndent && line[indent] == "#" && next[indent] == "#") {
  318. session.foldWidgets[row - 1] = "";
  319. session.foldWidgets[row + 1] = "";
  320. return "start";
  321. }
  322. } else if (prevIndent == indent && line[indent] == "#" && prev[indent] == "#") {
  323. if (session.getLine(row - 2).search(/\S/) == -1) {
  324. session.foldWidgets[row - 1] = "start";
  325. session.foldWidgets[row + 1] = "";
  326. return "";
  327. }
  328. }
  329. if (prevIndent!= -1 && prevIndent < indent)
  330. session.foldWidgets[row - 1] = "start";
  331. else
  332. session.foldWidgets[row - 1] = "";
  333. if (indent < nextIndent)
  334. return "start";
  335. else
  336. return "";
  337. };
  338. }).call(FoldMode.prototype);
  339. });
  340. 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) {
  341. "use strict";
  342. var oop = require("../lib/oop");
  343. var TextMode = require("./text").Mode;
  344. var MakefileHighlightRules = require("./makefile_highlight_rules").MakefileHighlightRules;
  345. var FoldMode = require("./folding/coffee").FoldMode;
  346. var Mode = function() {
  347. this.HighlightRules = MakefileHighlightRules;
  348. this.foldingRules = new FoldMode();
  349. this.$behaviour = this.$defaultBehaviour;
  350. };
  351. oop.inherits(Mode, TextMode);
  352. (function() {
  353. this.lineCommentStart = "#";
  354. this.$indentWithTabs = true;
  355. this.$id = "ace/mode/makefile";
  356. }).call(Mode.prototype);
  357. exports.Mode = Mode;
  358. });