JSONAntlrAntMavenJastadd is a Java application that parses and performs an analysis over JSON files.
This software package is an example Eclipse package that using the following technologies:
- ANTLR4
- JastAdd
- Apache Maven
- Apache Ant
- ANTLR 4 Maven plugin
- Jastadd Eclipse Plugin for syntax highlighting for file types used by the JastAdd system in Eclipse.
- ANTLR 4 Eclipse plugin for syntax highlighting of ANTLR 4 grammar files in Eclipse.
- JUnit for running Unit tests.
The purpose of this software package is to provide a sample application that demonstrates how to implement a source code analysis by:
- Parsing source files with ANTLR4 and creating a concrete syntax tree (CST).
- Implementing a program analysis over an abstract syntax tree (AST) using JastAdd.
- Implementing a Visitor over an ANTLR4 CST to generate a corresponding JastAdd AST.
- Using Maven to hook in the library dependencies for running both ANTLR4 and ANT from the command line and from the Eclipse IDE.
- Calling an ANT script from a Maven POM file by following these steps.
Compiling and using the Eclipse IDE to edit this software package requires installing software dependencies such as Maven. Not all of the dependencies listed above need to be manually installed because some may be included in your Eclipse installation. This section provides instructions for installing the required dependencies.
Not all of the Eclipse plugin dependencies listed above need to be manually installed because some may be included in your Eclipse installation. Only the following Eclipse plugins probably need to be manually installed.
Tips for installing the ANTLR 4 Eclipse plugin are below.
This Eclipse package has been tested with commit version
b5a38e75ef06d0ebd25361c8e9e1cd51062e0287
of the
ANTLR 4 Eclipse Plugin.
This version depends on version 2.7.3 of Xtext.
The following steps installs that version of Xtext:
- Download the zip archive of Xtext 2.7.3 from this webpage.
- From Eclipse Window, select the downloaded zip file for installing new Eclipse plugins:
Help
->Install New Software
->Add...
->Archive...
- Check Xtext for installation in the popup window and follow the instructions for installation.
For some Eclipse installations,
the ANTLR 4 Maven Plugin does not execute in Eclipse without performing
additional steps not listed on the ANTLR 4 Maven
plugin webpage.
Specifically, the ANTLR 4 plugin caused Eclipse to print
the following error message:
Plugin execution not covered by lifecycle configuration
.
If that error message occurs, this
this StackOverflow
webpage
discusses how to solve that problem.
To compile this software package, perform the following steps:
- Execute the ANT build script
build.xml
in directoryJSONAntlrAntMavenJastadd/src/main/jastadd
. This script can be executed two different ways:- From the Eclipse window by,
Right-clicking the default target ->
Run As
->Ant Build
. - From the command line,
execute
ant
fromJSONAntlrAntMavenJastadd/src/main/jastadd
.
- From the Eclipse window by,
Right-clicking the default target ->
- Run the Maven build script
pom.xml
from directoryJSONAntlrAntMavenJastadd
with the Maven goalcompile
. This script can be done two different ways:- From the Eclipse window by,
Right-clicking the Project Directory ->
Run As
->Maven Build
-> Enter goalcompile
in theGoals:
textbox of the pop-up window. - From the command line,
execute
mvn compile
fromJSONAntlrAntMavenJastadd
.
- From the Eclipse window by,
Right-clicking the Project Directory ->
- Right-clicking the Project Directory ->
Refresh
Executing the steps above should generate the required
source files and compile all of the source files of
JSONAntlrAntMavenJastadd
.
If building JSONAntlrAntMavenJastadd
from the command line,
executing maven compile
is the only step needed to build
the application.
Unfortunately, running the Maven build script from some Eclipse
installations does not in turn run the
ANT script
JSONAntlrAntMavenJastadd/src/main/jastadd/build.xml
,
which will cause compilation errors.
Specifically, if this ANT script did not execute,
executing maven compile
will generate an error message
that includes the phrase "package AST does not exist".
Executing this ANT script runs JastAdd to generate the source
files that perform the program analysis.
To run this ANT script manually, either execute ant
from
JSONAntlrAntMavenJastadd/src/main/jastadd
or execute this script from the Eclipse window by
Right-clicking the default target -> Run As
-> Ant Build
.
JUnit tests that utilize the JSONAntlrAntMavenJastadd
are in file
JSONAntlrAntMavenJastadd/src/test/java/parser/TestJSONParser.java
.
To execute the JUnit tests in that file from Eclipse:
in the Package Explorer,
Right-click the file -> Run As
-> JUnit Test
.