Package org.scijava.parsington
Class ParseOperation
java.lang.Object
org.scijava.parsington.ParseOperation
A stateful parsing operation.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final String
protected boolean
State flag for parsing context.protected final LinkedList<Object>
protected final ExpressionParser
protected final Position
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected char
protected char
futureChar
(int offset) protected boolean
isIdentifierPart
(char c) Determines whether the given character is allowed to start an identifier.protected boolean
isIdentifierStart
(char c) Determines whether the given character is allowed to start an identifier.protected Character
parseChar
(char c) Attempts to parse the given character.protected <CS extends CharSequence>
CSparseChars
(CS cs) Attempts to parse the given characters.protected String
Attempts to parse an element separator symbol.protected Group
Attempts to parse a group terminator symbol.protected int
Attempts to parse an identifier, as defined byisIdentifierStart(char)
andisIdentifierPart(char)
.protected Object
Attempts to parse a literal (e.g.protected Operator
Attempts to parse an operator.Parses the expression into an output queue in Reverse Polish notation (i.e., postfix notation).protected String
Attempts to parse a statement separator symbol.protected String
parseToken
(int length) Parses a token of the given length.protected Variable
Attempts to parse a variable.protected void
Skips past any whitespace to the next interesting character.toString()
-
Field Details
-
parser
-
expression
-
pos
-
stack
-
outputQueue
-
infix
protected boolean infixState flag for parsing context.- If true, we are expecting an infix or postfix operator next.
- If false, we are expecting a prefix operator or "noun" token (e.g., variable or literal) next.
-
-
Constructor Details
-
ParseOperation
-
-
Method Details
-
parsePostfix
Parses the expression into an output queue in Reverse Polish notation (i.e., postfix notation). -
toString
-
currentChar
protected char currentChar() -
futureChar
protected char futureChar(int offset) -
parseWhitespace
protected void parseWhitespace()Skips past any whitespace to the next interesting character. -
parseLiteral
Attempts to parse a literal (e.g. boolean, string, or number).- Returns:
- The parsed literal, or null if the next token is not one.
- See Also:
-
parseVariable
Attempts to parse a variable.- Returns:
- The parsed variable name, or null if the next token is not one.
-
parseIdentifier
protected int parseIdentifier()Attempts to parse an identifier, as defined byisIdentifierStart(char)
andisIdentifierPart(char)
.- Returns:
- The length of the parsed identifier, or 0 if the next token is not one.
-
isIdentifierStart
protected boolean isIdentifierStart(char c) Determines whether the given character is allowed to start an identifier.The default implementation uses
Character.isUnicodeIdentifierStart(char)
, but also accepts underscores, since many popular programming languages (e.g. Python and Java) allow identifiers to begin with an underscore symbol. -
isIdentifierPart
protected boolean isIdentifierPart(char c) Determines whether the given character is allowed to start an identifier.The default implementation uses
Character.isUnicodeIdentifierPart(char)
. -
parseOperator
Attempts to parse an operator.- Returns:
- The parsed operator, or null if the next token is not one.
-
parseGroupTerminator
Attempts to parse a group terminator symbol.- Returns:
- The group, or null if the next token is not a group terminator.
-
parseElementSeparator
Attempts to parse an element separator symbol.- Returns:
- The separator symbol, or null if the next token is not one.
-
parseStatementSeparator
Attempts to parse a statement separator symbol.- Returns:
- The separator symbol, or null if the next token is not one.
-
parseChar
Attempts to parse the given character.- Returns:
- The character, or null if the next token is not that character.
-
parseChars
Attempts to parse the given characters.- Returns:
- The characters, or null if the next tokens are not those characters.
-
parseToken
Parses a token of the given length.- Returns:
- The parsed token.
-