-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathturtle.tmLanguage.JSON
100 lines (100 loc) · 3.43 KB
/
turtle.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
// The Turtle syntax is defined here:
// http://www.w3.org/TR/2012/WD-turtle-20120710/
//
// It looks very much like N-Triples with extra literal forms taken
// from SPARQL, so rather than derive this language file from the
// official grammar, I've copied in patterns from sparql.tmLanguage.
// The only exceptions are for things noted explictly here:
// http://www.w3.org/TR/2012/WD-turtle-20120710/#sec-diff-sparql
{
"name": "Turtle",
"uuid": "12fe59d2-8594-4f33-a77c-e05c4d759325",
"scopeName": "source.turtle",
"fileTypes": ["ttl"],
"patterns": [
{
"name": "keyword.turtle",
"comment": "Keywords",
"match": "(?:^|\\s+)(?:@base|@prefix)\\b",
},
{
"name": "string.uri.turtle",
"comment": "URI",
// Best attempt to convert IRI_REF:
// http://www.w3.org/TR/rdf-sparql-query/#rIRI_REF
"match": "<[^<>\"{}|^`\\]\\\\]*>",
},
{
"name": "constant.complex.blank-node.turtle",
"comment": "Blank node",
// Don't bother trying to match the blank node label grammar exactly,
// just highlight anything up to a space
"match": "(_:)([^\\s]+)",
"captures": {
"1": { "name": "constant.language.turtle" },
"2": { "name": "entity.name.class.turtle" }
}
},
{
"name": "constant.complex.turtle",
"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.turtle" },
"2": { "name": "entity.name.class.turtle" }
}
},
{
"name": "entity.name.class.rdfs-type.turtle",
"comment": "The special triple predicate 'a'",
"match": "\\sa\\s"
},
{
"name": "literal.turtle",
"comment": "Typed literal",
// Note duplication of IRI_REF
"match": "(\"[^\"]*\")(\\^\\^)(<[^<>\"{}|^`\\]\\\\]*>|\\w*:[^\\s)]+)",
"captures": {
"1": { "name": "string.turtle" },
"2": { "name": "keyword.operator.turtle" },
"3": { "name": "support.type.turtle" }
}
},
{
"name": "string.turtle",
"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!
//
// I didn't bother with multi-line strings - I think you have to use multi-line
// begin...end captures to do this in Sublime, which is quite a big change from
// the regex I wrote for the SPARQL syntax.
"match": "('''(?:(?:'|'')?(?:[^'\\\\]|\\\\[tbnrf\\\"']))*'''|\"\"\"(?:(?:\"|\"\")?([^\"\\\\]|\\\\[tbnrf\\\"']))*\"\"\"|'(?:(?:[^\\x22\\x5C\\xA\\xD])|\\\\[tbnrf\\\"'])*'|\"(?:(?:[^\\x22\\x5C\\xA\\xD])|\\\\[tbnrf\\\"'])*\"|'''.*'''|'[^']*')(@[a-zA-Z-]+)?",
"captures": {
"1": { "name": "string.turtle" },
"2": { "name": "keyword.operator.turtle" },
"3": { "name": "support.type.turtle" }
}
},
{
"name": "comment.line.number-sign.turtle",
"comment": "Comments",
"match": "#.*$"
},
{
"name": "constant.numeric.turtle",
"comment": "Numeric literal",
"match": "\\b[+-]?(?:\\d+|[0-9]+\\.[0-9]*|\\.[0-9]+(?:[eE][+-]?\\d+)?)\\b"
},
{
"name": "constant.language.turtle",
"comment": "Boolean",
"match": "\\b(?:true|false)\\b"
}
]
}