Hibernate programmers,
I've made some progress with the HQL parser, so here's an
update:
Design decisions:
1) Use ANTLR to generate the parser. It has a
compatible Open Source licence, and adds only one new library
dependency.
2) Use a three phase design: parse/analyze/generate
code - This is a very typical modular compiler design. The parse
phase is implemented as a stream parser, the analysis phase is implemented as a
tree parser (tree transform, actually), and the code generation phase is a tree
parser that produces an SQL stream.
3) Use the ANTLR generated parsers as base classes,
implementing the main semantic / syntax analysis functions in derived
classes. This keeps the grammar files smaller, and alows me to use my
favorite Java IDE to write the analysis code.
So, what's been done so far?
* An HQL grammar / parser which sucessfully parses most of
the examples in the Hibernate HQL doco. A few additional features
have been added, as well as a unit test that exercises this
phase.
* An HQL AST analyzer, which converts the HQL AST into an
intermediate, SQL (ish) AST. This is implemented as a tree parser which
normalizes the HQL AST and binds the HQL AST elements to the appropriate
Hibernate mapping API objects (e.g. Queryable, etc.).
* A very simplistic SQL generator, which walks the
intermediate tree and produces an SQL stream. This is primarly for
testing, although it might come in handy later on when integrating all this into
Hibernate.
* Some initial 'implied join'
examples.
What's
next?
* Get implied joins (and 'fake'
AST generation to work).
* Utilize more of the existing
Hibernate API for mappings.