ANTLR禁用注释中的特定用户路径并返回 [英] ANTLR disable specific Userpath in Comments and returns

查看:193
本文介绍了ANTLR禁用注释中的特定用户路径并返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

总是当我从我的语法文件生成Parser和Lexer,一切工作正常,而不是问题,ANTLR自动添加整个用户目录到任何返回和评论。这是不好的。例如:

Always when i generate Parser and Lexer from my Grammarfile, everything works fine instead of the problem, that ANTLR automaticly adds the whole User directory to any returns and comments. That is not good. E.g.:

return "C:\\Users\\##\\workspace\\project\\src\\Grammar.g"

此工具也可以任何注释:

also this tool does the same with any comments:

// $ANTLR 3.4 C:\\Users\\##\\workspace\\project\\src\\Grammar.g 2012-06-18 18:25:20

我必须发布我的项目,所以有什么办法禁用这个功能?

i have to publish my project so is there any way to disable this "function" ?

回复,
redstreak。 >

Regards, redstreak.

推荐答案

路径似乎取决于调用ANTLR的位置和方式。我不能实现这一点与ANTLRWorks,但使用命令行ANTLR你能够执行这个。您可以执行以下操作(示例适用于Windows,但应该可以在其他操作系统上重现):

Paths seem to depend from where and how you invoke ANTLR. I was not able to achieve this with ANTLRWorks, but using command line ANTLR you are able to perform this. You can do the following (example is for Windows but should be reproducible on other OSes, too):


  1. 下载 Antlr命令行,并将其复制到例如

  1. Download Antlr for command line and copy it to e.g.

C:\Program Files(x86)\ANTLRworks\antlr-3.4-complete.jar

打开Windows命令行( cmd.exe ),并切换到您的语法文件所在的目录:

Open a Windows command line (cmd.exe) and change to the directory where your grammar file is located:

cd C:\Users [eclipse项目的路径] \src\some\package\\\
ame

调用

java -jar "C:\Program Files (x86)\ANTLRworks\antlr-3.4-complete.jar" MyGrammar.g

生成的java文件将只包含语法文件的名称和路径。

The generated java files will only contain the name of your grammar file and no path anymore.

这个答案来自我自己的问题在ANTLR生成的java类中删除(绝对)路径:最后我回答了自己。

This answer is from my own question Remove (absolute) paths in ANTLR generated java classes: which at the end I answered myself.

这篇关于ANTLR禁用注释中的特定用户路径并返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆