1 package p
2
3 import (
4 . "github.com/alecthomas/chroma"
5 "github.com/alecthomas/chroma/lexers/internal"
6 )
7
8
9 var Puppet = internal.Register(MustNewLazyLexer(
10 &Config{
11 Name: "Puppet",
12 Aliases: []string{"puppet"},
13 Filenames: []string{"*.pp"},
14 MimeTypes: []string{},
15 },
16 puppetRules,
17 ))
18
19 func puppetRules() Rules {
20 return Rules{
21 "root": {
22 Include("comments"),
23 Include("keywords"),
24 Include("names"),
25 Include("numbers"),
26 Include("operators"),
27 Include("strings"),
28 {`[]{}:(),;[]`, Punctuation, nil},
29 {`[^\S\n]+`, Text, nil},
30 },
31 "comments": {
32 {`\s*#.*$`, Comment, nil},
33 {`/(\\\n)?[*](.|\n)*?[*](\\\n)?/`, CommentMultiline, nil},
34 },
35 "operators": {
36 {`(=>|\?|<|>|=|\+|-|/|\*|~|!|\|)`, Operator, nil},
37 {`(in|and|or|not)\b`, OperatorWord, nil},
38 },
39 "names": {
40 {`[a-zA-Z_]\w*`, NameAttribute, nil},
41 {`(\$\S+)(\[)(\S+)(\])`, ByGroups(NameVariable, Punctuation, LiteralString, Punctuation), nil},
42 {`\$\S+`, NameVariable, nil},
43 },
44 "numbers": {
45 {`(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?j?`, LiteralNumberFloat, nil},
46 {`\d+[eE][+-]?[0-9]+j?`, LiteralNumberFloat, nil},
47 {`0[0-7]+j?`, LiteralNumberOct, nil},
48 {`0[xX][a-fA-F0-9]+`, LiteralNumberHex, nil},
49 {`\d+L`, LiteralNumberIntegerLong, nil},
50 {`\d+j?`, LiteralNumberInteger, nil},
51 },
52 "keywords": {
53 {Words(`(?i)`, `\b`, `absent`, `alert`, `alias`, `audit`, `augeas`, `before`, `case`, `check`, `class`, `computer`, `configured`, `contained`, `create_resources`, `crit`, `cron`, `debug`, `default`, `define`, `defined`, `directory`, `else`, `elsif`, `emerg`, `err`, `exec`, `extlookup`, `fail`, `false`, `file`, `filebucket`, `fqdn_rand`, `generate`, `host`, `if`, `import`, `include`, `info`, `inherits`, `inline_template`, `installed`, `interface`, `k5login`, `latest`, `link`, `loglevel`, `macauthorization`, `mailalias`, `maillist`, `mcx`, `md5`, `mount`, `mounted`, `nagios_command`, `nagios_contact`, `nagios_contactgroup`, `nagios_host`, `nagios_hostdependency`, `nagios_hostescalation`, `nagios_hostextinfo`, `nagios_hostgroup`, `nagios_service`, `nagios_servicedependency`, `nagios_serviceescalation`, `nagios_serviceextinfo`, `nagios_servicegroup`, `nagios_timeperiod`, `node`, `noop`, `notice`, `notify`, `package`, `present`, `purged`, `realize`, `regsubst`, `resources`, `role`, `router`, `running`, `schedule`, `scheduled_task`, `search`, `selboolean`, `selmodule`, `service`, `sha1`, `shellquote`, `split`, `sprintf`, `ssh_authorized_key`, `sshkey`, `stage`, `stopped`, `subscribe`, `tag`, `tagged`, `template`, `tidy`, `true`, `undef`, `unmounted`, `user`, `versioncmp`, `vlan`, `warning`, `yumrepo`, `zfs`, `zone`, `zpool`), Keyword, nil},
54 },
55 "strings": {
56 {`"([^"])*"`, LiteralString, nil},
57 {`'(\\'|[^'])*'`, LiteralString, nil},
58 },
59 }
60 }
61
View as plain text