Skip to content

Commit 9caacec

Browse files
authored
[sparql mode] Improve parsing of IRI atoms
* Do not treat the opening '<' of an expanded IRI atom as an operator The existing code would not highlight the IRI atom "<foo#bar>" in the following line as an atom. FILTER( ?x = "42"^^<foo#bar> ) for example everything after the # would be highlighted as a comment. This is because the sequence "^^<" while all "operator characters", are not all SPARQL operators in this case: the "<" introduces the IRI atom. I special-case the "^^". * Improve PN_LOCAL parsing to SPARQL 1.1 The following legal sequences of characters from SPARQL 1.1 are additionally parsed as being the right-hand-side of a prefixed IRI. 1) Colons 2) PERCENT escaping 3) PN_LOCAL_ESCAPE escaping
1 parent 55d0333 commit 9caacec

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

mode/sparql/sparql.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,18 @@ CodeMirror.defineMode("sparql", function(config) {
6060
stream.skipToEnd();
6161
return "comment";
6262
}
63+
else if (ch === "^") {
64+
ch = stream.peek();
65+
if (ch === "^") stream.eat("^");
66+
else stream.eatWhile(operatorChars);
67+
return "operator";
68+
}
6369
else if (operatorChars.test(ch)) {
6470
stream.eatWhile(operatorChars);
6571
return "operator";
6672
}
6773
else if (ch == ":") {
68-
stream.eatWhile(/[\w\d\._\-]/);
74+
eatPnLocal(stream);
6975
return "atom";
7076
}
7177
else if (ch == "@") {
@@ -75,7 +81,7 @@ CodeMirror.defineMode("sparql", function(config) {
7581
else {
7682
stream.eatWhile(/[_\w\d]/);
7783
if (stream.eat(":")) {
78-
stream.eatWhile(/[\w\d_\-]/);
84+
eatPnLocal(stream);
7985
return "atom";
8086
}
8187
var word = stream.current();
@@ -88,6 +94,10 @@ CodeMirror.defineMode("sparql", function(config) {
8894
}
8995
}
9096

97+
function eatPnLocal(stream) {
98+
while (stream.match(/([:\w\d._-]|\\[-\\_~.!$&'()*+,;=/?#@%]|%[a-fA-F0-9][a-fA-F0-9])/));
99+
}
100+
91101
function tokenLiteral(quote) {
92102
return function(stream, state) {
93103
var escaped = false, ch;

0 commit comments

Comments
 (0)