mode-puppet.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. define("ace/mode/puppet_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 PuppetHighlightRules = function () {
  6. this.$rules = {
  7. "start": [
  8. {
  9. token: ['keyword.type.puppet', 'constant.class.puppet', 'keyword.inherits.puppet', 'constant.class.puppet'],
  10. regex: "^\\s*(class)(\\s+(?:[-_A-Za-z0-9\".]+::)*[-_A-Za-z0-9\".]+\\s*)(?:(inherits\\s*)(\\s+(?:[-_A-Za-z0-9\".]+::)*[-_A-Za-z0-9\".]+\\s*))?"
  11. },
  12. {
  13. token: ['storage.function.puppet', 'name.function.puppet', 'punctuation.lpar'],
  14. regex: "(^\\s*define)(\\s+[a-zA-Z0-9_:]+\\s*)(\\()",
  15. push:
  16. [{
  17. token: 'punctuation.rpar.puppet',
  18. regex: "\\)",
  19. next: 'pop'
  20. },
  21. {include: "constants"},
  22. {include: "variable"},
  23. {include: "strings"},
  24. {include: "operators"},
  25. {defaultToken: 'string'}]
  26. },
  27. {
  28. token: ["language.support.class", "keyword.operator"],
  29. regex: "\\b([a-zA-Z_]+)(\\s+=>)"
  30. },
  31. {
  32. token: ["exported.resource.puppet", "keyword.name.resource.puppet", "paren.lparen"],
  33. regex: "(\\@\\@)?(\\s*[a-zA-Z_]*)(\\s*\\{)"
  34. },
  35. {
  36. token: "qualified.variable.puppet",
  37. regex: "(\\$([a-z][a-z0-9_]*)?(::[a-z][a-z0-9_]*)*::[a-z0-9_][a-zA-Z0-9_]*)"
  38. },
  39. {
  40. token: "singleline.comment.puppet",
  41. regex: '#(.)*$'
  42. },
  43. {
  44. token: "multiline.comment.begin.puppet",
  45. regex: '^\\s*\\/\\*\\s*$',
  46. push: "blockComment"
  47. },
  48. {
  49. token: "keyword.control.puppet",
  50. regex: "\\b(case|if|unless|else|elsif|in|default:|and|or)\\s+(?!::)"
  51. },
  52. {
  53. token: "keyword.control.puppet",
  54. regex: "\\b(import|default|inherits|include|require|contain|node|application|consumes|environment|site|function|produces)\\b"
  55. },
  56. {
  57. token: "support.function.puppet",
  58. regex: "\\b(lest|str2bool|escape|gsub|Timestamp|Timespan|with|alert|crit|debug|notice|sprintf|split|step|strftime|slice|shellquote|type|sha1|defined|scanf|reverse_each|regsubst|return|emerg|reduce|err|failed|fail|versioncmp|file|generate|then|info|realize|search|tag|tagged|template|epp|warning|hiera_include|each|assert_type|binary_file|create_resources|dig|digest|filter|lookup|find_file|fqdn_rand|hiera_array|hiera_hash|inline_epp|inline_template|map|match|md5|new|next)\\b"
  59. },
  60. {
  61. token: "constant.types.puppet",
  62. regex: "\\b(String|File|Package|Service|Class|Integer|Array|Catalogentry|Variant|Boolean|Undef|Number|Hash|Float|Numeric|NotUndef|Callable|Optional|Any|Regexp|Sensitive|Sensitive.new|Type|Resource|Default|Enum|Scalar|Collection|Data|Pattern|Tuple|Struct)\\b"
  63. },
  64. {
  65. token: "paren.lparen",
  66. regex: "[[({]"
  67. },
  68. {
  69. token: "paren.rparen",
  70. regex: "[\\])}]"
  71. },
  72. {include: "variable"},
  73. {include: "constants"},
  74. {include: "strings"},
  75. {include: "operators"},
  76. {
  77. token: "regexp.begin.string.puppet",
  78. regex: "\\s*(\\/(\\S)+)\\/"
  79. }
  80. ],
  81. blockComment: [{
  82. regex: "^\\s*\\/\\*\\s*$",
  83. token: "multiline.comment.begin.puppet",
  84. push: "blockComment"
  85. }, {
  86. regex: "^\\s*\\*\\/\\s*$",
  87. token: "multiline.comment.end.puppet",
  88. next: "pop"
  89. }, {
  90. defaultToken: "comment"
  91. }],
  92. "constants": [
  93. {
  94. token: "constant.language.puppet",
  95. regex: "\\b(false|true|running|stopped|installed|purged|latest|file|directory|held|undef|present|absent|link|mounted|unmounted)\\b"
  96. }
  97. ],
  98. "variable": [
  99. {
  100. token: "variable.puppet",
  101. regex: "(\\$[a-z0-9_\{][a-zA-Z0-9_]*)"
  102. }
  103. ],
  104. "strings": [
  105. {
  106. token: "punctuation.quote.puppet",
  107. regex: "'",
  108. push:
  109. [{
  110. token: 'punctuation.quote.puppet',
  111. regex: "'",
  112. next: 'pop'
  113. },
  114. {include: "escaped_chars"},
  115. {defaultToken: 'string'}]
  116. },
  117. {
  118. token: "punctuation.quote.puppet",
  119. regex: '"',
  120. push:
  121. [{
  122. token: 'punctuation.quote.puppet',
  123. regex: '"',
  124. next: 'pop'
  125. },
  126. {include: "escaped_chars"},
  127. {include: "variable"},
  128. {defaultToken: 'string'}]
  129. }
  130. ],
  131. "escaped_chars": [
  132. {
  133. token: "constant.escaped_char.puppet",
  134. regex: "\\\\."
  135. }
  136. ],
  137. "operators": [
  138. {
  139. token: "keyword.operator",
  140. regex: "\\+\\.|\\-\\.|\\*\\.|\\/\\.|#|;;|\\+|\\-|\\*|\\*\\*\\/|\\/\\/|%|<<|>>|&|\\||\\^|~|<|>|<=|=>|==|!=|<>|<-|=|::|,"
  141. }
  142. ]
  143. };
  144. this.normalizeRules();
  145. };
  146. oop.inherits(PuppetHighlightRules, TextHighlightRules);
  147. exports.PuppetHighlightRules = PuppetHighlightRules;
  148. });
  149. define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  150. "use strict";
  151. var oop = require("../../lib/oop");
  152. var Range = require("../../range").Range;
  153. var BaseFoldMode = require("./fold_mode").FoldMode;
  154. var FoldMode = exports.FoldMode = function(commentRegex) {
  155. if (commentRegex) {
  156. this.foldingStartMarker = new RegExp(
  157. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  158. );
  159. this.foldingStopMarker = new RegExp(
  160. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  161. );
  162. }
  163. };
  164. oop.inherits(FoldMode, BaseFoldMode);
  165. (function() {
  166. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  167. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  168. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  169. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  170. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  171. this._getFoldWidgetBase = this.getFoldWidget;
  172. this.getFoldWidget = function(session, foldStyle, row) {
  173. var line = session.getLine(row);
  174. if (this.singleLineBlockCommentRe.test(line)) {
  175. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  176. return "";
  177. }
  178. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  179. if (!fw && this.startRegionRe.test(line))
  180. return "start"; // lineCommentRegionStart
  181. return fw;
  182. };
  183. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  184. var line = session.getLine(row);
  185. if (this.startRegionRe.test(line))
  186. return this.getCommentRegionBlock(session, line, row);
  187. var match = line.match(this.foldingStartMarker);
  188. if (match) {
  189. var i = match.index;
  190. if (match[1])
  191. return this.openingBracketBlock(session, match[1], row, i);
  192. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  193. if (range && !range.isMultiLine()) {
  194. if (forceMultiline) {
  195. range = this.getSectionRange(session, row);
  196. } else if (foldStyle != "all")
  197. range = null;
  198. }
  199. return range;
  200. }
  201. if (foldStyle === "markbegin")
  202. return;
  203. var match = line.match(this.foldingStopMarker);
  204. if (match) {
  205. var i = match.index + match[0].length;
  206. if (match[1])
  207. return this.closingBracketBlock(session, match[1], row, i);
  208. return session.getCommentFoldRange(row, i, -1);
  209. }
  210. };
  211. this.getSectionRange = function(session, row) {
  212. var line = session.getLine(row);
  213. var startIndent = line.search(/\S/);
  214. var startRow = row;
  215. var startColumn = line.length;
  216. row = row + 1;
  217. var endRow = row;
  218. var maxRow = session.getLength();
  219. while (++row < maxRow) {
  220. line = session.getLine(row);
  221. var indent = line.search(/\S/);
  222. if (indent === -1)
  223. continue;
  224. if (startIndent > indent)
  225. break;
  226. var subRange = this.getFoldWidgetRange(session, "all", row);
  227. if (subRange) {
  228. if (subRange.start.row <= startRow) {
  229. break;
  230. } else if (subRange.isMultiLine()) {
  231. row = subRange.end.row;
  232. } else if (startIndent == indent) {
  233. break;
  234. }
  235. }
  236. endRow = row;
  237. }
  238. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  239. };
  240. this.getCommentRegionBlock = function(session, line, row) {
  241. var startColumn = line.search(/\s*$/);
  242. var maxRow = session.getLength();
  243. var startRow = row;
  244. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  245. var depth = 1;
  246. while (++row < maxRow) {
  247. line = session.getLine(row);
  248. var m = re.exec(line);
  249. if (!m) continue;
  250. if (m[1]) depth--;
  251. else depth++;
  252. if (!depth) break;
  253. }
  254. var endRow = row;
  255. if (endRow > startRow) {
  256. return new Range(startRow, startColumn, endRow, line.length);
  257. }
  258. };
  259. }).call(FoldMode.prototype);
  260. });
  261. define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module) {
  262. "use strict";
  263. var Range = require("../range").Range;
  264. var MatchingBraceOutdent = function() {};
  265. (function() {
  266. this.checkOutdent = function(line, input) {
  267. if (! /^\s+$/.test(line))
  268. return false;
  269. return /^\s*\}/.test(input);
  270. };
  271. this.autoOutdent = function(doc, row) {
  272. var line = doc.getLine(row);
  273. var match = line.match(/^(\s*\})/);
  274. if (!match) return 0;
  275. var column = match[1].length;
  276. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  277. if (!openBracePos || openBracePos.row == row) return 0;
  278. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  279. doc.replace(new Range(row, 0, row, column-1), indent);
  280. };
  281. this.$getIndent = function(line) {
  282. return line.match(/^\s*/)[0];
  283. };
  284. }).call(MatchingBraceOutdent.prototype);
  285. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  286. });
  287. define("ace/mode/puppet",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/puppet_highlight_rules","ace/mode/behaviour/cstyle","ace/mode/folding/cstyle","ace/mode/matching_brace_outdent"], function (require, exports, module) {
  288. "use strict";
  289. var oop = require("../lib/oop");
  290. var TextMode = require("./text").Mode;
  291. var PuppetHighlightRules = require("./puppet_highlight_rules").PuppetHighlightRules;
  292. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  293. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  294. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  295. var Mode = function () {
  296. TextMode.call(this);
  297. this.HighlightRules = PuppetHighlightRules;
  298. this.$outdent = new MatchingBraceOutdent();
  299. this.$behaviour = new CstyleBehaviour();
  300. this.foldingRules = new CStyleFoldMode();
  301. };
  302. oop.inherits(Mode, TextMode);
  303. (function () {
  304. this.$id = "ace/mode/puppet";
  305. }).call(Mode.prototype);
  306. exports.Mode = Mode;
  307. });
  308. (function() {
  309. window.require(["ace/mode/puppet"], function(m) {
  310. if (typeof module == "object" && typeof exports == "object" && module) {
  311. module.exports = m;
  312. }
  313. });
  314. })();