ANTLR 4.5 Java project using SBT

Couldn’t find anything online showing how to use ANTLR with SBT, so I made this simple example project on how to include ANTLR 4.5 into a Java application, using SBT for the build with the sbt-antlr4 plugin to automatically compile the grammar file under src/main/antlr.

This sample uses a grammar (starter/ArrayInit.g4) from the book “The Definitive ANTLR 4 Reference”, the code samples used in the book are available online for free here.

Setup

# get dependencies and compile
./sbt clean update compile

# run to parse input string "{4,3,2,1,0}", should output parsed LISP-style tree
./sbt "run {4,3,2,1,0}"
# output -> (init { (value 4) , (value 3) , (value 2) , (value 1) , (value 0) })

Source: https://github.com/stevenalexander/antlr-test1