我在Antlr 3中为我的公司实现了一种语法语言。目前,代码生成时没有评论。我想编码评论,以便自定义评论出现。例如:在Antlr 3中生成自定义JavaDoci
/**
* This class does something.
* @author name
*/
public class GrammarLanguageExample() {
}
语法语言的一个例子如下所示:
grammar Example;
options {
output=AST;
}
@header {
package com.example;
}
@rulecatch {
// ANTLR does not generate its normal rule try/catch
catch(RecognitionException e) {
throw e;
}
}
insert : 'INSERT INTO table' 'VALUES';
QUOTE : '"';
SPECIALCHAR : '-'|'~'|;
STRING : QUOTE('a'..'z'|'A'..'Z'|SPECIALCHAR|WS)+QUOTE;
WS: (' '|'\t'|'\f'|'\n'|'\r')+ { $channel = HIDDEN;}; // hide token from parser
上面语法仅是一个例子,并且不是完整的语法。当代码由AntlrWorks 3.4生成时会发生什么:
我得到两个Java文件:ExampleLexer和ExampleParser。
在ExampleLexer中,没有包信息。我期望它进入com.example包,而ExampleParser包含com.example包。每次语法发生变化时,我都必须输入Lexer代码的com.example进行编译。如何更改语法中的代码以便添加包信息?
另外,如何添加自定义JavaDoc注释?我想在此格式:
package com.example;
Then import statements;
/**
* This class is used for Lexer.
* @author name
*/
public class ExampleLexer() {
}
package com.example;
Then import statements
/**
* This class is used for parsing.
* @author
*/
public class ExampleParser() {
}
我也想取消自动包信息,生成语法时,告诉之前生成的注释。这怎么可能?
我希望你能帮上忙。我在Google上搜索过,但找不到任何关于此的内容。
感谢您的帮助。 – user1646481 2013-02-14 12:01:28
@ user1646481不客气。我希望你的项目进展顺利。 – user1201210 2013-02-14 12:36:30