ljos / sparql-mode

A SPARQL mode for emacs
GNU General Public License v3.0
62 stars 23 forks source link

SPARQL syntax error checking #29

Open ljos opened 9 years ago

ljos commented 9 years ago

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

Look into:

VladimirAlexiev commented 5 years ago

Also look at LSP:

bjonnh commented 4 years ago

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

johanwk commented 3 years ago

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)
VladimirAlexiev commented 3 years ago

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

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