hcl.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. define('vs/basic-languages/hcl/hcl',["require", "exports"], function (require, exports) {
  6. "use strict";
  7. Object.defineProperty(exports, "__esModule", { value: true });
  8. exports.language = exports.conf = void 0;
  9. exports.conf = {
  10. comments: {
  11. lineComment: '//',
  12. blockComment: ['/*', '*/']
  13. },
  14. brackets: [
  15. ['{', '}'],
  16. ['[', ']'],
  17. ['(', ')']
  18. ],
  19. autoClosingPairs: [
  20. { open: '{', close: '}' },
  21. { open: '[', close: ']' },
  22. { open: '(', close: ')' },
  23. { open: '"', close: '"', notIn: ['string'] }
  24. ],
  25. surroundingPairs: [
  26. { open: '{', close: '}' },
  27. { open: '[', close: ']' },
  28. { open: '(', close: ')' },
  29. { open: '"', close: '"' }
  30. ]
  31. };
  32. exports.language = {
  33. defaultToken: '',
  34. tokenPostfix: '.hcl',
  35. keywords: [
  36. 'var',
  37. 'local',
  38. 'path',
  39. 'for_each',
  40. 'any',
  41. 'string',
  42. 'number',
  43. 'bool',
  44. 'true',
  45. 'false',
  46. 'null',
  47. 'if ',
  48. 'else ',
  49. 'endif ',
  50. 'for ',
  51. 'in',
  52. 'endfor'
  53. ],
  54. operators: [
  55. '=',
  56. '>=',
  57. '<=',
  58. '==',
  59. '!=',
  60. '+',
  61. '-',
  62. '*',
  63. '/',
  64. '%',
  65. '&&',
  66. '||',
  67. '!',
  68. '<',
  69. '>',
  70. '?',
  71. '...',
  72. ':'
  73. ],
  74. symbols: /[=><!~?:&|+\-*\/\^%]+/,
  75. escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  76. 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)/,
  77. terraformMainBlocks: /(module|data|terraform|resource|provider|variable|output|locals)/,
  78. tokenizer: {
  79. root: [
  80. // highlight main blocks
  81. [
  82. /^@terraformMainBlocks([ \t]*)([\w-]+|"[\w-]+"|)([ \t]*)([\w-]+|"[\w-]+"|)([ \t]*)(\{)/,
  83. ['type', '', 'string', '', 'string', '', '@brackets']
  84. ],
  85. // highlight all the remaining blocks
  86. [
  87. /(\w+[ \t]+)([ \t]*)([\w-]+|"[\w-]+"|)([ \t]*)([\w-]+|"[\w-]+"|)([ \t]*)(\{)/,
  88. ['identifier', '', 'string', '', 'string', '', '@brackets']
  89. ],
  90. // highlight block
  91. [
  92. /(\w+[ \t]+)([ \t]*)([\w-]+|"[\w-]+"|)([ \t]*)([\w-]+|"[\w-]+"|)(=)(\{)/,
  93. ['identifier', '', 'string', '', 'operator', '', '@brackets']
  94. ],
  95. // terraform general highlight - shared with expressions
  96. { include: '@terraform' }
  97. ],
  98. terraform: [
  99. // highlight terraform functions
  100. [/@terraformFunctions(\()/, ['type', '@brackets']],
  101. // all other words are variables or keywords
  102. [
  103. /[a-zA-Z_]\w*-*/,
  104. {
  105. cases: {
  106. '@keywords': { token: 'keyword.$0' },
  107. '@default': 'variable'
  108. }
  109. }
  110. ],
  111. { include: '@whitespace' },
  112. { include: '@heredoc' },
  113. // delimiters and operators
  114. [/[{}()\[\]]/, '@brackets'],
  115. [/[<>](?!@symbols)/, '@brackets'],
  116. [
  117. /@symbols/,
  118. {
  119. cases: {
  120. '@operators': 'operator',
  121. '@default': ''
  122. }
  123. }
  124. ],
  125. // numbers
  126. [/\d*\d+[eE]([\-+]?\d+)?/, 'number.float'],
  127. [/\d*\.\d+([eE][\-+]?\d+)?/, 'number.float'],
  128. [/\d[\d']*/, 'number'],
  129. [/\d/, 'number'],
  130. [/[;,.]/, 'delimiter'],
  131. // strings
  132. [/"/, 'string', '@string'],
  133. [/'/, 'invalid']
  134. ],
  135. heredoc: [
  136. [
  137. /<<[-]*\s*["]?([\w\-]+)["]?/,
  138. { token: 'string.heredoc.delimiter', next: '@heredocBody.$1' }
  139. ]
  140. ],
  141. heredocBody: [
  142. [
  143. /([\w\-]+)$/,
  144. {
  145. cases: {
  146. '$1==$S2': [
  147. {
  148. token: 'string.heredoc.delimiter',
  149. next: '@popall'
  150. }
  151. ],
  152. '@default': 'string.heredoc'
  153. }
  154. }
  155. ],
  156. [/./, 'string.heredoc']
  157. ],
  158. whitespace: [
  159. [/[ \t\r\n]+/, ''],
  160. [/\/\*/, 'comment', '@comment'],
  161. [/\/\/.*$/, 'comment'],
  162. [/#.*$/, 'comment']
  163. ],
  164. comment: [
  165. [/[^\/*]+/, 'comment'],
  166. [/\*\//, 'comment', '@pop'],
  167. [/[\/*]/, 'comment']
  168. ],
  169. string: [
  170. [/\$\{/, { token: 'delimiter', next: '@stringExpression' }],
  171. [/[^\\"\$]+/, 'string'],
  172. [/@escapes/, 'string.escape'],
  173. [/\\./, 'string.escape.invalid'],
  174. [/"/, 'string', '@popall']
  175. ],
  176. stringInsideExpression: [
  177. [/[^\\"]+/, 'string'],
  178. [/@escapes/, 'string.escape'],
  179. [/\\./, 'string.escape.invalid'],
  180. [/"/, 'string', '@pop']
  181. ],
  182. stringExpression: [
  183. [/\}/, { token: 'delimiter', next: '@pop' }],
  184. [/"/, 'string', '@stringInsideExpression'],
  185. { include: '@terraform' }
  186. ]
  187. }
  188. };
  189. });