Skip to content
Tom Everett edited this page Jan 5, 2019 · 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

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