在Eclipse Luna上设置ANTLR 4 IDE的麻烦(4.4) [英] Trouble Setting Up ANTLR 4 IDE on Eclipse Luna (4.4)
问题描述
我正在Eclipse Luna(4.4)上安装 ANTLR 4 IDE 。我已经从Marketplace安装了它,但我不知道如何创建一个具有ANTLR 4 Lexer / Parser的项目。
I'm trying to install the ANTLR 4 IDE on Eclipse Luna (4.4). I've installed it from the Marketplace but I have no idea how to create a project that has an ANTLR 4 Lexer/Parser in it.
当我去创建一个新项目我没有看到ANTLR 4的任何选项。我尝试创建一个.g4文件,它在编辑器中打开,但当我保存它不会做任何事情。
When I go to create a new project I don't see any options for ANTLR 4. I tried creating a .g4 file and it opens in the editor but when I save it doesn't do anything.
推荐答案
我环顾了互联网,发现了一大堆资源,我拼凑在一起,通过反复试验找到了解决方案。
以下是我在几台机器上使用的指南,以便在Eclipse中获得ANTLR 4 IDE设置。我想我应该在这里分享一下,拯救别人Google搜索几个小时的麻烦(希望)
I looked around all over the internet and found a handful of resources that I cobbled together and found a solution by trial and error. Below is a guide that I've used on a few of my machines to get ANTLR 4 IDE setup in Eclipse. I figured I should share it here and save others the trouble of Google searching for hours (hopefully)
先决条件
- Eclipse 4.4 Luna Xtext完整的SDK(需要版本为2.7.3)
- Eclipse Faceted Project Framework(经3.4测试) 0)Eclipse Faceted
- 项目框架JDT启用(使用3.4.0进行测试)ANTLR 4 SDK A
- antlr-4.x的副本-complete.jar(4.5写作时)
- Eclipse 4.4 Luna Xtext Complete SDK(Needs to be version 2.7.3)
- Eclipse Faceted Project Framework (Tested with 3.4.0) Eclipse Faceted
- Project Framework JDT Enablement(Tested with 3.4.0) ANTLR 4 SDK A
- A copy of the antlr-4.x-complete.jar (4.5 at the time of writing)
设置
- 安装Eclipse
- Install Eclipse
- Download it from https://www.eclipse.org/downloads/
- 转到
帮助>安装新软件...
- 输入
http://download.eclipse.org/modeling/tmf/xtext/updates/composite / code>工作与
文本框 - 点击Enter等待列表加载(这个将花费一些时间)
- 展开
Xtext
节点,并检查Xtext Complete SDK
(确保版本为2.7.3x) - 单击
下一步
,同意EULA,然后单击完成 - 让安装程序完成并重新启动Eclipse
- Go to
Help > Install New Software...
- Enter
http://download.eclipse.org/modeling/tmf/xtext/updates/composite/releases/
in theWork With
textbox - Hit Enter and wait for the list to load (this will take a few moments)
- Expand the
Xtext
node and checkXtext Complete SDK
(ensure the version is 2.7.3x) - Click
Next
, agree to the EULA, and click finish - Let the installer finish and restart Eclipse
- 转到
帮助>安装新软件...
- 输入
http://download.eclipse.org/releases/luna
使用
文本框 - 点击Enter等待列表加载(这将需要一些时间)
- 在过滤器文本框中输入
Facet
- 选择
Eclipse Faceted Project Framework
和Eclipse Faceted Project Framework JDT启用
- 点击
Next
,同意EULA,并单击完成 - 让安装程序完成并重新启动Eclipse
- Go to
Help > Install New Software...
- Enter
http://download.eclipse.org/releases/luna
in theWork With
textbox - Hit Enter and wait for the list to load (this will take a few moments)
- In the filter text box enter
Facet
- Select
Eclipse Faceted Project Framework
andEclipse Faceted Project Framework JDT Enablement
- Click
Next
, agree to the EULA, and click finish - Let the installer finish and restart Eclipse
- 转到
帮助> Eclipse Marketplace ...
- 搜索
antlr
- 选择
ANTLR 4 IDE
(确保它是ANTLR 4 IDE不是ANTLR IDE) - 单击安装
- 让安装程序完成点击ok,如果它提示并重新启动Eclipse
- Go to
Help > Eclipse Marketplace...
- Search for
antlr
- Choose
ANTLR 4 IDE
(make sure it's ANTLR 4 IDE not ANTLR IDE) - Click Install
- Let the installer finish clicking ok if it prompts and restart Eclipse
- 从此处下载文件
- 将它保存在你会记住的地方
- Download the file from here
- Save it somewhere you'll remember
创建ANTRL 4项目
I found most of this information here, the rest was reading errors and guessing
- 转到
文件>新项目>项目
- 展开
常规选项卡
并选择ANTLR 4项目
(如果没有看到,请参阅设置的第4步) - 点击
下一步
,给项目一个名字并单击完成
- 项目完成后,右键单击项目,然后单击
属性
- 转到
项目方面
,然后点击转换为刻面形式...
(如果看不到,请参阅设置步骤3) - 检查
Java
项目构面,然后单击应用
(如果看不到,请参阅设置步骤3) - 点击
确定
,让解决方案重建,再次打开属性 - 转到
Java构建路径
,单击源
标签 - 点击
添加文件夹...
并检查Project>目标>生成源> antlr4
,点击确定
- 点击
Libraries
标签 -
添加外部JAR ...
,找到您的副本antlr-4.x-complete .jar
,点击打开
- 转到
ANTLR 4>工具
,点击应用
如果弹出窗口出现 - 检查
启用项目单击
添加
,找到antlr-4的副本。 x-complete.jar
,点击打开
- 检查
4.x
- 点击
申请
,点击是
重建,点击确定
退出属性
- Go to
File > New Project > Project
- Expand the
General Tab
and selectANTLR 4 Project
(if you don't see this see step 4 of setup) - Click
Next
, give the project a name and clickFinish
- Once the project is complete right click the project and click
Properties
- Go to
Project Facets
and clickConvert to faceted form...
(if you don't see this see step 3 of setup) - Check the
Java
project facet and clickApply
(if you don't see this see step 3 of setup) - Click
OK
, let the solution rebuild, open the properties again - Go to
Java Build Path
, click theSource
tab - Click
Add Folder...
and checkProject > target > generated-sources > antlr4
, clickOK
- Click the
Libraries
tab Add External JARs...
, find your copy ofantlr-4.x-complete.jar
, clickOpen
- Go to
ANTLR 4 > Tool
, clickApply
if a pop-up appears - Check
Enable project specific settings
- Click
Add
, find your copy ofantlr-4.x-complete.jar
, clickOpen
- Check
4.x
- Click
Apply
, clickYes
to rebuild, clickOK
to exit the properties
测试
使用以下代码创建一个新类,然后尝试运行。在控制台中写入 Hello there
和 Ctrl + z 将EOF发送到输入流
Create a new class with the following code and try running. In the console write 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
}
}
笔记
- 如果您尝试进入
ANTLR 4>工具
检查您的Xtext版本,2.8.0在工具窗口中导致错误 - 在步骤8中,如果您更改了ANTLR生成的目录来源该目录
-
如果您注意到您已添加到
ANTLR 4>的ANTLR版本工具>分发
消失,这似乎是好的
- If you see an error when you try to go into
ANTLR 4 > Tool
check your Xtext version, 2.8.0 causes an error in the tool window - In step 8, if you've changed the directory ANTLR generates it's sources use that directory
If you notice that the version of ANTLR you've added to
ANTLR 4 > Tool > Distributions
disappears this seems to be ok
- 检查你的构建输出,看看它使用什么工具,它应该还使用你添加的JAR,即使它消失了。这是我的样子:
ANTLR工具v4.5(C:\JavaLib\antlr -4.5-complete.jar)
Hello.g4 -o C:\Users\username\workspace\project\target\generated-sources\antlr4 -listener -no-visitor -encoding UTF -8
这篇关于在Eclipse Luna上设置ANTLR 4 IDE的麻烦(4.4)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!