1package t
2
3import (
4	. "github.com/alecthomas/chroma" // nolint
5	"github.com/alecthomas/chroma/lexers/internal"
6)
7
8// Turtle lexer.
9var Turtle = internal.Register(MustNewLexer(
10	&Config{
11		Name:            "Turtle",
12		Aliases:         []string{"turtle"},
13		Filenames:       []string{"*.ttl"},
14		MimeTypes:       []string{"text/turtle", "application/x-turtle"},
15		NotMultiline:    true,
16		CaseInsensitive: true,
17	},
18	Rules{
19		"root": {
20			{`\s+`, TextWhitespace, nil},
21			{"(@base|BASE)(\\s+)(<[^<>\"{}|^`\\\\\\x00-\\x20]*>)(\\s*)(\\.?)", ByGroups(Keyword, TextWhitespace, NameVariable, TextWhitespace, Punctuation), nil},
22			{"(@prefix|PREFIX)(\\s+)((?:[a-z][\\w-]*)?\\:)(\\s+)(<[^<>\"{}|^`\\\\\\x00-\\x20]*>)(\\s*)(\\.?)", ByGroups(Keyword, TextWhitespace, NameNamespace, TextWhitespace, NameVariable, TextWhitespace, Punctuation), nil},
23			{`(?<=\s)a(?=\s)`, KeywordType, nil},
24			{"(<[^<>\"{}|^`\\\\\\x00-\\x20]*>)", NameVariable, nil},
25			{`((?:[a-z][\w-]*)?\:)([a-z][\w-]*)`, ByGroups(NameNamespace, NameTag), nil},
26			{`#[^\n]+`, Comment, nil},
27			{`\b(true|false)\b`, Literal, nil},
28			{`[+\-]?\d*\.\d+`, LiteralNumberFloat, nil},
29			{`[+\-]?\d*(:?\.\d+)?E[+\-]?\d+`, LiteralNumberFloat, nil},
30			{`[+\-]?\d+`, LiteralNumberInteger, nil},
31			{`[\[\](){}.;,:^]`, Punctuation, nil},
32			{`"""`, LiteralString, Push("triple-double-quoted-string")},
33			{`"`, LiteralString, Push("single-double-quoted-string")},
34			{`'''`, LiteralString, Push("triple-single-quoted-string")},
35			{`'`, LiteralString, Push("single-single-quoted-string")},
36		},
37		"triple-double-quoted-string": {
38			{`"""`, LiteralString, Push("end-of-string")},
39			{`[^\\]+`, LiteralString, nil},
40			{`\\`, LiteralString, Push("string-escape")},
41		},
42		"single-double-quoted-string": {
43			{`"`, LiteralString, Push("end-of-string")},
44			{`[^"\\\n]+`, LiteralString, nil},
45			{`\\`, LiteralString, Push("string-escape")},
46		},
47		"triple-single-quoted-string": {
48			{`'''`, LiteralString, Push("end-of-string")},
49			{`[^\\]+`, LiteralString, nil},
50			{`\\`, LiteralString, Push("string-escape")},
51		},
52		"single-single-quoted-string": {
53			{`'`, LiteralString, Push("end-of-string")},
54			{`[^'\\\n]+`, LiteralString, nil},
55			{`\\`, LiteralString, Push("string-escape")},
56		},
57		"string-escape": {
58			{`.`, LiteralString, Pop(1)},
59		},
60		"end-of-string": {
61			{`(@)([a-z]+(:?-[a-z0-9]+)*)`, ByGroups(Operator, GenericEmph, GenericEmph), Pop(2)},
62			{"(\\^\\^)(<[^<>\"{}|^`\\\\\\x00-\\x20]*>)", ByGroups(Operator, GenericEmph), Pop(2)},
63			{`(\^\^)((?:[a-z][\w-]*)?\:)([a-z][\w-]*)`, ByGroups(Operator, GenericEmph, GenericEmph), Pop(2)},
64			Default(Pop(2)),
65		},
66	},
67))
68