Skip to content

Commit e1fe210

Browse files
authored
[sparql mode] Identify all characters in prefixes
1 parent e5071eb commit e1fe210

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

mode/sparql/sparql.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ CodeMirror.defineMode("sparql", function(config) {
3333
"true", "false", "with",
3434
"data", "copy", "to", "move", "add", "create", "drop", "clear", "load", "into"]);
3535
var operatorChars = /[*+\-<>=&|\^\/!\?]/;
36+
var PN_CHARS = "[A-Za-z_\\-0-9]";
37+
var PREFIX_START = new RegExp("[A-Za-z]");
38+
var PREFIX_REMAINDER = new RegExp("((" + PN_CHARS + "|\\.)*(" + PN_CHARS + "))?:");
3639

3740
function tokenBase(stream, state) {
3841
var ch = stream.next();
@@ -71,20 +74,18 @@ CodeMirror.defineMode("sparql", function(config) {
7174
stream.eatWhile(/[a-z\d\-]/i);
7275
return "meta";
7376
}
74-
else {
75-
stream.eatWhile(/[_\w\d]/);
76-
if (stream.eat(":")) {
77+
else if (PREFIX_START.test(ch) && stream.match(PREFIX_REMAINDER)) {
7778
eatPnLocal(stream);
7879
return "atom";
79-
}
80-
var word = stream.current();
81-
if (ops.test(word))
82-
return "builtin";
83-
else if (keywords.test(word))
84-
return "keyword";
85-
else
86-
return "variable";
8780
}
81+
stream.eatWhile(/[_\w\d]/);
82+
var word = stream.current();
83+
if (ops.test(word))
84+
return "builtin";
85+
else if (keywords.test(word))
86+
return "keyword";
87+
else
88+
return "variable";
8889
}
8990

9091
function eatPnLocal(stream) {

0 commit comments

Comments
 (0)