1 package h
2
3 import (
4 . "github.com/alecthomas/chroma"
5 "github.com/alecthomas/chroma/lexers/internal"
6 )
7
8
9 var HCL = internal.Register(MustNewLazyLexer(
10 &Config{
11 Name: "HCL",
12 Aliases: []string{"hcl"},
13 Filenames: []string{"*.hcl"},
14 MimeTypes: []string{"application/x-hcl"},
15 },
16 hclRules,
17 ))
18
19 func hclRules() Rules {
20 return Rules{
21 "root": {
22 Include("string"),
23 Include("punctuation"),
24 Include("curly"),
25 Include("basic"),
26 Include("whitespace"),
27 {`[0-9]+`, LiteralNumber, nil},
28 },
29 "basic": {
30 {Words(`\b`, `\b`, `true`, `false`), KeywordType, nil},
31 {`\s*/\*`, CommentMultiline, Push("comment")},
32 {`\s*#.*\n`, CommentSingle, nil},
33 {`(.*?)(\s*)(=)`, ByGroups(Name, Text, Operator), nil},
34 {`\d+`, Number, nil},
35 {`\b\w+\b`, Keyword, nil},
36 {`\$\{`, LiteralStringInterpol, Push("var_builtin")},
37 },
38 "function": {
39 {`(\s+)(".*")(\s+)`, ByGroups(Text, LiteralString, Text), nil},
40 Include("punctuation"),
41 Include("curly"),
42 },
43 "var_builtin": {
44 {`\$\{`, LiteralStringInterpol, Push()},
45 {Words(`\b`, `\b`, `concat`, `file`, `join`, `lookup`, `element`), NameBuiltin, nil},
46 Include("string"),
47 Include("punctuation"),
48 {`\s+`, Text, nil},
49 {`\}`, LiteralStringInterpol, Pop(1)},
50 },
51 "string": {
52 {`(".*")`, ByGroups(LiteralStringDouble), nil},
53 },
54 "punctuation": {
55 {`[\[\](),.]`, Punctuation, nil},
56 },
57 "curly": {
58 {`\{`, TextPunctuation, nil},
59 {`\}`, TextPunctuation, nil},
60 },
61 "comment": {
62 {`[^*/]`, CommentMultiline, nil},
63 {`/\*`, CommentMultiline, Push()},
64 {`\*/`, CommentMultiline, Pop(1)},
65 {`[*/]`, CommentMultiline, nil},
66 },
67 "whitespace": {
68 {`\n`, Text, nil},
69 {`\s+`, Text, nil},
70 {`\\\n`, Text, nil},
71 },
72 }
73 }
74
View as plain text