Package net.diversionmc.parser
Class Parser<T extends Sentence>
java.lang.Object
net.diversionmc.parser.Parser<T>
- Type Parameters:
T- Parsed text output sentence type.
Parser - convert any written language into custom format
- Author:
- Kirill Semyonkin - Diversion Network 2021
-
Constructor Summary
ConstructorsConstructorDescriptionParser()Create Parser without any input attached and automatically set name.Create Parser from a file.Create Parser with a title.Parser(String name, InputStream is) Create Parser from an input stream with a title.Create Parser of a text with a title. -
Method Summary
Modifier and TypeMethodDescriptionbuild()Convert input text into a list of usable sentences.end()Get file pointer pointing to the end of the file (line += 1, column = 1).<L extends ExpressionPiece,R extends ExpressionPiece>
Parser<T>group(Predicate<ExpressionPiece> left, Predicate<ExpressionPiece> right, GroupSupplier<L, R> supplier) Create a grouper for specific pieces.name()Get title used on creation of this parser.parser()Create Parser without any input attached and automatically set name.Create Parser from a file.Create Parser of a text with a title.parser(String name, InputStream is) Create Parser from an input stream with a title.Create Parser of a text with a title.Get a pattern that was already added to this parser.pattern(String id, ParsePattern<T> pattern) Add a piece to sentence converter.ParsePattern<T>[]patterns()Get all patterns that were added to this parser.piece(PiecePredicate check, PieceSupplier supplier) Add a parse piece.piece(PieceSupplier supplier) Add a parse piece that is always accepted.pieceFinish(Consumer<ExpressionPiece> event) Add an action to run after a piece is completed.Set the first action to perform onbuild()before starting to parse text.Set text to parse from a file, as well as text title.readFrom(InputStream is) Set text to parse from a stream.text()Get text that was inputted into this Parser.Set text to parse.
-
Constructor Details
-
Parser
public Parser()Create Parser without any input attached and automatically set name. -
Parser
Create Parser with a title.- Parameters:
name- Text title; usually filename.
-
Parser
Create Parser of a text with a title.- Parameters:
name- Text title; usually filename.text- Input text to parse.
-
Parser
Create Parser from an input stream with a title.- Parameters:
name- Text title; usually filename.is- Input stream to get text from to parse.- Throws:
IOException- If stream reading error occurs.
-
Parser
Create Parser from a file.- Parameters:
f- File to parse.- Throws:
IOException- If file reading error occurs.
-
-
Method Details
-
parser
Create Parser without any input attached and automatically set name.- Type Parameters:
T- Parsed text output sentence type.- Returns:
Parser()
-
parser
Create Parser of a text with a title.- Type Parameters:
T- Parsed text output sentence type.- Parameters:
name- Text title; usually filename.- Returns:
Parser(String)
-
parser
Create Parser of a text with a title.- Type Parameters:
T- Parsed text output sentence type.- Parameters:
name- Text title; usually filename.text- Input text to parse.- Returns:
Parser(String, String)
-
parser
Create Parser from an input stream with a title.- Type Parameters:
T- Parsed text output sentence type.- Parameters:
name- Text title; usually filename.is- Input stream to get text from to parse.- Returns:
Parser(String, InputStream)- Throws:
IOException- If stream reading error occurs.
-
parser
Create Parser from a file.- Type Parameters:
T- Parsed text output sentence type.- Parameters:
f- File to parse.- Returns:
Parser(File)- Throws:
IOException- If file reading error occurs.
-
name
Get title used on creation of this parser. If title was not specified, it isObject.hashCode().- Returns:
- Text title; usually filename.
-
text
Get text that was inputted into this Parser.- Returns:
- Input text to parse.
-
text
Set text to parse.- Parameters:
text- Input text to parse.
-
readFrom
Set text to parse from a file, as well as text title.- Parameters:
f- File to parse.- Throws:
IOException- If file reading error occurs.
-
readFrom
Set text to parse from a stream.- Parameters:
is- Input stream to get text from to parse.- Throws:
IOException- If stream reading error occurs.
-
end
Get file pointer pointing to the end of the file (line += 1, column = 1).- Returns:
- End file pointer.
-
pre
Set the first action to perform onbuild()before starting to parse text.- Parameters:
pre- Action to run.
-
piece
Add a parse piece that is always accepted.- Parameters:
supplier- Piece supplier, null is same as not accepting a piece.
-
piece
Add a parse piece.- Parameters:
check- Check whether the piece is acceptable for a character at a position.supplier- Piece supplier, null is same as not accepting a piece.
-
pieceFinish
Add an action to run after a piece is completed.- Parameters:
event- Action to run.
-
group
public <L extends ExpressionPiece,R extends ExpressionPiece> Parser<T> group(Predicate<ExpressionPiece> left, Predicate<ExpressionPiece> right, GroupSupplier<L, R> supplier) Create a grouper for specific pieces.- Type Parameters:
L- Opening piece type.R- Closing piece type.- Parameters:
left- Group opening piece.right- Group closing piece.supplier- Group creator.
-
pattern
Add a piece to sentence converter.- Parameters:
id- Name of the pattern.pattern- The pattern.
-
pattern
Get a pattern that was already added to this parser.- Parameters:
id- Name of the pattern.
-
patterns
Get all patterns that were added to this parser.- Returns:
- Array of the patterns to use in matchOne().
-
build
Convert input text into a list of usable sentences.- Returns:
- List of sentences.
-