Skip to content

Commit

Permalink
[sparql mode] Improve parsing of IRI atoms
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
MarkBoyes committed Oct 15, 2020
1 parent 55d0333 commit 9caacec
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions mode/sparql/sparql.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,18 @@ CodeMirror.defineMode("sparql", function(config) {
stream.skipToEnd();
return "comment";
}
else if (ch === "^") {
ch = stream.peek();
if (ch === "^") stream.eat("^");
else stream.eatWhile(operatorChars);
return "operator";
}
else if (operatorChars.test(ch)) {
stream.eatWhile(operatorChars);
return "operator";
}
else if (ch == ":") {
stream.eatWhile(/[\w\d\._\-]/);
eatPnLocal(stream);
return "atom";
}
else if (ch == "@") {
Expand All @@ -75,7 +81,7 @@ CodeMirror.defineMode("sparql", function(config) {
else {
stream.eatWhile(/[_\w\d]/);
if (stream.eat(":")) {
stream.eatWhile(/[\w\d_\-]/);
eatPnLocal(stream);
return "atom";
}
var word = stream.current();
Expand All @@ -88,6 +94,10 @@ CodeMirror.defineMode("sparql", function(config) {
}
}

function eatPnLocal(stream) {
while (stream.match(/([:\w\d._-]|\\[-\\_~.!$&'()*+,;=/?#@%]|%[a-fA-F0-9][a-fA-F0-9])/));
}

function tokenLiteral(quote) {
return function(stream, state) {
var escaped = false, ch;
Expand Down

0 comments on commit 9caacec

Please sign in to comment.