sparql-mode icon indicating copy to clipboard operation
sparql-mode copied to clipboard

SPARQL syntax error checking

Open ljos opened this issue 10 years ago • 4 comments

To do true syntax error checking we need to parse the syntax and report errors if there are any.

Look into:

ljos avatar Nov 26 '14 16:11 ljos

Also look at LSP:

  • Emacs implementations: https://github.com/emacs-lsp/lsp-mode/, https://github.com/joaotavora/eglot
  • SPARQL & Turtle implementations: https://www.stardog.com/blog/language-servers-for-everybody

VladimirAlexiev avatar Jan 30 '19 12:01 VladimirAlexiev

I made a basic implementation for that no idea how to integrate it properly, it works because I have a node_modules in my project (projectile).

https://gist.github.com/bjonnh/dc274cc64aef296d65e37fe71bcf6cbc

bjonnh avatar May 08 '20 14:05 bjonnh

Flycheck works well for me, using qparse from Jena. Since I'm on Windows, the command is qparse.bat:

(flycheck-define-checker sparql-syntax
  "A SPARQL syntax checker using ARQ qparse. See URL https://jena.apache.org/documentation/query/cmds.html."
  :command ("qparse.bat" "--query" source)
  :error-patterns
  ((error line-start "Encountered \"" (message) "\" at line " line ", column " column "." line-end)
   (error line-start "Lexical error at line " line ", column " column "." (+ space) "Encountered: " (message) line-end))
  :modes sparql-mode)
(add-to-list 'flycheck-checkers 'sparql-syntax)
(add-hook 'sparql-mode-hook 'flycheck-mode)

johanwk avatar Feb 03 '21 15:02 johanwk

@johanwk @ljos

  1. sparql-mode also works well on SPARQL Update files (*.ru). Would it be possible to make the flychecker work for such files as well? Jena has another command update that produces errors in the same format as qparse (see below). Maybe the cleanest approach is to define a derived sparql-update-mode?
update --update <query>.ru
org.apache.jena.query.QueryParseException: Lexical error at line 7, column 2.  Encountered: "\r" (13), after : "z"
        at org.apache.jena.sparql.lang.ParserSPARQL11Update._parse(ParserSPARQL11Update.java:72)
        at org.apache.jena.sparql.lang.ParserSPARQL11Update.parse$(ParserSPARQL11Update.java:45)
        at org.apache.jena.sparql.lang.UpdateParser.parse(UpdateParser.java:48)
        at org.apache.jena.update.UpdateFactory.make(UpdateFactory.java:283)
        at org.apache.jena.update.UpdateFactory.read(UpdateFactory.java:272)
        at org.apache.jena.update.UpdateFactory.read(UpdateFactory.java:183)
        at org.apache.jena.update.UpdateFactory.read(UpdateFactory.java:167)
        at org.apache.jena.update.UpdateFactory.read(UpdateFactory.java:155)
        at arq.update.execOneFile(update.java:104)
        at arq.update.execUpdate(update.java:81)
        at arq.cmdline.CmdUpdate.exec(CmdUpdate.java:63)
        at jena.cmd.CmdMain.mainMethod(CmdMain.java:93)
        at jena.cmd.CmdMain.mainRun(CmdMain.java:58)
        at jena.cmd.CmdMain.mainRun(CmdMain.java:45)
        at arq.update.main(update.java:49)
  1. Would it be possible to adapt the checker to work with http://tarql.github.io/? It's the same as SPARQL, except the last bullet below:
  • A SPARQL 1.1 SELECT query
  • A SPARQL 1.1 ASK query
  • One or more consecutive SPARQL 1.1 CONSTRUCT queries.
    • All prefixes defined at the beginning should apply to all queries
    • IMHO the only way to accommodate this is to split up the file before passing to qparse

VladimirAlexiev avatar Feb 16 '21 12:02 VladimirAlexiev