Open source ABNF Parser implementation for Java? [closed]
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this questionI need an Augmented Backus-Naur Form Parser (RFC 5234) in Java to validate some languages.
In the interest of not re-inventing the wheel, I would prefer to use an existing open source i开发者_开发知识库mplementation of ABNF Parser if one already exists.
I need open source because it allows me to maintain the code as needed.
Does anyone know of any that exists?
I have made the observation that Parse2 (see answer by Ralph) comes with some limitations:
- aparse doesn't like the comments and they have to be removed manually prior to code generation
- all statements need to end with a
;
at the end of the line - aparse does not apply the "core" ABNF rules as defined RFC 5234 so they have to be copied from the RFC if your grammar is based on them
- aparse does not like loops in the grammar ( e.g.
S --> NT1 NT2 T1 ; NT1 --> S | T2 ; ...
) and might run into endless loops.
These observations have been confirmed by the developer of Parse2. So in short: Parse2 can parse a subset of ABNF grammars, however it will most likely have problems if you find an existing ABNF grammar and try to feed it to the software.
If you specify the ABNF grammars yourself and keep these limitations in mind, this library should work for you. If you have to work with existing ABNF grammars you might have to put additional effort into the grammar prior to code generation.
PS: the Parse2 library source code is currently not available even though the compiled binary (java byte code) is available freely.
Parse2 generates source java for a parser from ABNF.
精彩评论