Skip to content

Commit fc25da4

Browse files
bollwyvlmarijnh
authored andcommitted
[sparql mode] Update with more details from 1.1
- more style classes: operator, builtin, meta, brackets - literal metas (@ and ^^) - many more operators - mime type and extension from spec
1 parent 13af2af commit fc25da4

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

mode/meta.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
{name: "Smarty", mime: "text/x-smarty", mode: "smarty", ext: ["tpl"]},
103103
{name: "SmartyMixed", mime: "text/x-smarty", mode: "smartymixed"},
104104
{name: "Solr", mime: "text/x-solr", mode: "solr"},
105-
{name: "SPARQL", mime: "application/x-sparql-query", mode: "sparql", ext: ["sparql"]},
105+
{name: "SPARQL", mime: "application/sparql-query", mode: "sparql", ext: ["rq", "sparql"], alias: ["sparul"]},
106106
{name: "SQL", mime: "text/x-sql", mode: "sql", ext: ["sql"]},
107107
{name: "MariaDB", mime: "text/x-mariadb", mode: "sql"},
108108
{name: "sTeX", mime: "text/x-stex", mode: "stex"},

mode/sparql/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ <h2>SPARQL mode</h2>
4343
</textarea></form>
4444
<script>
4545
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
46-
mode: "application/x-sparql-query",
46+
mode: "application/sparql-query",
4747
matchBrackets: true
4848
});
4949
</script>
5050

51-
<p><strong>MIME types defined:</strong> <code>application/x-sparql-query</code>.</p>
51+
<p><strong>MIME types defined:</strong> <code>application/sparql-query</code>.</p>
5252

5353
</article>

mode/sparql/sparql.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,18 @@ CodeMirror.defineMode("sparql", function(config) {
1919
return new RegExp("^(?:" + words.join("|") + ")$", "i");
2020
}
2121
var ops = wordRegexp(["str", "lang", "langmatches", "datatype", "bound", "sameterm", "isiri", "isuri",
22+
"iri", "uri", "bnode", "count", "sum", "min", "max", "avg", "sample",
23+
"group_concat", "rand", "abs", "ceil", "floor", "round", "concat", "substr", "strlen",
24+
"replace", "ucase", "lcase", "encode_for_uri", "contains", "strstarts", "strends",
25+
"strbefore", "strafter", "year", "month", "day", "hours", "minutes", "seconds",
26+
"timezone", "tz", "now", "uuid", "struuid", "md5", "sha1", "sha256", "sha384",
27+
"sha512", "coalesce", "if", "strlang", "strdt", "isnumeric", "regex", "exists",
2228
"isblank", "isliteral", "a"]);
2329
var keywords = wordRegexp(["base", "prefix", "select", "distinct", "reduced", "construct", "describe",
2430
"ask", "from", "named", "where", "order", "limit", "offset", "filter", "optional",
2531
"graph", "by", "asc", "desc", "as", "having", "undef", "values", "group",
2632
"minus", "in", "not", "service", "silent", "using", "insert", "delete", "union",
33+
"true", "false", "with",
2734
"data", "copy", "to", "move", "add", "create", "drop", "clear", "load"]);
2835
var operatorChars = /[*+\-<>=&|]/;
2936

@@ -44,20 +51,28 @@ CodeMirror.defineMode("sparql", function(config) {
4451
}
4552
else if (/[{}\(\),\.;\[\]]/.test(ch)) {
4653
curPunc = ch;
47-
return null;
54+
return "bracket";
4855
}
4956
else if (ch == "#") {
5057
stream.skipToEnd();
5158
return "comment";
5259
}
5360
else if (operatorChars.test(ch)) {
5461
stream.eatWhile(operatorChars);
55-
return null;
62+
return "operator";
5663
}
5764
else if (ch == ":") {
5865
stream.eatWhile(/[\w\d\._\-]/);
5966
return "atom";
6067
}
68+
else if (ch == "@") {
69+
stream.eatWhile(/[a-z\d\-]/i);
70+
return "meta";
71+
}
72+
else if (ch == "^") {
73+
stream.eatWhile(/\^/);
74+
return "meta";
75+
}
6176
else {
6277
stream.eatWhile(/[_\w\d]/);
6378
if (stream.eat(":")) {
@@ -66,7 +81,7 @@ CodeMirror.defineMode("sparql", function(config) {
6681
}
6782
var word = stream.current();
6883
if (ops.test(word))
69-
return null;
84+
return "builtin";
7085
else if (keywords.test(word))
7186
return "keyword";
7287
else
@@ -155,6 +170,6 @@ CodeMirror.defineMode("sparql", function(config) {
155170
};
156171
});
157172

158-
CodeMirror.defineMIME("application/x-sparql-query", "sparql");
173+
CodeMirror.defineMIME("application/sparql-query", "sparql");
159174

160175
});

0 commit comments

Comments
 (0)