ANTLR 4 IDE for Eclipse
This project has not seen commits/updates for several years now. It is no longer maintained.
This is brand new version of the old ANTLR IDE. The new IDE supports ANTLR 4.x and it was created to run on Eclipse 4.x
The old ANTLR IDE isn't supported anymore. When I wrote it, I was young and didn't know what was doing ;)
Don't get me wrong, the old version did a very good work from user point of view, it just I'm not proud of the code base because is kind of complex and had a poor quality.
The main reason of complexity of the old IDE was in Dynamic Language ToolKit (DLTK) dependency. The DLTK project didn't evolve so much over the last few years and doing something in DLTK is very very complex and require a lot of work.
Now, the new IDE was built on XText. XText is great for building DSL with Eclipse IDE support, so if you are not familiar with XText go and see it.
See link to ANTLR tools for a comparison of ANTLR4IDE with other development tools for ANTLR.
Help > Install New Software...
http://download.eclipse.org/modeling/tmf/xtext/updates/composite/releases/
in the Work With
textboxXtext
node and check Xtext Complete SDK
(ensure the version is 2.7.3x)Next
, agree to the EULA, and click finishHelp > Install New Software...
http://download.eclipse.org/releases/luna
in the Work With
textboxFacet
Eclipse Faceted Project Framework
and Eclipse Faceted Project Framework JDT Enablement
Next
, agree to the EULA, and click finishHelp > Eclipse Marketplace...
antlr
ANTLR 4 IDE
(make sure it's ANTLR 4 IDE not ANTLR IDE)File > New Project > Project
General Tab
and select ANTLR 4 Project
(if you don't see this see step 4 of setup)Next
, give the project a name and click Finish
Properties
Project Facets
and click Convert to faceted form...
(if you don't see this see step 3 of setup)Java
project facet and click Apply
(if you don't see this see step 3 of setup)OK
, let the solution rebuild, open the properties againJava Build Path
, click the Source
tabAdd Folder...
and check Project > target > generated-sources > antlr4
, click OK
Libraries
tabAdd External JARs...
, find your copy of antlr-4.x-complete.jar
, click Open
ANTLR 4 > Tool
, click Apply
if a pop-up appearsEnable project specific settings
Add
, find your copy of antlr-4.x-complete.jar
, click Open
4.x
Apply
, click Yes
to rebuild, click OK
to exit the propertiesThe new IDE is very simple to use all the files with a *.g4
extension will be opened by the ANTLR 4 Editor. So, just open a *.g4
file and play with it.
See grammars examples at https://github.com/antlr/grammars-v4
Code is automatically generated on save if the grammar is valid. You can turn off this feature by going to: Window > Preferences > ANTLR 4 > Tool
and uncheck the "Tool is activated" option. From there you can configure a couple more of options.
You can find the generated code in the target/generated-sources/antlr4
(same directory as antlr4-maven-plugin)
You can fire a code generation action by selecting a *.g4
file from the Package Explorer, right click: Run As > ANTLR 4
.
A default ANTLR 4 launch configuration will be created. You can modify the generated launch configuration by going to: Run > External Tools > External Tools Configurations...
from there you will see the launch configuration and how to set or override code generation options
To open the Syntax Diagram view go to: Window > Show View > Other
search and select: Syntax Diagram
Hello there
and Ctrl + z to send EOF to the input stream import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.tree.*;
public class HelloRunner
{
public static void main( String[] args) throws Exception
{
ANTLRInputStream input = new ANTLRInputStream( System.in);
HelloLexer lexer = new HelloLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
HelloParser parser = new HelloParser(tokens);
ParseTree tree = parser.r(); // begin parsing at rule 'r'
System.out.println(tree.toStringTree(parser)); // print LISP-style tree
}
Build with Maven 3.x
Fork and clone the repository from github
Download and install Maven 3.x
Open a shell console and type: cd antlr4ide
Build the project with: mvn clean package
It takes a while to download and configure Eclipse dependencies, so be patient
Wait for a: BUILD SUCCESS
message
When building for the very first time there might be some missing dependencies, so please retry mvn clean package
Setup Eclipse
Open Eclipse Luna (4.4)
Install Xtext 2.7.3
Copy and paste this url: http://download.eclipse.org/modeling/tmf/xtext/updates/composite/releases/ in the Work with text field
Hit Enter
Choose XText 2.7.3. NOTE: DON'T confuse with Xtend, you must choose Xtext
Restart Eclipse after installing Xtext
Import the project into Eclipse
Go to: File > Import...
then General > Existing Projects into Workspace
Choose project root antlr4ide
Enabled: Search for nested projects
Finish
You don't need any extra Eclipse plugin (like m2e or similar). Project metadata is on git so all you need to do is: mvn clean package
and then import the projects into Eclipse.
[Edgar Espina] (https://twitter.com/edgarespina)