-
-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add SPARQL & Turtle highlighter #44
Comments
Emacs does it with regexps: (defconst sparql-keywords-re
(regexp-opt
'("ADD" "ALL" "AS" "ASC" "ASK"
"BASE" "BIND" "BINDINGS" "BY"
"CLEAR" "CONSTRUCT" "COPY" "CREATE"
"DATA" "DEFAULT" "DELETE" "DESC" "DESCRIBE" "DISTINCT" "DROP"
"EXISTS"
"FILTER" "FROM"
"GRAPH" "GROUP"
"HAVING"
"IN" "INSERT" "INTO"
"LIMIT" "LOAD"
"MINUS" "MOVE"
"NAMED" "NOT"
"OFFSET" "OPTIONAL" "ORDER"
"PREFIX"
"REDUCED"
"SELECT" "SERVICE" "SILENT"
"TO"
"UNDEF" "UNION" "USING"
"WHERE" "WITH")
'symbols))
(defconst sparql-keywords
`((,(rx "<" (* (not space)) ">")
0 font-lock-constant-face t)
(,(rx bol (*? (not (in "#"))) (group "\"" (* (not (in "\""))) "\""))
1 font-lock-string-face)
(,(rx bol (*? (not (in "#"))) (group "'" (* (not (in "'"))) "'"))
1 font-lock-string-face)
(,(rx (*? not-newline) (group "#" (* not-newline)))
1 font-lock-comment-face)
,sparql-keywords-re
(,(rx (any "?$") (+ word))
0 font-lock-variable-name-face))) Turtle (n3) is basically a subset of sparql: (setq n3-highlights
'(("\\(@prefix\\)\\>" 1 font-lock-keyword-face t)
("\\(a\\)\\>" 1 font-lock-keyword-face t)
("\\(\\S-*?:\\)" 1 font-lock-type-face t)
(":\\(.+?\\)[ ;.]" 1 font-lock-constant-face t)
("\\(<.*?>\\)" 1 font-lock-function-name-face t)
("\\(\\\".*?\\\"\\)" 1 font-lock-string-face t)
; Bug: some trailing characters are highlighted; restricting comments regexp
; ("\\(#.*\\)" 1 font-lock-comment-face t)
("^\\s-*\\(#.*\\)" 1 font-lock-comment-face t)
)
) |
Yes, read the KDE docs. skylighting is nearly 100% compatible
with existing KDE syntax definitions -- there are just occasionally
small tweaks needed due to differences in the regex engine.
|
There is Turtle & SPARQL highlighting in highlight.js.
@jgm, what are the disadvantages of using highlight.js instead of skylighting ? |
Skylighting will give you coloring support in many of the formats pandoc supports, and the coloring will be baked into the document (not requiring a javascript interpreter). But feel free to use highlighting.js if it meets your needs! |
See https://www.w3.org/TR/sparql11-query/#sparqlGrammar
I'm thinking of using this as a model:
https://github.com/jgm/skylighting/blob/master/skylighting-core/xml/sql.xml
@jgm, could you give me some pointers? I have a lot of questions (eg what is
#stay
and#pop
, what is the list of reusableitemDatas
...)Guess I should first read https://docs.kde.org/stable5/en/applications/katepart/highlight.html,
then diff https://github.com/KDE/syntax-highlighting/blob/master/data/syntax/sql.xml to the above to see what changes skylighting has compared to KDE/syntax-highlighting?
My next question would be about Turtle: https://www.w3.org/TR/turtle/#h3_sec-grammar-grammar. It has very few keywords and relatively simple structure that consists mostly of terms.
Thanks for all your help!
The text was updated successfully, but these errors were encountered: