mode-terraform.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. define("ace/mode/terraform_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 TerraformHighlightRules = function () {
  6. this.$rules = {
  7. "start": [
  8. {
  9. token: ['storage.function.terraform'],
  10. regex: '\\b(output|resource|data|variable|module|export)\\b'
  11. },
  12. {
  13. token: "variable.terraform",
  14. regex: "\\$\\s",
  15. push: [
  16. {
  17. token: "keyword.terraform",
  18. regex: "(-var-file|-var)"
  19. },
  20. {
  21. token: "variable.terraform",
  22. regex: "\\n|$",
  23. next: "pop"
  24. },
  25. {include: "strings"},
  26. {include: "variables"},
  27. {include: "operators"},
  28. {defaultToken: "text"}
  29. ]
  30. },
  31. {
  32. token: "language.support.class",
  33. regex: "\\b(timeouts|provider|connection|provisioner|lifecycleprovider|atlas)\\b"
  34. },
  35. {
  36. token: "singleline.comment.terraform",
  37. regex: '#(.)*$'
  38. },
  39. {
  40. token: "multiline.comment.begin.terraform",
  41. regex: '^\\s*\\/\\*',
  42. push: "blockComment"
  43. },
  44. {
  45. token: "storage.function.terraform",
  46. regex: "^\\s*(locals|terraform)\\s*{"
  47. },
  48. {
  49. token: "paren.lparen",
  50. regex: "[[({]"
  51. },
  52. {
  53. token: "paren.rparen",
  54. regex: "[\\])}]"
  55. },
  56. {include: "constants"},
  57. {include: "strings"},
  58. {include: "operators"},
  59. {include: "variables"}
  60. ],
  61. blockComment: [{
  62. regex: "^\\s*\\/\\*",
  63. token: "multiline.comment.begin.terraform",
  64. push: "blockComment"
  65. }, {
  66. regex: "\\*\\/\\s*$",
  67. token: "multiline.comment.end.terraform",
  68. next: "pop"
  69. }, {
  70. defaultToken: "comment"
  71. }],
  72. "constants": [
  73. {
  74. token: "constant.language.terraform",
  75. regex: "\\b(true|false|yes|no|on|off|EOF)\\b"
  76. },
  77. {
  78. token: "constant.numeric.terraform",
  79. regex: "(\\b([0-9]+)([kKmMgG]b?)?\\b)|(\\b(0x[0-9A-Fa-f]+)([kKmMgG]b?)?\\b)"
  80. }
  81. ],
  82. "variables": [
  83. {
  84. token: ["variable.assignment.terraform", "keyword.operator"],
  85. regex: "\\b([a-zA-Z_]+)(\\s*=)"
  86. }
  87. ],
  88. "interpolated_variables": [
  89. {
  90. token: "variable.terraform",
  91. regex: "\\b(var|self|count|path|local)\\b(?:\\.*[a-zA-Z_-]*)?"
  92. }
  93. ],
  94. "strings": [
  95. {
  96. token: "punctuation.quote.terraform",
  97. regex: "'",
  98. push:
  99. [{
  100. token: 'punctuation.quote.terraform',
  101. regex: "'",
  102. next: 'pop'
  103. },
  104. {include: "escaped_chars"},
  105. {defaultToken: 'string'}]
  106. },
  107. {
  108. token: "punctuation.quote.terraform",
  109. regex: '"',
  110. push:
  111. [{
  112. token: 'punctuation.quote.terraform',
  113. regex: '"',
  114. next: 'pop'
  115. },
  116. {include: "interpolation"},
  117. {include: "escaped_chars"},
  118. {defaultToken: 'string'}]
  119. }
  120. ],
  121. "escaped_chars": [
  122. {
  123. token: "constant.escaped_char.terraform",
  124. regex: "\\\\."
  125. }
  126. ],
  127. "operators": [
  128. {
  129. token: "keyword.operator",
  130. regex: "\\?|:|==|!=|>|<|>=|<=|&&|\\|\\\||!|%|&|\\*|\\+|\\-|/|="
  131. }
  132. ],
  133. "interpolation": [
  134. {// TODO: double $
  135. token: "punctuation.interpolated.begin.terraform",
  136. regex: "\\$?\\$\\{",
  137. push: [{
  138. token: "punctuation.interpolated.end.terraform",
  139. regex: "\\}",
  140. next: "pop"
  141. },
  142. {include: "interpolated_variables"},
  143. {include: "operators"},
  144. {include: "constants"},
  145. {include: "strings"},
  146. {include: "functions"},
  147. {include: "parenthesis"},
  148. {defaultToken: "punctuation"}
  149. ]
  150. }
  151. ],
  152. "functions": [
  153. {
  154. token: "keyword.function.terraform",
  155. regex: "\\b(abs|basename|base64decode|base64encode|base64gzip|base64sha256|base64sha512|bcrypt|ceil|chomp|chunklist|cidrhost|cidrnetmask|cidrsubnet|coalesce|coalescelist|compact|concat|contains|dirname|distinct|element|file|floor|flatten|format|formatlist|indent|index|join|jsonencode|keys|length|list|log|lookup|lower|map|matchkeys|max|merge|min|md5|pathexpand|pow|replace|rsadecrypt|sha1|sha256|sha512|signum|slice|sort|split|substr|timestamp|timeadd|title|transpose|trimspace|upper|urlencode|uuid|values|zipmap)\\b"
  156. }
  157. ],
  158. "parenthesis": [
  159. {
  160. token: "paren.lparen",
  161. regex: "\\["
  162. },
  163. {
  164. token: "paren.rparen",
  165. regex: "\\]"
  166. }
  167. ]
  168. };
  169. this.normalizeRules();
  170. };
  171. oop.inherits(TerraformHighlightRules, TextHighlightRules);
  172. exports.TerraformHighlightRules = TerraformHighlightRules;
  173. });
  174. define("ace/mode/folding/cstyle",["ace_require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(ace_require, exports, module) {
  175. "use strict";
  176. var oop = ace_require("../../lib/oop");
  177. var Range = ace_require("../../range").Range;
  178. var BaseFoldMode = ace_require("./fold_mode").FoldMode;
  179. var FoldMode = exports.FoldMode = function(commentRegex) {
  180. if (commentRegex) {
  181. this.foldingStartMarker = new RegExp(
  182. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  183. );
  184. this.foldingStopMarker = new RegExp(
  185. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  186. );
  187. }
  188. };
  189. oop.inherits(FoldMode, BaseFoldMode);
  190. (function() {
  191. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  192. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  193. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  194. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  195. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  196. this._getFoldWidgetBase = this.getFoldWidget;
  197. this.getFoldWidget = function(session, foldStyle, row) {
  198. var line = session.getLine(row);
  199. if (this.singleLineBlockCommentRe.test(line)) {
  200. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  201. return "";
  202. }
  203. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  204. if (!fw && this.startRegionRe.test(line))
  205. return "start"; // lineCommentRegionStart
  206. return fw;
  207. };
  208. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  209. var line = session.getLine(row);
  210. if (this.startRegionRe.test(line))
  211. return this.getCommentRegionBlock(session, line, row);
  212. var match = line.match(this.foldingStartMarker);
  213. if (match) {
  214. var i = match.index;
  215. if (match[1])
  216. return this.openingBracketBlock(session, match[1], row, i);
  217. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  218. if (range && !range.isMultiLine()) {
  219. if (forceMultiline) {
  220. range = this.getSectionRange(session, row);
  221. } else if (foldStyle != "all")
  222. range = null;
  223. }
  224. return range;
  225. }
  226. if (foldStyle === "markbegin")
  227. return;
  228. var match = line.match(this.foldingStopMarker);
  229. if (match) {
  230. var i = match.index + match[0].length;
  231. if (match[1])
  232. return this.closingBracketBlock(session, match[1], row, i);
  233. return session.getCommentFoldRange(row, i, -1);
  234. }
  235. };
  236. this.getSectionRange = function(session, row) {
  237. var line = session.getLine(row);
  238. var startIndent = line.search(/\S/);
  239. var startRow = row;
  240. var startColumn = line.length;
  241. row = row + 1;
  242. var endRow = row;
  243. var maxRow = session.getLength();
  244. while (++row < maxRow) {
  245. line = session.getLine(row);
  246. var indent = line.search(/\S/);
  247. if (indent === -1)
  248. continue;
  249. if (startIndent > indent)
  250. break;
  251. var subRange = this.getFoldWidgetRange(session, "all", row);
  252. if (subRange) {
  253. if (subRange.start.row <= startRow) {
  254. break;
  255. } else if (subRange.isMultiLine()) {
  256. row = subRange.end.row;
  257. } else if (startIndent == indent) {
  258. break;
  259. }
  260. }
  261. endRow = row;
  262. }
  263. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  264. };
  265. this.getCommentRegionBlock = function(session, line, row) {
  266. var startColumn = line.search(/\s*$/);
  267. var maxRow = session.getLength();
  268. var startRow = row;
  269. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  270. var depth = 1;
  271. while (++row < maxRow) {
  272. line = session.getLine(row);
  273. var m = re.exec(line);
  274. if (!m) continue;
  275. if (m[1]) depth--;
  276. else depth++;
  277. if (!depth) break;
  278. }
  279. var endRow = row;
  280. if (endRow > startRow) {
  281. return new Range(startRow, startColumn, endRow, line.length);
  282. }
  283. };
  284. }).call(FoldMode.prototype);
  285. });
  286. define("ace/mode/matching_brace_outdent",["ace_require","exports","module","ace/range"], function(ace_require, exports, module) {
  287. "use strict";
  288. var Range = ace_require("../range").Range;
  289. var MatchingBraceOutdent = function() {};
  290. (function() {
  291. this.checkOutdent = function(line, input) {
  292. if (! /^\s+$/.test(line))
  293. return false;
  294. return /^\s*\}/.test(input);
  295. };
  296. this.autoOutdent = function(doc, row) {
  297. var line = doc.getLine(row);
  298. var match = line.match(/^(\s*\})/);
  299. if (!match) return 0;
  300. var column = match[1].length;
  301. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  302. if (!openBracePos || openBracePos.row == row) return 0;
  303. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  304. doc.replace(new Range(row, 0, row, column-1), indent);
  305. };
  306. this.$getIndent = function(line) {
  307. return line.match(/^\s*/)[0];
  308. };
  309. }).call(MatchingBraceOutdent.prototype);
  310. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  311. });
  312. define("ace/mode/terraform",["ace_require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/terraform_highlight_rules","ace/mode/behaviour/cstyle","ace/mode/folding/cstyle","ace/mode/matching_brace_outdent"], function (ace_require, exports, module) {
  313. "use strict";
  314. var oop = ace_require("../lib/oop");
  315. var TextMode = ace_require("./text").Mode;
  316. var TerraformHighlightRules = ace_require("./terraform_highlight_rules").TerraformHighlightRules;
  317. var CstyleBehaviour = ace_require("./behaviour/cstyle").CstyleBehaviour;
  318. var CStyleFoldMode = ace_require("./folding/cstyle").FoldMode;
  319. var MatchingBraceOutdent = ace_require("./matching_brace_outdent").MatchingBraceOutdent;
  320. var Mode = function () {
  321. TextMode.call(this);
  322. this.HighlightRules = TerraformHighlightRules;
  323. this.$outdent = new MatchingBraceOutdent();
  324. this.$behaviour = new CstyleBehaviour();
  325. this.foldingRules = new CStyleFoldMode();
  326. };
  327. oop.inherits(Mode, TextMode);
  328. (function () {
  329. this.$id = "ace/mode/terraform";
  330. }).call(Mode.prototype);
  331. exports.Mode = Mode;
  332. }); (function() {
  333. window.ace_require(["ace/mode/terraform"], function(m) {
  334. if (typeof module == "object" && typeof exports == "object" && module) {
  335. module.exports = m;
  336. }
  337. });
  338. })();