PageRenderTime 57ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/lexers/t/terraform.go

https://github.com/alecthomas/chroma
Go | 60 lines | 57 code | 2 blank | 1 comment | 0 complexity | 5ea3672147ab95c143f845324f7e9e29 MD5 | raw file
  1. package t
  2. import (
  3. . "github.com/alecthomas/chroma" // nolint
  4. "github.com/alecthomas/chroma/lexers/internal"
  5. )
  6. // Terraform lexer.
  7. var Terraform = internal.Register(MustNewLexer(
  8. &Config{
  9. Name: "Terraform",
  10. Aliases: []string{"terraform", "tf"},
  11. Filenames: []string{"*.tf"},
  12. MimeTypes: []string{"application/x-tf", "application/x-terraform"},
  13. },
  14. Rules{
  15. "root": {
  16. {`[\[\](),.{}]`, Punctuation, nil},
  17. {`-?[0-9]+`, LiteralNumber, nil},
  18. {`=>`, Punctuation, nil},
  19. {Words(``, `\b`, `true`, `false`), KeywordConstant, nil},
  20. {`/(?s)\*(((?!\*/).)*)\*/`, CommentMultiline, nil},
  21. {`\s*(#|//).*\n`, CommentSingle, nil},
  22. {`([a-zA-Z]\w*)(\s*)(=(?!>))`, ByGroups(NameAttribute, Text, Text), nil},
  23. {Words(`^\s*`, `\b`, `variable`, `data`, `resource`, `provider`, `provisioner`, `module`, `output`), KeywordReserved, nil},
  24. {Words(``, `\b`, `for`, `in`), Keyword, nil},
  25. {Words(``, ``, `count`, `data`, `var`, `module`, `each`), NameBuiltin, nil},
  26. {Words(``, `\b`, `abs`, `ceil`, `floor`, `log`, `max`, `min`, `parseint`, `pow`, `signum`), NameBuiltin, nil},
  27. {Words(``, `\b`, `chomp`, `format`, `formatlist`, `indent`, `join`, `lower`, `regex`, `regexall`, `replace`, `split`, `strrev`, `substr`, `title`, `trim`, `trimprefix`, `trimsuffix`, `trimspace`, `upper`), NameBuiltin, nil},
  28. {Words(`[^.]`, `\b`, `chunklist`, `coalesce`, `coalescelist`, `compact`, `concat`, `contains`, `distinct`, `element`, `flatten`, `index`, `keys`, `length`, `list`, `lookup`, `map`, `matchkeys`, `merge`, `range`, `reverse`, `setintersection`, `setproduct`, `setsubtract`, `setunion`, `slice`, `sort`, `transpose`, `values`, `zipmap`), NameBuiltin, nil},
  29. {Words(`[^.]`, `\b`, `base64decode`, `base64encode`, `base64gzip`, `csvdecode`, `jsondecode`, `jsonencode`, `urlencode`, `yamldecode`, `yamlencode`), NameBuiltin, nil},
  30. {Words(``, `\b`, `abspath`, `dirname`, `pathexpand`, `basename`, `file`, `fileexists`, `fileset`, `filebase64`, `templatefile`), NameBuiltin, nil},
  31. {Words(``, `\b`, `formatdate`, `timeadd`, `timestamp`), NameBuiltin, nil},
  32. {Words(``, `\b`, `base64sha256`, `base64sha512`, `bcrypt`, `filebase64sha256`, `filebase64sha512`, `filemd5`, `filesha1`, `filesha256`, `filesha512`, `md5`, `rsadecrypt`, `sha1`, `sha256`, `sha512`, `uuid`, `uuidv5`), NameBuiltin, nil},
  33. {Words(``, `\b`, `cidrhost`, `cidrnetmask`, `cidrsubnet`), NameBuiltin, nil},
  34. {Words(``, `\b`, `can`, `tobool`, `tolist`, `tomap`, `tonumber`, `toset`, `tostring`, `try`), NameBuiltin, nil},
  35. {`=(?!>)|\+|-|\*|\/|:|!|%|>|<(?!<)|>=|<=|==|!=|&&|\||\?`, Operator, nil},
  36. {`\n|\s+|\\\n`, Text, nil},
  37. {`[a-zA-Z]\w*`, NameOther, nil},
  38. {`"`, LiteralStringDouble, Push("string")},
  39. {`(?s)(<<-?)(\w+)(\n\s*(?:(?!\2).)*\s*\n\s*)(\2)`, ByGroups(Operator, Operator, String, Operator), nil},
  40. },
  41. "declaration": {
  42. {`(\s*)("(?:\\\\|\\"|[^"])*")(\s*)`, ByGroups(Text, NameVariable, Text), nil},
  43. {`\{`, Punctuation, Pop(1)},
  44. },
  45. "string": {
  46. {`"`, LiteralStringDouble, Pop(1)},
  47. {`\\\\`, LiteralStringDouble, nil},
  48. {`\\\\"`, LiteralStringDouble, nil},
  49. {`\$\{`, LiteralStringInterpol, Push("interp-inside")},
  50. {`\$`, LiteralStringDouble, nil},
  51. {`[^"\\\\$]+`, LiteralStringDouble, nil},
  52. },
  53. "interp-inside": {
  54. {`\}`, LiteralStringInterpol, Pop(1)},
  55. Include("root"),
  56. },
  57. },
  58. ))