TreeViewer package not working in ANTLR v4 w/ Java

Viewed 992

I am trying to display a GUI of a tree I have parsed in from a pascal program using ANTLR v4. I have used this import to get access to the TV package: import org.antlr.v4.runtime.tree.gui.TreeViewer;

However whenever I try to compile my java program using ANTLR is says that the package org.antlr.v4.runtime.tree.gui. doesn't exist and that it cannot find the symbol for TreeViewer.

Any ideas on why it might be doing this and am I missing something from my imports? I am defining this TreeViewer in java with:

TreeViewer viewr = new TreeViewer(Arrays.asList(
                        parser.getRuleNames()), tree);
2 Answers

Running a grammar requires antlr4-runtime package

using maven :

<dependency>
   <groupId>org.antlr</groupId>
   <artifactId>antlr4-runtime</artifactId>
   <version>4.7</version>
</dependency>

Gui tools like TreeViewer requires antlr4 package

using maven :

<dependency>
   <groupId>org.antlr</groupId>
   <artifactId>antlr4</artifactId>
   <version>4.7</version>
</dependency>

I had the same problem. This is how I solved it:

I use IntelliJ IDE and I had added the Antlr4 plugin from here.

Then in the project, under external libraries, there is an antlr4-4.7.jar file and the TreeViewer class is in there. I click on the class and then it was added to the project.

Related