1 package c
2
3 import (
4 . "github.com/alecthomas/chroma"
5 "github.com/alecthomas/chroma/lexers/internal"
6 )
7
8
9 var Cfengine3 = internal.Register(MustNewLazyLexer(
10 &Config{
11 Name: "CFEngine3",
12 Aliases: []string{"cfengine3", "cf3"},
13 Filenames: []string{"*.cf"},
14 MimeTypes: []string{},
15 },
16 cfengine3Rules,
17 ))
18
19 func cfengine3Rules() Rules {
20 return Rules{
21 "root": {
22 {`#.*?\n`, Comment, nil},
23 {`(body)(\s+)(\S+)(\s+)(control)`, ByGroups(Keyword, Text, Keyword, Text, Keyword), nil},
24 {`(body|bundle)(\s+)(\S+)(\s+)(\w+)(\()`, ByGroups(Keyword, Text, Keyword, Text, NameFunction, Punctuation), Push("arglist")},
25 {`(body|bundle)(\s+)(\S+)(\s+)(\w+)`, ByGroups(Keyword, Text, Keyword, Text, NameFunction), nil},
26 {`(")([^"]+)(")(\s+)(string|slist|int|real)(\s*)(=>)(\s*)`, ByGroups(Punctuation, NameVariable, Punctuation, Text, KeywordType, Text, Operator, Text), nil},
27 {`(\S+)(\s*)(=>)(\s*)`, ByGroups(KeywordReserved, Text, Operator, Text), nil},
28 {`"`, LiteralString, Push("string")},
29 {`(\w+)(\()`, ByGroups(NameFunction, Punctuation), nil},
30 {`([\w.!&|()]+)(::)`, ByGroups(NameClass, Punctuation), nil},
31 {`(\w+)(:)`, ByGroups(KeywordDeclaration, Punctuation), nil},
32 {`@[{(][^)}]+[})]`, NameVariable, nil},
33 {`[(){},;]`, Punctuation, nil},
34 {`=>`, Operator, nil},
35 {`->`, Operator, nil},
36 {`\d+\.\d+`, LiteralNumberFloat, nil},
37 {`\d+`, LiteralNumberInteger, nil},
38 {`\w+`, NameFunction, nil},
39 {`\s+`, Text, nil},
40 },
41 "string": {
42 {`\$[{(]`, LiteralStringInterpol, Push("interpol")},
43 {`\\.`, LiteralStringEscape, nil},
44 {`"`, LiteralString, Pop(1)},
45 {`\n`, LiteralString, nil},
46 {`.`, LiteralString, nil},
47 },
48 "interpol": {
49 {`\$[{(]`, LiteralStringInterpol, Push()},
50 {`[})]`, LiteralStringInterpol, Pop(1)},
51 {`[^${()}]+`, LiteralStringInterpol, nil},
52 },
53 "arglist": {
54 {`\)`, Punctuation, Pop(1)},
55 {`,`, Punctuation, nil},
56 {`\w+`, NameVariable, nil},
57 {`\s+`, Text, nil},
58 },
59 }
60 }
61
View as plain text