1 package t
2
3 import (
4 . "github.com/alecthomas/chroma"
5 "github.com/alecthomas/chroma/lexers/internal"
6 )
7
8
9 var Turtle = internal.Register(MustNewLazyLexer(
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 turtleRules,
19 ))
20
21 func turtleRules() Rules {
22 return Rules{
23 "root": {
24 {`\s+`, TextWhitespace, nil},
25 {"(@base|BASE)(\\s+)(<[^<>\"{}|^`\\\\\\x00-\\x20]*>)(\\s*)(\\.?)", ByGroups(Keyword, TextWhitespace, NameVariable, TextWhitespace, Punctuation), nil},
26 {"(@prefix|PREFIX)(\\s+)((?:[a-z][\\w-]*)?\\:)(\\s+)(<[^<>\"{}|^`\\\\\\x00-\\x20]*>)(\\s*)(\\.?)", ByGroups(Keyword, TextWhitespace, NameNamespace, TextWhitespace, NameVariable, TextWhitespace, Punctuation), nil},
27 {`(?<=\s)a(?=\s)`, KeywordType, nil},
28 {"(<[^<>\"{}|^`\\\\\\x00-\\x20]*>)", NameVariable, nil},
29 {`((?:[a-z][\w-]*)?\:)([a-z][\w-]*)`, ByGroups(NameNamespace, NameTag), nil},
30 {`#[^\n]+`, Comment, nil},
31 {`\b(true|false)\b`, Literal, nil},
32 {`[+\-]?\d*\.\d+`, LiteralNumberFloat, nil},
33 {`[+\-]?\d*(:?\.\d+)?E[+\-]?\d+`, LiteralNumberFloat, nil},
34 {`[+\-]?\d+`, LiteralNumberInteger, nil},
35 {`[\[\](){}.;,:^]`, Punctuation, nil},
36 {`"""`, LiteralString, Push("triple-double-quoted-string")},
37 {`"`, LiteralString, Push("single-double-quoted-string")},
38 {`'''`, LiteralString, Push("triple-single-quoted-string")},
39 {`'`, LiteralString, Push("single-single-quoted-string")},
40 },
41 "triple-double-quoted-string": {
42 {`"""`, LiteralString, Push("end-of-string")},
43 {`[^\\]+`, LiteralString, nil},
44 {`\\`, LiteralString, Push("string-escape")},
45 },
46 "single-double-quoted-string": {
47 {`"`, LiteralString, Push("end-of-string")},
48 {`[^"\\\n]+`, LiteralString, nil},
49 {`\\`, LiteralString, Push("string-escape")},
50 },
51 "triple-single-quoted-string": {
52 {`'''`, LiteralString, Push("end-of-string")},
53 {`[^\\]+`, LiteralString, nil},
54 {`\\`, LiteralString, Push("string-escape")},
55 },
56 "single-single-quoted-string": {
57 {`'`, LiteralString, Push("end-of-string")},
58 {`[^'\\\n]+`, LiteralString, nil},
59 {`\\`, LiteralString, Push("string-escape")},
60 },
61 "string-escape": {
62 {`.`, LiteralString, Pop(1)},
63 },
64 "end-of-string": {
65 {`(@)([a-z]+(:?-[a-z0-9]+)*)`, ByGroups(Operator, GenericEmph, GenericEmph), Pop(2)},
66 {"(\\^\\^)(<[^<>\"{}|^`\\\\\\x00-\\x20]*>)", ByGroups(Operator, GenericEmph), Pop(2)},
67 {`(\^\^)((?:[a-z][\w-]*)?\:)([a-z][\w-]*)`, ByGroups(Operator, GenericEmph, GenericEmph), Pop(2)},
68 Default(Pop(2)),
69 },
70 }
71 }
72
View as plain text