1package t
2
3import (
4 . "github.com/alecthomas/chroma" // nolint
5 "github.com/alecthomas/chroma/lexers/internal"
6)
7
8// Terraform lexer.
9var Terraform = internal.Register(MustNewLexer(
10 &Config{
11 Name: "Terraform",
12 Aliases: []string{"terraform", "tf"},
13 Filenames: []string{"*.tf"},
14 MimeTypes: []string{"application/x-tf", "application/x-terraform"},
15 },
16 Rules{
17 "root": {
18 Include("string"),
19 Include("punctuation"),
20 Include("curly"),
21 Include("basic"),
22 Include("whitespace"),
23 {`[0-9]+`, LiteralNumber, nil},
24 },
25 "basic": {
26 {Words(`\b`, `\b`, `true`, `false`), KeywordType, nil},
27 {`\s*/\*`, CommentMultiline, Push("comment")},
28 {`\s*#.*\n`, CommentSingle, nil},
29 {`(.*?)(\s*)(=)`, ByGroups(NameAttribute, Text, Operator), nil},
30 {Words(`\b`, `\b`, `variable`, `resource`, `provider`, `provisioner`, `module`), KeywordReserved, Push("function")},
31 {Words(`\b`, `\b`, `ingress`, `egress`, `listener`, `default`, `connection`, `alias`), KeywordDeclaration, nil},
32 {`\$\{`, LiteralStringInterpol, Push("var_builtin")},
33 },
34 "function": {
35 {`(\s+)(".*")(\s+)`, ByGroups(Text, LiteralString, Text), nil},
36 Include("punctuation"),
37 Include("curly"),
38 },
39 "var_builtin": {
40 {`\$\{`, LiteralStringInterpol, Push()},
41 {Words(`\b`, `\b`, `concat`, `file`, `join`, `lookup`, `element`), NameBuiltin, nil},
42 Include("string"),
43 Include("punctuation"),
44 {`\s+`, Text, nil},
45 {`\}`, LiteralStringInterpol, Pop(1)},
46 },
47 "string": {
48 {`(".*")`, ByGroups(LiteralStringDouble), nil},
49 },
50 "punctuation": {
51 {`[\[\](),.]`, Punctuation, nil},
52 },
53 "curly": {
54 {`\{`, TextPunctuation, nil},
55 {`\}`, TextPunctuation, nil},
56 },
57 "comment": {
58 {`[^*/]`, CommentMultiline, nil},
59 {`/\*`, CommentMultiline, Push()},
60 {`\*/`, CommentMultiline, Pop(1)},
61 {`[*/]`, CommentMultiline, nil},
62 },
63 "whitespace": {
64 {`\n`, Text, nil},
65 {`\s+`, Text, nil},
66 {`\\\n`, Text, nil},
67 },
68 },
69))