Antlr 4中的模糊java解析器

时间:2014-02-06 01:08:49

标签: java parsing antlr4

2012年,Terence Parr写道:

“添加模糊java”解析器“到v4示例页面

您好,

查看本页底部的模糊Java解析器,它只使用词法规则来获取感兴趣的项目:

http://www.antlr.org/wiki/display/ANTLR4/Examples

泰尔“

但页面是“404”,我找不到这个语法。有人有副本吗?或指向另一个模糊或错误恢复Java语法的指针?

1 个答案:

答案 0 :(得分:0)

问题多年后,但语法在 ANTLR4 文档中Wildcard Operator and Nongreedy Subrules

grammar FuzzyJava;
 
/** Match anything in between constant rule matches */
file : .*? (constant .*?)+ ;
 
/** Faster alternate version (Gets an ANTLR tool warning about
 * a subrule like .* in parser that you can ignore.)
 */
altfile : (constant | .)* ; // match a constant or any token, 0-or-more times

/** Match things like "public static final SIZE" followed by anything */
constant
    :   'public' 'static' 'final' 'int' Identifier
        {System.out.println("constant: "+$Identifier.text);}
    ;
 
Identifier : [a-zA-Z_$] [a-zA-Z_$0-9]* ; // simplified