AQL: Upgrade grammar to ANTLR4

The AQL grammar is now ANTLR3, but there are a number of other variants (vendor defined grammars) in ANTLR4.
Our published grammar needs to be upgraded to latest format - ANTLR4 (which is allegedly cleaner, easier) and synchronized as much as possible with these other circulating variants.
Therefore I created this [SPECQUERY-30] Upgrade grammar to ANTLR4 - openEHR JIRA.

Do you have any objection or suggestion or any other things that you can share to get this done?

I started to look into this issue, doing some refactor of rules. Converting to v4 make some things simpler but it is still a (challenging) complex task, especially if we want to minimize the impact on the code directly using the old grammar. So far I’m checking also publicly available grammars, such as the one from EhrBase and from Nedap/Archie, but I could use more grammars if they are available.

Perhaps we should ask a question: We’re updating the grammar to a new ANTLR4 version. That will require some changes if people are using the previous grammar and want to switch to the new ANTLR4 one. We can try to get a clean grammar as possible, but that will likely mean more changes to the tree walkers/listeners side rather than converting the old grammar with very little changes. Is this a problem for your company to do? Are you even considering switching to the standard grammar, or are you planning on keeping your own

To answer for us: it’s not a big problem. It is going to be work to implement AQL 1.1.0 anyway, and the parsing code is isolated from the rest of our application anyway. If it’s a clean grammar we will switch, otherwise we might not do so and keep using our own.

1 Like

I think we might stick to our version of the grammar but of course consider aligning whenever possible. I would assume that the variations are not far away from each other and everybody, similar to SQL, likes to have some dialect that eventually might become part of the standard.

1 Like

I don’t see anything wrong with a) a new Antrl4 grammar, and b) implementers sticking to what they have.

One use of a new grammar is simply to formally state the semantics associated with the syntax, even if real implementations use another way (e.g. old parser) to get the same result. A new grammar is also good for any new OS or other implementation effort.

I could even have a go at redoing the grammar in Antlr4 if no-one else has already started - it would be a big improvement over the current. And/or happy to review someone else’s.

All good comments, thanks; @pieterbos was spot-on rephrasing things as a question.

Currently, I consider also a complete refactor, so that we can use g4 potentials. Actually I already did a major step in this direction, and I’ll also have a meeting soon with Nedap to finalize it. If more of you are interested, I can invite also.

One reason I need a (new) grammar urgently is that I need to add also changes from the JIRA issues.

Our AQL implementation for. NET is handcoded for the Rosalyn parser. We had an older implementation based on ANTLR but it introduced dependencies we didn’t want to have. We’ll continue to adopt our implementation to the changes in spec.

1 Like