Skip to content
Tom Everett edited this page Nov 21, 2020 · 29 revisions

Welcome to the grammars-v4

Grammars-v4 is a collection of antrl4 grammars contributed by authors around the world. Grammars-v4 uses antlr4test-maven-plugin and travis to ensure that all grammars on the tree compile properly with Antlr4. Additionally each grammar has a directory of examples which antlr4test-maven-plugin uses to ensure that the grammars on the source tree can parse examples without errors.

A core value of grammars-v4 is that any grammar downloaded from grammars-v4 will compile properly with Antlr4, and has been validated against some example inputs.

FAQ

What are the licensing terms for Grammars-v4?

There is no single license for the grammars, each grammar has its own license. Check inside the grammar files for licensing terms

There is no grammar for the language or file format I need. What do I do?

You are welcome to submit an issue ticket, and contributions to the grammars tree are welcome also.

My PR was rejected! Why?!

If your PR breaks the existing tests, it will be rejected. Additionally, we ask that any incremental changes made to grammar files have examples contributed to the /examples directory for that grammar to ensure that future changes to the grammars don't introduce regressions

Are there examples of how to use the grammars?

Look here

Is there a coding standard for Antlr4 grammars?

There is no official standard. However, there is a formatter that most grammars use: Antlr4Formatter

Typically, grammar files use 3 spaces for indents.

How can I use Antlr to parse binary files?

There is an example at (/tcpheader/)[https://github.com/antlr/grammars-v4/tree/master/tcpheader]

How can I download grammars from the github page in a maven build?

Use download-maven-plugin

<plugin>
	<groupId>com.googlecode.maven-download-plugin</groupId>
	<artifactId>download-maven-plugin</artifactId>
	<version>1.4.0</version>
	<executions>
		<execution>
			<phase>generate-sources</phase>
			<goals>
				<goal>wget</goal>
			</goals>
			<configuration>
				<url>https://raw.githubusercontent.com/antlr/grammars-v4/master/arithmetic/arithmetic.g4</url>
				<outputFileName>arithmetic.g4</outputFileName>
				<outputDirectory>src/main/antlr4/com/khubla/antlr4example/</outputDirectory>
			</configuration>
		</execution>
	</executions>
</plugin>

How do i test the grammars?

mvn clean test
Clone this wiki locally