prism-hcl.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. Prism.languages.hcl = {
  2. 'comment': /(?:\/\/|#).*|\/\*[\s\S]*?(?:\*\/|$)/,
  3. 'heredoc': {
  4. pattern: /<<-?(\w+\b)[\s\S]*?^[ \t]*\1/m,
  5. greedy: true,
  6. alias: 'string'
  7. },
  8. 'keyword': [
  9. {
  10. pattern: /(?:data|resource)\s+(?:"(?:\\[\s\S]|[^\\"])*")(?=\s+"[\w-]+"\s+\{)/i,
  11. inside: {
  12. 'type': {
  13. pattern: /(resource|data|\s+)(?:"(?:\\[\s\S]|[^\\"])*")/i,
  14. lookbehind: true,
  15. alias: 'variable'
  16. }
  17. }
  18. },
  19. {
  20. pattern: /(?:backend|module|output|provider|provisioner|variable)\s+(?:[\w-]+|"(?:\\[\s\S]|[^\\"])*")\s+(?=\{)/i,
  21. inside: {
  22. 'type': {
  23. pattern: /(backend|module|output|provider|provisioner|variable)\s+(?:[\w-]+|"(?:\\[\s\S]|[^\\"])*")\s+/i,
  24. lookbehind: true,
  25. alias: 'variable'
  26. }
  27. }
  28. },
  29. /[\w-]+(?=\s+\{)/
  30. ],
  31. 'property': [
  32. /[-\w\.]+(?=\s*=(?!=))/,
  33. /"(?:\\[\s\S]|[^\\"])+"(?=\s*[:=])/,
  34. ],
  35. 'string': {
  36. pattern: /"(?:[^\\$"]|\\[\s\S]|\$(?:(?=")|\$+(?!\$)|[^"${])|\$\{(?:[^{}"]|"(?:[^\\"]|\\[\s\S])*")*\})*"/,
  37. greedy: true,
  38. inside: {
  39. 'interpolation': {
  40. pattern: /(^|[^$])\$\{(?:[^{}"]|"(?:[^\\"]|\\[\s\S])*")*\}/,
  41. lookbehind: true,
  42. inside: {
  43. 'type': {
  44. pattern: /(\b(?:count|data|local|module|path|self|terraform|var)\b\.)[\w\*]+/i,
  45. lookbehind: true,
  46. alias: 'variable'
  47. },
  48. 'keyword': /\b(?:count|data|local|module|path|self|terraform|var)\b/i,
  49. 'function': /\w+(?=\()/,
  50. 'string': {
  51. pattern: /"(?:\\[\s\S]|[^\\"])*"/,
  52. greedy: true,
  53. },
  54. 'number': /\b0x[\da-f]+\b|\b\d+(?:\.\d*)?(?:e[+-]?\d+)?/i,
  55. 'punctuation': /[!\$#%&'()*+,.\/;<=>@\[\\\]^`{|}~?:]/,
  56. }
  57. },
  58. }
  59. },
  60. 'number': /\b0x[\da-f]+\b|\b\d+(?:\.\d*)?(?:e[+-]?\d+)?/i,
  61. 'boolean': /\b(?:false|true)\b/i,
  62. 'punctuation': /[=\[\]{}]/,
  63. };