mirror of
https://github.com/alecthomas/chroma.git
synced 2025-03-17 20:58:08 +02:00
See: https://www.freedesktop.org/software/systemd/man/systemd.syntax.html#
This commit is contained in:
parent
e36baa268a
commit
c4123fc163
29
lexers/s/systemd.go
Normal file
29
lexers/s/systemd.go
Normal file
@ -0,0 +1,29 @@
|
||||
package s
|
||||
|
||||
import (
|
||||
. "github.com/alecthomas/chroma" // nolint
|
||||
"github.com/alecthomas/chroma/lexers/internal"
|
||||
)
|
||||
|
||||
var SYSTEMD = internal.Register(MustNewLexer(
|
||||
&Config{
|
||||
Name: "SYSTEMD",
|
||||
Aliases: []string{"systemd"},
|
||||
Filenames: []string{"*.service"},
|
||||
MimeTypes: []string{"text/plain"},
|
||||
},
|
||||
Rules {
|
||||
"root": {
|
||||
{`\s+`, Text, nil},
|
||||
{`[;#].*`, Comment, nil},
|
||||
{`\[.*?\]$`, Keyword, nil},
|
||||
{`(.*?)(=)(.*)(\\\n)`, ByGroups(NameAttribute, Operator, LiteralString, Text), Push("continuation")},
|
||||
{`(.*?)(=)(.*)`, ByGroups(NameAttribute, Operator, LiteralString), nil},
|
||||
},
|
||||
"continuation": {
|
||||
{`(.*?)(\\\n)`, ByGroups(LiteralString, Text), nil},
|
||||
{`(.*)`, LiteralString, Pop(1)},
|
||||
},
|
||||
},
|
||||
))
|
||||
|
11
lexers/testdata/systemd.actual
vendored
Normal file
11
lexers/testdata/systemd.actual
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
[Section A]
|
||||
KeyOne=value 1
|
||||
KeyTwo=value 2
|
||||
|
||||
# a comment
|
||||
|
||||
[Section B]
|
||||
Setting="something" "some thing" "…"
|
||||
KeyTwo=value 2 \
|
||||
value 2 continued
|
||||
|
26
lexers/testdata/systemd.expected
vendored
Normal file
26
lexers/testdata/systemd.expected
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
[
|
||||
{"type":"Keyword","value":"[Section A]"},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"NameAttribute","value":"KeyOne"},
|
||||
{"type":"Operator","value":"="},
|
||||
{"type":"LiteralString","value":"value 1"},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"NameAttribute","value":"KeyTwo"},
|
||||
{"type":"Operator","value":"="},
|
||||
{"type":"LiteralString","value":"value 2"},
|
||||
{"type":"Text","value":"\n\n"},
|
||||
{"type":"Comment","value":"# a comment"},
|
||||
{"type":"Text","value":"\n\n"},
|
||||
{"type":"Keyword","value":"[Section B]"},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"NameAttribute","value":"Setting"},
|
||||
{"type":"Operator","value":"="},
|
||||
{"type":"LiteralString","value":"\"something\" \"some thing\" \"…\""},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"NameAttribute","value":"KeyTwo"},
|
||||
{"type":"Operator","value":"="},
|
||||
{"type":"LiteralString","value":"value 2 "},
|
||||
{"type":"Text","value":"\\\n"},
|
||||
{"type":"LiteralString","value":" value 2 continued"},
|
||||
{"type":"Text","value":"\n\n"}
|
||||
]
|
Loading…
x
Reference in New Issue
Block a user