Class ExpressionPiece
java.lang.Object
net.diversionmc.parser.util.Pointable
net.diversionmc.parser.expression.ExpressionPiece
- Direct Known Subclasses:
CharPiece,CommentPiece,GroupPiece,NamePiece,NumberPiece,StringPiece
public abstract class ExpressionPiece extends Pointable
Expression Pieces are the units of the text format. They represent single characters or sequences of characters digested into structural form by first parsing pass.
A piece usually features a PiecePredicate determining which piece type
should start processing at a current point in file given a character.
There must be only one valid piece type at a given point.
Piece never starts with a whitespace character (space, tab, newline, etc),
when there is no currently set piece, the whitespace characters are skipped.
-
Constructor Summary
Constructors Constructor Description ExpressionPiece(FilePointer ptr)Construct a piece at a position. -
Method Summary
Modifier and Type Method Description abstract PieceResultread(char c, FilePointer ptr)Parse a character by this piece.ExpressionPiecereplace(FilePointer ptr)Called wheneverPieceResult.REPLACE_LEAVEorPieceResult.REPLACE_TAKEare used.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
ExpressionPiece
Construct a piece at a position.- Parameters:
ptr- Creation position.
-
-
Method Details
-
read
Parse a character by this piece.- Parameters:
c- Character to parse.ptr- Character position in file.- Returns:
PieceResult
-
replace
Called wheneverPieceResult.REPLACE_LEAVEorPieceResult.REPLACE_TAKEare used.- Parameters:
ptr- Position when replace was used.- Returns:
- Another piece to continue parsing with, or null to discard current piece.
-