An ANTLR 4 grammar and parser for PCRE (Perl Compatible Regular Expressions).
To generate the parser classes, do a mvn clean install
and then do something
like this:
import nl.bigo.pcreparser.*;
// ...
String regex = "((.)\\1+ (?<YEAR>(?:19|20)\\d{2})) [^]-x]\\x";
PCRELexer lexer = new PCRELexer(CharStreams.fromString(regex));
PCREParser parser = new PCREParser(new CommonTokenStream(lexer));
ParseTree tree = parser.pcre();
// ...
To print an ASCII tree of the generated parse tree, see the Main
class.