1package g
2
3import (
4	. "github.com/alecthomas/chroma" // nolint
5	"github.com/alecthomas/chroma/lexers/internal"
6)
7
8// Groff lexer.
9var Groff = internal.Register(MustNewLazyLexer(
10	&Config{
11		Name:      "Groff",
12		Aliases:   []string{"groff", "nroff", "man"},
13		Filenames: []string{"*.[1-9]", "*.1p", "*.3pm", "*.man"},
14		MimeTypes: []string{"application/x-troff", "text/troff"},
15	},
16	func() Rules {
17		return Rules{
18			"root": {
19				{`(\.)(\w+)`, ByGroups(Text, Keyword), Push("request")},
20				{`\.`, Punctuation, Push("request")},
21				{`[^\\\n]+`, Text, Push("textline")},
22				Default(Push("textline")),
23			},
24			"textline": {
25				Include("escapes"),
26				{`[^\\\n]+`, Text, nil},
27				{`\n`, Text, Pop(1)},
28			},
29			"escapes": {
30				{`\\"[^\n]*`, Comment, nil},
31				{`\\[fn]\w`, LiteralStringEscape, nil},
32				{`\\\(.{2}`, LiteralStringEscape, nil},
33				{`\\.\[.*\]`, LiteralStringEscape, nil},
34				{`\\.`, LiteralStringEscape, nil},
35				{`\\\n`, Text, Push("request")},
36			},
37			"request": {
38				{`\n`, Text, Pop(1)},
39				Include("escapes"),
40				{`"[^\n"]+"`, LiteralStringDouble, nil},
41				{`\d+`, LiteralNumber, nil},
42				{`\S+`, LiteralString, nil},
43				{`\s+`, Text, nil},
44			},
45		}
46	},
47))
48