3 ms·
If we're all being postgres-specific, isn't there presumably a grammar somewhere in postgres's code that is used to parse the query SQL? Wouldn't you all want t
by atonse 3y ago
If we're all being postgres-specific, isn't there presumably a grammar somewhere in postgres's code that is used to parse the query SQL? Wouldn't you all want to use that same file as a source so it's 100% identical to what Postgres is actually doing?
Genuine question. But maybe the tooling is incompatible.
Also, have you looked at Azure Data Studio? I'm wondering how much you can reuse from the work they did.
- aidos 3y agoYacc, I believe. https://www.postgresql.org/docs/7.1/parser-stage.html https://www.postgresql.org/docs/7.1/parser-stage.html
- SR2Z 3y agoNot necessarily. It might be a recursive descent parser (to generate better error messages).
- specialist 3y agoI'll check out Azure Data Studio, thank you. For a bunch of reasons, probably all bad, I decided to roll my own, using ANTLR. Being just a simple bear, LALR (yacc, bison) is beyond me. With ANTLR4 the parse tree can be pretty close to the desired abstract syntax tree. Which is very nice. Also, ANTLR4 has automagic left-recursion, so grammars can be very similar to the (reference) EBNF. Lastly, ANTLR4 allows grammar inheritance. My hope is to have a subgrammar for each dialect which extends the one amazing core supergrammar. Looking at all the example SQL grammars, they're all pretty different, so it's not immediately clear how to generalize. Which is a bummer.