1 package s
2
3 import (
4 . "github.com/alecthomas/chroma"
5 "github.com/alecthomas/chroma/lexers/internal"
6 )
7
8
9 var Sparql = internal.Register(MustNewLazyLexer(
10 &Config{
11 Name: "SPARQL",
12 Aliases: []string{"sparql"},
13 Filenames: []string{"*.rq", "*.sparql"},
14 MimeTypes: []string{"application/sparql-query"},
15 },
16 sparqlRules,
17 ))
18
19 func sparqlRules() Rules {
20 return Rules{
21 "root": {
22 {`\s+`, Text, nil},
23 {`((?i)select|construct|describe|ask|where|filter|group\s+by|minus|distinct|reduced|from\s+named|from|order\s+by|desc|asc|limit|offset|bindings|load|clear|drop|create|add|move|copy|insert\s+data|delete\s+data|delete\s+where|delete|insert|using\s+named|using|graph|default|named|all|optional|service|silent|bind|union|not\s+in|in|as|having|to|prefix|base)\b`, Keyword, nil},
24 {`(a)\b`, Keyword, nil},
25 {"(<(?:[^<>\"{}|^`\\\\\\x00-\\x20])*>)", NameLabel, nil},
26 {`(_:[_\p{L}\p{N}](?:[-_.\p{L}\p{N}]*[-_\p{L}\p{N}])?)`, NameLabel, nil},
27 {`[?$][_\p{L}\p{N}]+`, NameVariable, nil},
28 {`([\p{L}][-_.\p{L}\p{N}]*)?(\:)((?:[_:\p{L}\p{N}]|(?:%[0-9A-Fa-f][0-9A-Fa-f])|(?:\\[ _~.\-!$&"()*+,;=/?#@%]))(?:(?:[-_:.\p{L}\p{N}]|(?:%[0-9A-Fa-f][0-9A-Fa-f])|(?:\\[ _~.\-!$&"()*+,;=/?#@%]))*(?:[-_:\p{L}\p{N}]|(?:%[0-9A-Fa-f][0-9A-Fa-f])|(?:\\[ _~.\-!$&"()*+,;=/?#@%])))?)?`, ByGroups(NameNamespace, Punctuation, NameTag), nil},
29 {`((?i)str|lang|langmatches|datatype|bound|iri|uri|bnode|rand|abs|ceil|floor|round|concat|strlen|ucase|lcase|encode_for_uri|contains|strstarts|strends|strbefore|strafter|year|month|day|hours|minutes|seconds|timezone|tz|now|md5|sha1|sha256|sha384|sha512|coalesce|if|strlang|strdt|sameterm|isiri|isuri|isblank|isliteral|isnumeric|regex|substr|replace|exists|not\s+exists|count|sum|min|max|avg|sample|group_concat|separator)\b`, NameFunction, nil},
30 {`(true|false)`, KeywordConstant, nil},
31 {`[+\-]?(\d+\.\d*[eE][+-]?\d+|\.?\d+[eE][+-]?\d+)`, LiteralNumberFloat, nil},
32 {`[+\-]?(\d+\.\d*|\.\d+)`, LiteralNumberFloat, nil},
33 {`[+\-]?\d+`, LiteralNumberInteger, nil},
34 {`(\|\||&&|=|\*|\-|\+|/|!=|<=|>=|!|<|>)`, Operator, nil},
35 {`[(){}.;,:^\[\]]`, Punctuation, nil},
36 {`#[^\n]*`, Comment, nil},
37 {`"""`, LiteralString, Push("triple-double-quoted-string")},
38 {`"`, LiteralString, Push("single-double-quoted-string")},
39 {`'''`, LiteralString, Push("triple-single-quoted-string")},
40 {`'`, LiteralString, Push("single-single-quoted-string")},
41 },
42 "triple-double-quoted-string": {
43 {`"""`, LiteralString, Push("end-of-string")},
44 {`[^\\]+`, LiteralString, nil},
45 {`\\`, LiteralString, Push("string-escape")},
46 },
47 "single-double-quoted-string": {
48 {`"`, LiteralString, Push("end-of-string")},
49 {`[^"\\\n]+`, LiteralString, nil},
50 {`\\`, LiteralString, Push("string-escape")},
51 },
52 "triple-single-quoted-string": {
53 {`'''`, LiteralString, Push("end-of-string")},
54 {`[^\\]+`, LiteralString, nil},
55 {`\\`, LiteralStringEscape, Push("string-escape")},
56 },
57 "single-single-quoted-string": {
58 {`'`, LiteralString, Push("end-of-string")},
59 {`[^'\\\n]+`, LiteralString, nil},
60 {`\\`, LiteralString, Push("string-escape")},
61 },
62 "string-escape": {
63 {`u[0-9A-Fa-f]{4}`, LiteralStringEscape, Pop(1)},
64 {`U[0-9A-Fa-f]{8}`, LiteralStringEscape, Pop(1)},
65 {`.`, LiteralStringEscape, Pop(1)},
66 },
67 "end-of-string": {
68 {`(@)([a-zA-Z]+(?:-[a-zA-Z0-9]+)*)`, ByGroups(Operator, NameFunction), Pop(2)},
69 {`\^\^`, Operator, Pop(2)},
70 Default(Pop(2)),
71 },
72 }
73 }
74
View as plain text