Class ParseOperation

java.lang.Object
org.scijava.parsington.ParseOperation

public class ParseOperation extends Object
A stateful parsing operation.
  • Field Details

    • parser

      protected final ExpressionParser parser
    • expression

      protected final String expression
    • pos

      protected final Position pos
    • stack

      protected final Deque<Object> stack
    • outputQueue

      protected final LinkedList<Object> outputQueue
    • infix

      protected boolean infix
      State 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

  • Method Details

    • parsePostfix

      public LinkedList<Object> parsePostfix()
      Parses the expression into an output queue in Reverse Polish notation (i.e., postfix notation).
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • currentChar

      protected char currentChar()
    • futureChar

      protected char futureChar(int offset)
    • parseWhitespace

      protected void parseWhitespace()
      Skips past any whitespace to the next interesting character.
    • parseLiteral

      protected Object 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

      protected Variable 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 by isIdentifierStart(char) and isIdentifierPart(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

      protected Operator parseOperator()
      Attempts to parse an operator.
      Returns:
      The parsed operator, or null if the next token is not one.
    • parseGroupTerminator

      protected Group parseGroupTerminator()
      Attempts to parse a group terminator symbol.
      Returns:
      The group, or null if the next token is not a group terminator.
    • parseElementSeparator

      protected String parseElementSeparator()
      Attempts to parse an element separator symbol.
      Returns:
      The separator symbol, or null if the next token is not one.
    • parseStatementSeparator

      protected String parseStatementSeparator()
      Attempts to parse a statement separator symbol.
      Returns:
      The separator symbol, or null if the next token is not one.
    • parseChar

      protected Character parseChar(char c)
      Attempts to parse the given character.
      Returns:
      The character, or null if the next token is not that character.
    • parseChars

      protected <CS extends CharSequence> CS parseChars(CS cs)
      Attempts to parse the given characters.
      Returns:
      The characters, or null if the next tokens are not those characters.
    • parseToken

      protected String parseToken(int length)
      Parses a token of the given length.
      Returns:
      The parsed token.