hcl.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*!-----------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Version: 0.31.1(337587859b1c171314b40503171188b6cea6a32a)
  4. * Released under the MIT license
  5. * https://github.com/microsoft/monaco-editor/blob/main/LICENSE.txt
  6. *-----------------------------------------------------------------------------*/
  7. // src/basic-languages/hcl/hcl.ts
  8. var conf = {
  9. comments: {
  10. lineComment: "#",
  11. blockComment: ["/*", "*/"]
  12. },
  13. brackets: [
  14. ["{", "}"],
  15. ["[", "]"],
  16. ["(", ")"]
  17. ],
  18. autoClosingPairs: [
  19. { open: "{", close: "}" },
  20. { open: "[", close: "]" },
  21. { open: "(", close: ")" },
  22. { open: '"', close: '"', notIn: ["string"] }
  23. ],
  24. surroundingPairs: [
  25. { open: "{", close: "}" },
  26. { open: "[", close: "]" },
  27. { open: "(", close: ")" },
  28. { open: '"', close: '"' }
  29. ]
  30. };
  31. var language = {
  32. defaultToken: "",
  33. tokenPostfix: ".hcl",
  34. keywords: [
  35. "var",
  36. "local",
  37. "path",
  38. "for_each",
  39. "any",
  40. "string",
  41. "number",
  42. "bool",
  43. "true",
  44. "false",
  45. "null",
  46. "if ",
  47. "else ",
  48. "endif ",
  49. "for ",
  50. "in",
  51. "endfor"
  52. ],
  53. operators: [
  54. "=",
  55. ">=",
  56. "<=",
  57. "==",
  58. "!=",
  59. "+",
  60. "-",
  61. "*",
  62. "/",
  63. "%",
  64. "&&",
  65. "||",
  66. "!",
  67. "<",
  68. ">",
  69. "?",
  70. "...",
  71. ":"
  72. ],
  73. symbols: /[=><!~?:&|+\-*\/\^%]+/,
  74. escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  75. terraformFunctions: /(abs|ceil|floor|log|max|min|pow|signum|chomp|format|formatlist|indent|join|lower|regex|regexall|replace|split|strrev|substr|title|trimspace|upper|chunklist|coalesce|coalescelist|compact|concat|contains|distinct|element|flatten|index|keys|length|list|lookup|map|matchkeys|merge|range|reverse|setintersection|setproduct|setunion|slice|sort|transpose|values|zipmap|base64decode|base64encode|base64gzip|csvdecode|jsondecode|jsonencode|urlencode|yamldecode|yamlencode|abspath|dirname|pathexpand|basename|file|fileexists|fileset|filebase64|templatefile|formatdate|timeadd|timestamp|base64sha256|base64sha512|bcrypt|filebase64sha256|filebase64sha512|filemd5|filemd1|filesha256|filesha512|md5|rsadecrypt|sha1|sha256|sha512|uuid|uuidv5|cidrhost|cidrnetmask|cidrsubnet|tobool|tolist|tomap|tonumber|toset|tostring)/,
  76. terraformMainBlocks: /(module|data|terraform|resource|provider|variable|output|locals)/,
  77. tokenizer: {
  78. root: [
  79. [
  80. /^@terraformMainBlocks([ \t]*)([\w-]+|"[\w-]+"|)([ \t]*)([\w-]+|"[\w-]+"|)([ \t]*)(\{)/,
  81. ["type", "", "string", "", "string", "", "@brackets"]
  82. ],
  83. [
  84. /(\w+[ \t]+)([ \t]*)([\w-]+|"[\w-]+"|)([ \t]*)([\w-]+|"[\w-]+"|)([ \t]*)(\{)/,
  85. ["identifier", "", "string", "", "string", "", "@brackets"]
  86. ],
  87. [
  88. /(\w+[ \t]+)([ \t]*)([\w-]+|"[\w-]+"|)([ \t]*)([\w-]+|"[\w-]+"|)(=)(\{)/,
  89. ["identifier", "", "string", "", "operator", "", "@brackets"]
  90. ],
  91. { include: "@terraform" }
  92. ],
  93. terraform: [
  94. [/@terraformFunctions(\()/, ["type", "@brackets"]],
  95. [
  96. /[a-zA-Z_]\w*-*/,
  97. {
  98. cases: {
  99. "@keywords": { token: "keyword.$0" },
  100. "@default": "variable"
  101. }
  102. }
  103. ],
  104. { include: "@whitespace" },
  105. { include: "@heredoc" },
  106. [/[{}()\[\]]/, "@brackets"],
  107. [/[<>](?!@symbols)/, "@brackets"],
  108. [
  109. /@symbols/,
  110. {
  111. cases: {
  112. "@operators": "operator",
  113. "@default": ""
  114. }
  115. }
  116. ],
  117. [/\d*\d+[eE]([\-+]?\d+)?/, "number.float"],
  118. [/\d*\.\d+([eE][\-+]?\d+)?/, "number.float"],
  119. [/\d[\d']*/, "number"],
  120. [/\d/, "number"],
  121. [/[;,.]/, "delimiter"],
  122. [/"/, "string", "@string"],
  123. [/'/, "invalid"]
  124. ],
  125. heredoc: [
  126. [/<<[-]*\s*["]?([\w\-]+)["]?/, { token: "string.heredoc.delimiter", next: "@heredocBody.$1" }]
  127. ],
  128. heredocBody: [
  129. [
  130. /([\w\-]+)$/,
  131. {
  132. cases: {
  133. "$1==$S2": [
  134. {
  135. token: "string.heredoc.delimiter",
  136. next: "@popall"
  137. }
  138. ],
  139. "@default": "string.heredoc"
  140. }
  141. }
  142. ],
  143. [/./, "string.heredoc"]
  144. ],
  145. whitespace: [
  146. [/[ \t\r\n]+/, ""],
  147. [/\/\*/, "comment", "@comment"],
  148. [/\/\/.*$/, "comment"],
  149. [/#.*$/, "comment"]
  150. ],
  151. comment: [
  152. [/[^\/*]+/, "comment"],
  153. [/\*\//, "comment", "@pop"],
  154. [/[\/*]/, "comment"]
  155. ],
  156. string: [
  157. [/\$\{/, { token: "delimiter", next: "@stringExpression" }],
  158. [/[^\\"\$]+/, "string"],
  159. [/@escapes/, "string.escape"],
  160. [/\\./, "string.escape.invalid"],
  161. [/"/, "string", "@popall"]
  162. ],
  163. stringInsideExpression: [
  164. [/[^\\"]+/, "string"],
  165. [/@escapes/, "string.escape"],
  166. [/\\./, "string.escape.invalid"],
  167. [/"/, "string", "@pop"]
  168. ],
  169. stringExpression: [
  170. [/\}/, { token: "delimiter", next: "@pop" }],
  171. [/"/, "string", "@stringInsideExpression"],
  172. { include: "@terraform" }
  173. ]
  174. }
  175. };
  176. export {
  177. conf,
  178. language
  179. };