Idea: Creating a XML target for ANTLR4

Hello everybody!

Some months ago I had the idea to create a new target for ANTLR only using XML technologies. I started creating finite state machine with XSLT parsing binary number input. After this little proof of concept I started reviewing the code of ANTLR4 and started a new target.

The plan is to create a XSD schema (data) and a lexer/parser XSLT (code). The code creates a parse tree as XML. The sexy thing is that you can generate XML grammars for each ANTLR grammar by only using a XSLT processor.

As far as I could see, the Java target creates two ATN automata and serializes them into lexer and parser variables as string constants.

At runtime these strings are deserialized with a XSLT script, on which I was working the last time. Porting Java to XSLT manually is easy but can be full of errors, so I thought about porting the code automatically with “JavaParser”. Also because I want to be quickly up to date with ANTLR4 releases.

For simulating execution I could model a stack machine state and a transition function in XSLT. Each method has a data schema for the stack frame. A stack frame contains a state number (which tells the position inside the stackframe’s method) and the “this” object, variables, parameters and return values.

I think creating this target is a lot of fun. But I don’t know if it is so valuable to spend so much time. In the XML community there already exists a concept named “Invisible XML” based on PEG. The ANTLR discussion group signalled no big interest to my idea… so I present it here.

What do you think?

  • Has a ANTLR target for XML any value for someone here?
  • Is it too much work? Is there an easier way?
  • Any pitfalls you see? I never worked with Java in that way…