It is said that it is difficult to parse email addresses in the program, so I implemented the full-featured ABNF. As a result of packing various things, you can easily implement JSON, JSON Pointer, and JSON Patch.
ABNF is often used in IETF RFCs. E-mail and JSON are famous, and even how to write IP address and URL is ABNF. For that reason, I've only seen countless general tools and libraries on the market, so I made it quickly.
The structure is just to extend Parser to create something like a verb, and then convert it from text to an object. ABNF itself is also written in ABNF, but since this is the first time, it is made only by the builder. If you specify the format of JSON etc., you can create a parser, so if you incorporate a builder-like part that assembles the output parts, it will be completed.
A part of RFC ABNF is summarized in SoftLibRFC, so I will introduce how to use it. All you need is SoftLibRFC, SoftLibABNF, and SoftLib. SoftLib JSON is not used. Currently, only the source code is available, so try using it appropriately.
The class net.siisise.abnf.rfc.IMF5322 is the RFC 5322 almost as it is in the RFC mail ABNF. IMF5322.angleAddr is just right for defining email addresses only. Since the definition is stored in a variable called REG, if it is not made public, it can be taken from there or made public.
boolean b = IMF5322.REG.ref("angle-addr").eq(mail address);
I wonder if it can be judged as boolean. The individual ABNF is an ABNF class. There are methods such as boolean eq (String) exact match and boolean is (String) first match, so please try it. If you combine it with a class called Packet, you can do various things, but this time it is omitted. ABNF can be multiplied and enlarged.
To use all together
You can name and register ABNFReg, and you can also refer to it in the definition. .rule (name, ABNF) and .rule (name, rule) .rule (rule) are all ABNF registrations. .ref (String) and .href (String) bring the ABNF registered by name. Since the relationship of registration order may change, there is a difference whether to fetch unregistered items or not. It is also possible to register multiple definitions at once with .rulelist (String). Line breaks may be needed.
It's strange that JSON will get on as soon as it expands.
SoftLibRFC https://github.com/okomeki/SoftLibRFC SoftLibABNF https://github.com/okomeki/SoftLibABNF SoftLib https://github.com/okomeki/SoftLib RFC 5234 ABNF https://tools.ietf.org/html/rfc5234 RFC 8259 JSON https://tools.ietf.org/html/rfc8259
Recommended Posts