Antlr4 grammars for ADL, ODIN, BEL, EL, BMM.
The grammars in this project are an attempt to systematise all grammars for openEHR in one place, and using common lexers for common patterns such as identifiers, paths, terminal values and so on. The grammars use modal lexers (example: ADL2 lexer) to handle the multiple formalisms that may appear in e.g. ADL files, CADL blocks within ADL (which may have further embedded ODIN or JSON blocks) and so on.
It is eventually intended to be used as the official source for grammars for various specifications, i.e. replacing existing grammars in the adl-antlr repository.
This is a development repository containing Antlr4 grammars for most of the languages and syntaxes in use in openEHR.
This is a multi-module project, using gradle as the build system. IntelliJ is the usual IDE, but it is configured with gradle rather than the internal build and test, and should work in Visual Studio, Eclipse and other IDEs.
Building is set up with an attempt at best practices using gradle 9.1.0 or later. Common build specifications (i.e. instructions normally found in build.gradle files) are in the gradle special module buildSrc, which contains a file java-build-conventions.gradle, which in turn defines a plugin that can be re-used in the build.gradle file for in other modules using the following include:
plugins {
id("java-build-conventions")
}Building can be performed from the command line, e.g. within IntelliJ’s terminal as follows:
./gradlew clean
./gradlew build --continueThe --continue switch above will ensure that a build continues across all modules, even if test cases fail post build of each module.
The grammars are maintained in various modules:
-
the
reader_common/src/main/antlrdirectory contains common reusable grammars, incuding some legacy ones; -
the modules
reader_adl2,reader_adl14,reader_bmmletc contain top-level grammars for complete languages, in files undersrc/main/antlr. Each of these modules re-uses thereader_commonmodule grammars, via thebuild.gradlestatement:
dependencies {
api project(':reader_common')
}|
Note
|
To use the Antlr plugin preview function for any of the top-level grammars, e.g. bmml, testing within the reader_bmml module will not work. Although there are gradle rules to make gradle pass the 'grammar import' directory to the antlr plug-in code generator during gradle building, the Antlr plugin previewer does not use the import directory (!), and cannot correctly evaluate a grammar in one of these modules, because it doesn’t see the referenced grammars in reader_common. To run the previewer therefore, there is currently no option but to copy the grammar files from reader_bmml, reader_adl2 etc, to the antlr directory in reader_common and do it there, followed by removing these files.
|
Each module contains its own test class(es) in src/test/xxx and test files, under src/test/resources, in the usual way.
Common test utility code is in the module test_fixtures. Ideally it would be in reader_common/src/testFixtures, but this could not be made to work due to IntelliJ’s documented inability to handle testFixtures properly (as of end 2025).
The test cases are known to generally work using IntelliJ Idea 2025.x, with the Antlr4 4.13.1 plug-in (see top-level build.gradle file), and Java 17 JRE & JDK installed.
To run the tests in reader_adl2, for example, use the test class reader_adl2/src/test/java/org/openehr/reader_adl2/Adl2ReaderTest.java. A similar test class can be found in the other reader_xxx modules.
Relevant specifications may be found on the openEHR specifications home page, in particular: