mode-puppet.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. ace.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*\\/\\*',
  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: "\\*\\/",
  83. token: "multiline.comment.end.puppet",
  84. next: "pop"
  85. }, {
  86. defaultToken: "comment"
  87. }],
  88. "constants": [
  89. {
  90. token: "constant.language.puppet",
  91. regex: "\\b(false|true|running|stopped|installed|purged|latest|file|directory|held|undef|present|absent|link|mounted|unmounted)\\b"
  92. }
  93. ],
  94. "variable": [
  95. {
  96. token: "variable.puppet",
  97. regex: "(\\$[a-z0-9_\{][a-zA-Z0-9_]*)"
  98. }
  99. ],
  100. "strings": [
  101. {
  102. token: "punctuation.quote.puppet",
  103. regex: "'",
  104. push:
  105. [{
  106. token: 'punctuation.quote.puppet',
  107. regex: "'",
  108. next: 'pop'
  109. },
  110. {include: "escaped_chars"},
  111. {defaultToken: 'string'}]
  112. },
  113. {
  114. token: "punctuation.quote.puppet",
  115. regex: '"',
  116. push:
  117. [{
  118. token: 'punctuation.quote.puppet',
  119. regex: '"',
  120. next: 'pop'
  121. },
  122. {include: "escaped_chars"},
  123. {include: "variable"},
  124. {defaultToken: 'string'}]
  125. }
  126. ],
  127. "escaped_chars": [
  128. {
  129. token: "constant.escaped_char.puppet",
  130. regex: "\\\\."
  131. }
  132. ],
  133. "operators": [
  134. {
  135. token: "keyword.operator",
  136. regex: "\\+\\.|\\-\\.|\\*\\.|\\/\\.|#|;;|\\+|\\-|\\*|\\*\\*\\/|\\/\\/|%|<<|>>|&|\\||\\^|~|<|>|<=|=>|==|!=|<>|<-|=|::|,"
  137. }
  138. ]
  139. };
  140. this.normalizeRules();
  141. };
  142. oop.inherits(PuppetHighlightRules, TextHighlightRules);
  143. exports.PuppetHighlightRules = PuppetHighlightRules;
  144. });
  145. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  146. "use strict";
  147. var oop = require("../../lib/oop");
  148. var Range = require("../../range").Range;
  149. var BaseFoldMode = require("./fold_mode").FoldMode;
  150. var FoldMode = exports.FoldMode = function(commentRegex) {
  151. if (commentRegex) {
  152. this.foldingStartMarker = new RegExp(
  153. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  154. );
  155. this.foldingStopMarker = new RegExp(
  156. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  157. );
  158. }
  159. };
  160. oop.inherits(FoldMode, BaseFoldMode);
  161. (function() {
  162. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  163. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  164. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  165. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  166. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  167. this._getFoldWidgetBase = this.getFoldWidget;
  168. this.getFoldWidget = function(session, foldStyle, row) {
  169. var line = session.getLine(row);
  170. if (this.singleLineBlockCommentRe.test(line)) {
  171. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  172. return "";
  173. }
  174. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  175. if (!fw && this.startRegionRe.test(line))
  176. return "start"; // lineCommentRegionStart
  177. return fw;
  178. };
  179. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  180. var line = session.getLine(row);
  181. if (this.startRegionRe.test(line))
  182. return this.getCommentRegionBlock(session, line, row);
  183. var match = line.match(this.foldingStartMarker);
  184. if (match) {
  185. var i = match.index;
  186. if (match[1])
  187. return this.openingBracketBlock(session, match[1], row, i);
  188. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  189. if (range && !range.isMultiLine()) {
  190. if (forceMultiline) {
  191. range = this.getSectionRange(session, row);
  192. } else if (foldStyle != "all")
  193. range = null;
  194. }
  195. return range;
  196. }
  197. if (foldStyle === "markbegin")
  198. return;
  199. var match = line.match(this.foldingStopMarker);
  200. if (match) {
  201. var i = match.index + match[0].length;
  202. if (match[1])
  203. return this.closingBracketBlock(session, match[1], row, i);
  204. return session.getCommentFoldRange(row, i, -1);
  205. }
  206. };
  207. this.getSectionRange = function(session, row) {
  208. var line = session.getLine(row);
  209. var startIndent = line.search(/\S/);
  210. var startRow = row;
  211. var startColumn = line.length;
  212. row = row + 1;
  213. var endRow = row;
  214. var maxRow = session.getLength();
  215. while (++row < maxRow) {
  216. line = session.getLine(row);
  217. var indent = line.search(/\S/);
  218. if (indent === -1)
  219. continue;
  220. if (startIndent > indent)
  221. break;
  222. var subRange = this.getFoldWidgetRange(session, "all", row);
  223. if (subRange) {
  224. if (subRange.start.row <= startRow) {
  225. break;
  226. } else if (subRange.isMultiLine()) {
  227. row = subRange.end.row;
  228. } else if (startIndent == indent) {
  229. break;
  230. }
  231. }
  232. endRow = row;
  233. }
  234. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  235. };
  236. this.getCommentRegionBlock = function(session, line, row) {
  237. var startColumn = line.search(/\s*$/);
  238. var maxRow = session.getLength();
  239. var startRow = row;
  240. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  241. var depth = 1;
  242. while (++row < maxRow) {
  243. line = session.getLine(row);
  244. var m = re.exec(line);
  245. if (!m) continue;
  246. if (m[1]) depth--;
  247. else depth++;
  248. if (!depth) break;
  249. }
  250. var endRow = row;
  251. if (endRow > startRow) {
  252. return new Range(startRow, startColumn, endRow, line.length);
  253. }
  254. };
  255. }).call(FoldMode.prototype);
  256. });
  257. ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module) {
  258. "use strict";
  259. var Range = require("../range").Range;
  260. var MatchingBraceOutdent = function() {};
  261. (function() {
  262. this.checkOutdent = function(line, input) {
  263. if (! /^\s+$/.test(line))
  264. return false;
  265. return /^\s*\}/.test(input);
  266. };
  267. this.autoOutdent = function(doc, row) {
  268. var line = doc.getLine(row);
  269. var match = line.match(/^(\s*\})/);
  270. if (!match) return 0;
  271. var column = match[1].length;
  272. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  273. if (!openBracePos || openBracePos.row == row) return 0;
  274. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  275. doc.replace(new Range(row, 0, row, column-1), indent);
  276. };
  277. this.$getIndent = function(line) {
  278. return line.match(/^\s*/)[0];
  279. };
  280. }).call(MatchingBraceOutdent.prototype);
  281. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  282. });
  283. ace.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) {
  284. "use strict";
  285. var oop = require("../lib/oop");
  286. var TextMode = require("./text").Mode;
  287. var PuppetHighlightRules = require("./puppet_highlight_rules").PuppetHighlightRules;
  288. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  289. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  290. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  291. var Mode = function () {
  292. TextMode.call(this);
  293. this.HighlightRules = PuppetHighlightRules;
  294. this.$outdent = new MatchingBraceOutdent();
  295. this.$behaviour = new CstyleBehaviour();
  296. this.foldingRules = new CStyleFoldMode();
  297. };
  298. oop.inherits(Mode, TextMode);
  299. (function () {
  300. this.lineCommentStart = "#";
  301. this.blockComment = {start: "/*", end: "*/"};
  302. this.$id = "ace/mode/puppet";
  303. }).call(Mode.prototype);
  304. exports.Mode = Mode;
  305. }); (function() {
  306. ace.require(["ace/mode/puppet"], function(m) {
  307. if (typeof module == "object" && typeof exports == "object" && module) {
  308. module.exports = m;
  309. }
  310. });
  311. })();