ANTLR4 grammar for parsing the INTERLIS 2.4 language.
This ANTLR4 grammar is based on the INTERLIS 2.4 specification published by eCH:
The specification is also available in an AsciiDoc/HTML format:
The original grammar is defined using a WSN-based notation. This repository contains an independent ANTLR4 adaptation which has been adjusted to comply with ANTLR4 grammar requirements.
This repository is licensed under the MIT License. See the LICENSE file for details.
Attribution and information about the source specification are provided in the NOTICE file.
The grammar targets the INTERLIS 2.4 language specification.
Because the grammar has been adapted for ANTLR4, differences may exist compared with other INTERLIS grammar representations or implementations.
The generated parsers are intended for parsing INTERLIS 2.4 models and may not provide identical behavior to other INTERLIS tools in all edge cases.
Install uv by following the official installation instructions:
https://docs.astral.sh/uv/getting-started/installation/
To create the project's virtual environment and install its dependencies:
uv sync:::info
This step is optional: running any uv run ... command will automatically create the environment and install the required depencies if needed.
:::
antlr4-tools downloads and runs a specific ANTLR release; pin it with the
-v flag on the command itself:
uv run antlr4-parse -v 4.13.2 <command's other arguments>(-v VERSION takes priority over the ANTLR4_TOOLS_ANTLR_VERSION
environment variable, which antlr4-tools otherwise falls back to and,
failing that, the latest release - see antlr4_tool_runner.py's
process_args.) Every command below pins 4.13.2 this way.
To parse an input file, use the following command:
uv run antlr4-parse -v 4.13.2 InterlisLexer.g4 InterlisParser.g4 <rule> input/<inputfile.extension> -<option>-tree: Display the parse tree.-gui: Display the parse tree in a graphical interface.-tokens: Display the tokens.-diagnostics: Display the errors
You can also parse an expression directly from the command line:
uv run antlr4-parse -v 4.13.2 InterlisLexer.g4 InterlisParser.g4 <startRule> -tree
<input_expression>
^DGenerating a log with all the inconsistencies:
uv run antlr4-parse -v 4.13.2 InterlisLexer.g4 InterlisParser.g4 <rule> input/<inputfile.extension> -diagnostics > errors.log 2>&1The ANTLR4 grammar is target-language independent. This repository uses Python and uv as the development environment, but the grammar can be used to generate parsers for any ANTLR4-supported target, including Java, JavaScript, TypeScript, Go, Dart, C#, C++, Swift, PHP and others.
uv run antlr4 -v 4.13.2 \
-Dlanguage=Python3 \
-o generated \
InterlisLexer.g4 \
InterlisParser.g4The generated files are stored in the generated/ directory.
This directory contains the Python sources generated by ANTLR4 and should not be edited manually.
To remove the virtual environment, the ANTLR cache and the generated parser files:
rm -rf .venv .antlr generated/