Write ABNF in Java and pass the email address

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

Write ABNF in Java and pass the email address
Have the surname and given name entered separately and combine them before saving
Write ABNF in Java and pass the email address
Regarding the transient modifier and serialization in Java
Write a class in Kotlin and call it in Java
Java classes and instances to understand in the figure
Write flyway callbacks in Java
Implement Email Sending in Java
Write Java8-like code in Java8
Find the address class and address type from the IP address with Java
JSON in Java and Jackson Part 1 Return JSON from the server
Correct the character code in Java and read from the URL
Define abstract methods in Java enum and write each behavior
Think about the differences between functions and methods (in Java)
How to write comments in the schema definition file in GraphQL Java and reflect them in GraphQL and GraphQL Playground
Access the network interface in Java
I sent an email in Java
Guess the character code in Java
Pass the i18n locale to JavaScript
[Java] Get the dates of the past Monday and Sunday in order
Encoding and Decoding example in Java
Specify the java location in eclipse.ini
Unzip the zip file in Java
StringBuffer and StringBuilder Class in Java
Write keys and values in Ruby
Java pass by value and pass by reference
Parsing the COTOHA API in Java
Understanding equals and hashCode in Java
Sample to read and write LibreOffice Calc fods file in Java 2021
Hello world in Java and Gradle
Call the super method in Java
Find the address class and address type from the IP address with Java [No. 2 decoction]
Web application structure by Java and processing flow in the presentation layer
Specify the order in which configuration files and classes are loaded in Java
The story of forgetting to close a file in Java and failing
A note on the differences between interfaces and abstract classes in Java
[Java] Write the programming quiz SET INTERSECTION in one line with StreamAPI
This and that of the implementation of date judgment within the period in Java
I want to get the IP address when connecting to Wi-Fi in Java
Find the maximum and minimum of the five numbers you entered in Java
<java> Split the address before and after the street address with a regular expression
Check the domain by checking the MX record of the email address with java
Understand the difference between int and Integer and BigInteger in java and float and double
How to create your own annotation in Java and get the value
Get the result of POST in Java
Difference between final and Immutable in Java
Java reference to understand in the figure
Try using the Stream API in Java
Call the Windows Notification API in Java
Java SE8 Silver ~ The Road to Pass ~
I tried the new era in Java
[Java] for Each and sorted in Lambda
[Java] Use cryptography in the standard library
Organized memo in the head (Java --Array)
[Java] How to output and write files!
Try calling the CORBA service in Java 11+
Verify the uniqueness of your email address
What is the main method in Java?
How to get the date in java
[Java 7] Divide the Java list and execute the process
Arrylist and linked list difference in java
Program PDF headers and footers in Java