New Antlr4 grammars for openEHR

All,
I have been working on a new set of Antlr4 grammars for openEHR, starting with ADL2, CADL, ODIN, Expressions, and now looking at AQL. They are here in a public repo in my home area for now, and contain sufficient initial Java code and tests to run syntax tests on any of these languages. You can find the grammars and everything else right here in Github.

The aims of the revised set of grammars include:

  • modular: a separate reader for ODIN, EL, ADL2, Expressions etc;
  • re-use: enable maximal re-use of common patterns e.g. for openEHR archetype ids & codes, ISO8601 date/time codes etc, but also of higher level rules e.g. expressions;
  • modal: use Antlr4 modes to handle embedded syntaxes within another syntax, which occurs in ADL2, Cadl (default values), AQL (WHERE clauses with ADL and ODIN blocks), Expressions (can contain ADL) etc;
  • simplification: clean up some historical difficulties that made the grammars needlessly complicated, like regex handling, URIs;
  • Enable ODIN replacement: to make life easier for developers, it would be useful to enable syntaxes like JSON, JSON5 and YAML to replace ODIN in many places it is used (most ADL sections). For uses like Archetype description, terminology, straight JSON should work OK; for polymorphic typed structures and use of the compact leaf types, a schema-based approach will be needed; the new modular grammars make it easy to rewrite archetypes and AQL with ODIN replaced by a preferred syntax;
  • support old and new Expression languages: provide a grammar implementing the old (unfinished) Expression spec as well as the new BMM-based Expression Language;
  • Spec reference: act as the specifications grammar reference for inclusion into published specifications.

Feel free to fork this repo and have a look / play. It is set up for IntelliJ with gradle as the build mechanism. All the grammars under development are under the ‘combined’ module; the other separate modules might be updated or deleted later, depending on whether I can make gradle + Antlr work together a bit better.

An obvious practical aim is to integrate this work into Archie. @pieterbos has been looking at them and helping me with Gradle setup and other details, not to mention errors in the grammars themselves. I have not tried to do this just yet, because I want to get the grammar files named properly, get the importing working perfectly and make any improvements that make software development easier. I think we can decide that as a group.

Right now, I am continuing to make adjustments and test.

I will post more on specifics of these grammars in the relevant categories here on Discourse. Please respond to those topics for the particular grammars, e.g. ADL2, AQL, or here for the general approach.

I have released a new version of these grammars. The Cadl grammars now extract ODIN blocks and send them to the ODIN reader. In ADL2, an ODIN (or JSON) block is used within the definition section to represent a default value. In ADL1.4, it is used for the old style of ‘special’ constraint, mainly for C_DV_QUANTITY constraints.

See the GitHub repo.