-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsparql.tmLanguage.JSON
108 lines (108 loc) · 4.17 KB
/
sparql.tmLanguage.JSON
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// I found an ANTLR grammar for SPARQL so I've been through that once but I
// didn't try to catch every last case. The file test.rq explains some of
// the scenarios.
// http://www.antlr3.org/grammar/1200929755392/Sparql.g
//
// Also I made a bit of an aesthetic distinction between keywords and functions
// in some cases. Hopefully it's a good balance between distinguisability and
// conformance to the offical syntax but I'm open to alterations.
{
"name": "SPARQL",
"uuid": "5a91f9b9-c324-40e6-8bd2-ed959b3adda9",
"scopeName": "source.sparql",
"fileTypes": ["rq"],
"patterns": [
{
"name": "keyword.sparql",
"comment": "Keywords",
"match": "\\b(?i:base|prefix|select|distinct|reduced|from|named|construct|ask|describe|where|graph|bind|as|filter|optional|union|order|by|limit|offset|values|insert data|delete data|with|delete|insert|clear|silent|default|all|create|drop|copy|move|add|to|using|service|not exists|exists|not in|in|minus)\\b",
},
{
"name": "support.function.sparql",
"comment": "SPARQL built-in functions",
// I included `separator` here, which is a keyword argument to `group_concat`
"match": "\\b(?i:concat|regex|asc|desc|bound|isiri|isuri|isblank|isliteral|str|lang|datatype|sameterm|langmatches|avg|count|group_concat|separator|max|min|sample|sum|iri|bnode|strdt|uuid|struuid|strlen|strlen|strlen|substr|ucase|lcase|strstarts|strends|contains|strbefore|strafter|encode_for_uri|replace|abs|round|ceil|floor|rand|now|year|month|day|hours|minutes|seconds|timezone|tz|md5|sha1|sha256|sha384|sha512|coalesce|if|)\\b"
},
{
"name": "string.uri.sparql",
"comment": "URI",
// Best attempt to convert IRI_REF:
// http://www.w3.org/TR/rdf-sparql-query/#rIRI_REF
"match": "<[^<>\"{}|^`\\]\\\\]*>",
},
{
"name": "constant.complex.sparql",
"comment": "Prefix / prefixed URI",
// PN_CHARS_BASE is insane
// http://www.w3.org/TR/rdf-sparql-query/#rPN_CHARS_BASE
"match": "(\\w*:)([^\\s|/^*?+{}()]*)",
"captures": {
"1": { "name": "constant.other.sparql" },
"2": { "name": "entity.name.class.sparql" }
}
},
{
"name": "entity.name.class.rdfs-type.sparql",
"comment": "The special triple predicate 'a'",
"match": "\\sa\\s"
},
{
"name": "variable.other.sparql",
"match": "(?<!\\w)[?$]\\w+"
},
{
"name": "literal.sparql",
"comment": "Typed literal",
// Note duplication of IRI_REF
"match": "(\"[^\"]*\")(\\^\\^)(<[^<>\"{}|^`\\]\\\\]*>|\\w*:[^\\s)]+)",
"captures": {
"1": { "name": "string.sparql" },
"2": { "name": "keyword.operator.sparql" },
"3": { "name": "support.type.sparql" }
}
},
{
"name": "string.sparql",
"comment": "String literal",
// This is an attempt to implement the following BNF combinations:
// STRING_LITERAL_LONG1 | STRING_LITERAL_LONG2 | STRING_LITERAL1 | STRING_LITERAL2
// Creating an incorrectly highlighted example of a triple-quoted string
// turned out to be really hard, so I can't promise the first two options
// are correct!
"match": "('''(?:(?:'|'')?(?:[^'\\\\]|\\\\[tbnrf\\\"']))*'''|\"\"\"(?:(?:\"|\"\")?([^\"\\\\]|\\\\[tbnrf\\\"']))*\"\"\"|'(?:(?:[^\\x22\\x5C\\xA\\xD])|\\\\[tbnrf\\\"'])*'|\"(?:(?:[^\\x22\\x5C\\xA\\xD])|\\\\[tbnrf\\\"'])*\"|'''.*'''|'[^']*')(@[a-zA-Z-]+)?",
"captures": {
"1": { "name": "string.sparql" },
"2": { "name": "keyword.operator.sparql" },
"3": { "name": "support.type.sparql" }
}
},
{
"name": "keyword.operator.range.complex.sparql",
"match": "\\{\\s*(\\d+)?(\\s*(?:,\\s*(\\d+)?)?)+\\s*\\}",
"captures": {
"1": { "name": "constant.numeric.sparql" },
"3": { "name": "constant.numeric.sparql" }
}
},
{
"name": "constant.numeric.sparql",
"comment": "Numeric literal",
"match": "\\b[+-]?(?:\\d+|[0-9]+\\.[0-9]*|\\.[0-9]+(?:[eE][+-]?\\d+)?)\\b"
},
{
"name": "constant.language.sparql",
"comment": "Boolean",
"match": "\\b(?i:true|false)\\b"
},
{
"name": "keyword.operator.sparql",
"comment": "SPARQL operators",
"match": "(?:\\|\\||&&|=|!=|<|>|<=|>=|\\*|/|\\+|-|\\||\\^|\\?|\\!)"
},
{
"name": "comment.line.number-sign.sparql",
"comment": "Comments",
"match": "#.*$"
}
]
}