ANTLR disable specific Userpath in Comments and returns

放肆的年华 提交于 2019-12-13 06:04:50

问题


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" ?

Regards, redstreak.


回答1:


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. Download Antlr for command line and copy it to e.g.

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

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

    cd C:\Users[path to the eclipse project]\src\some\package\name

  3. Invoke

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

    from commandline.

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

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



来源:https://stackoverflow.com/questions/11087097/antlr-disable-specific-userpath-in-comments-and-returns

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!