Giter Club home page Giter Club logo

hibernate-antlr4-poc's Introduction

Antlr v4 PoC

This project represents a proof-of-concept (PoC) of using Antlr v4 as the basis for the redesign of the HQL (/JPQL) parser used in Hibernate. The initial Antlr-based translator used v2. The initial redesign work used v3, as that was the latest release at that time. Both rely heavily on the principals of tree parsing and tree re-writing, two concepts that are no longer available in Antlr v4.

The PoC then, is meant to determine how Antlr v4 might be used to address the HQL translation needs and whether that is the route we want to go.

There are 2 possible approaches this PoC will demonstrate: AST and decoration...

AST

The premise here is very similar to the design of our Antlr v2/v3 approach. Basically it mimics the idea of a tree parser. The idea is to write multiple grammars. The first grammar is the parse grammar and builds the parse tree. We use the Antlr-generator walker + visitor to produce a new, more semantically rich tree: an AST. However, this AST would also be a parse tree by nature of implementing the proper Antlr contracts. The second grammar would be designed such that it would produce walker + visitor capable of walking this AST tree.

We could have as many phases (subsequent grammars) as we want here. Really, I think the 2 approaches could even be combined.

Decoration

The idea behind decoration is to stuff semantic information (payload) into pertinent points in the parse tree. The walking is still done using the parse tree structure, but using the visitor you would decide whether to continue down a particular sub-tree or not. For example, given a parse tree like:

[QUERY]
  [SELECT]
    [SELECT_ITEM]
      [DOT]
        [DOT]
          [DOT]
            [IDENT, "c"]
            [IDENT, "headquarters"]
          [IDENT, "state"]
        [IDENT, "code"]
...

We would push semantic information into the [SELECT_ITEM] node indicating the "resolution" of the expression. The grammar, the rules, the walker and the visitor/listener would still be stated in relation to the less expressive model; we would just make decisions in the visitor based on the encountered payload.

This is a completely different approach, and so I am completely unfamiliar with what risks it might entail.

Details

The PoC of both approaches start off with the same grammar: Hql.g4. This grammar uses HqlLexer.g4 as its lexer grammar, which defines a complete set of tokens used across all phases of translation. Later we may want to look at breaking that up into tokens needed just for input parsing/recognition versus strictly semantic tokens. But for now, we will use the comp[lete common set of tokens.

It is also important to note that this PoC defines a subset of HQL grammar. It is not meant as THE redesign, just a PoC of how Antlr v4 might be used in the redesign.

hibernate-antlr4-poc's People

Contributors

sebersole avatar

Watchers

James Cloos avatar 郭联伟 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.