简体   繁体   中英

ANTLR Grammar for Java Regular Expression syntax

I'm currently working on a testing framework for regular expressions, and I need to be able to parse Java regular expressions into ASTs to be able to generate sample strings which match the given regex.

I looked at the implementation of java.util.regex.Pattern but the code looks quite unwieldy (the emphasis was on speed over readability I would imagine), so I decided to use ANTLR to write a regex parser from scratch.

I'm wondering if anyone knows of a ready ANTLR grammar for regex, before I start bashing one out myself.

There's a similar question here:

Regex Grammar

The answers contain links to assorted grammars, none of them ANTLR ones. I suspect that if you translated the BNF one to ANTLR, you'd be plagued by left-recursion headaches but it's worth a try, you might get lucky.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM