grammars-v4 icon indicating copy to clipboard operation
grammars-v4 copied to clipboard

New grammar: XQuery

Open kaby76 opened this issue 2 years ago • 1 comments

XQuery is to XML what SQL is to databases.

This grammar is very useful for Trash. Up to now, I've been providing tools like trxgrep, trinsert, trdelete, and trreplace, which implement CRUD. But a query language that affects CRUD is far more efficient. I can then replace the older collection of tools with one tool.

https://www.w3.org/TR/xquery-3/#nt-bnf

Some links are at https://stackoverflow.com/questions/44890237/antlr-v4-grammar-for-xquery-3-1.

  • The link to "conclusion of the work by JoeyACC" gist is for a combined and import grammar ( xcore.txt xquery31.txt ). While it does try to faithfully follow the Spec, there are many errors (e.g., Unicode sets hare in the wrong syntax, Antlr chokes; "ws: explicit" is on some parser rules in the Spec, but whitespace "S" is "skip", and cannot be used on the RHS of a rule!).
  • There is a link to the only other grammar, which was written by the author of the SO question. But, does not follow the Spec, and contains numerous errors: e.g., rule "VersioDecl": the "version" string is required in the rule, but it's optional in the Spec; expressionExpr does not follow the Spec.
  • There's minimum testing for either.

I started over with the Spec.

kaby76 avatar Jul 29 '23 11:07 kaby76

The XQuery grammar doesn't note it, but it includes almost all the rules for the XPath grammar. See https://www.w3.org/TR/xpath-31/. Therefore, there's going to be a tension between writing this grammar according to Spec, and using Antlr "import" statements for XPath3.1.

kaby76 avatar Aug 01 '23 12:08 kaby76