Skip to content

About

ANTLR4 grammar for the INTERLIS modeling language

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

21 Commits

Folders and files

Repository files navigation

INTERLIS 2.4 ANTLR4 grammar

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.

Compatibility

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.

Prerequisites

Install uv by following the official installation instructions:

https://docs.astral.sh/uv/getting-started/installation/

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. :::

Configuration

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.

Usage

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>

Options

  • -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>
^D

Generating 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>&1

Generating a parser

The 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.

Python

uv run antlr4 -v 4.13.2 \
    -Dlanguage=Python3 \
    -o generated \
    InterlisLexer.g4 \
    InterlisParser.g4

The generated files are stored in the generated/ directory. This directory contains the Python sources generated by ANTLR4 and should not be edited manually.

Cleanup

To remove the virtual environment, the ANTLR cache and the generated parser files:

rm -rf .venv .antlr generated/

References

About

ANTLR4 grammar for the INTERLIS modeling language

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages