Skip to content
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

Open
VladimirAlexiev opened this issue Apr 19, 2018 · 4 comments
Open

add SPARQL & Turtle highlighter #44

VladimirAlexiev opened this issue Apr 19, 2018 · 4 comments

Comments

@VladimirAlexiev
Copy link
Contributor

VladimirAlexiev commented Apr 19, 2018

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 reusable itemDatas...)

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!

@VladimirAlexiev
Copy link
Contributor Author

VladimirAlexiev commented Apr 19, 2018

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)
    )
)

@jgm
Copy link
Owner

jgm commented Apr 19, 2018 via email

@VladimirAlexiev
Copy link
Contributor Author

There is Turtle & SPARQL highlighting in highlight.js.

@jgm, what are the disadvantages of using highlight.js instead of skylighting ?

@jgm
Copy link
Owner

jgm commented Mar 13, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants