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

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

问题描述

总是当我从我的语法文件生成解析器和词法分析器时,一切正常,而不是问题,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" ?

问候,红线.

推荐答案

路径似乎取决于您调用 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\name

调用

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天全站免登陆