Class Parser

java.lang.Object
com.inductiveautomation.snap.parse.Parser
Direct Known Subclasses:
JavaParser, ParseUtils.DebugParser

public class Parser extends Object
A class to parse a given input (string) using given rule(s).
  • Constructor Details

    • Parser

      public Parser()
      Creates a new Parser.
    • Parser

      public Parser(ParseRule aRule)
      Creates a new Parser for given rule.
  • Method Details

    • getRule

      public ParseRule getRule()
      Returns the top level rule.
    • setRule

      public void setRule(ParseRule aRule)
      Sets the top level rule.
    • createRule

      protected ParseRule createRule()
      Creates the top level rule.
    • getInput

      public CharSequence getInput()
      Returns the current parse character input.
    • setInput

      public Parser setInput(CharSequence aSequence)
      Sets the current parse string.
    • getTokenizer

      public Tokenizer getTokenizer()
      Returns the tokenizer.
    • createTokenizer

      protected Tokenizer createTokenizer()
      Creates the tokenizer instance and initializes patters from rule.
    • createTokenizerImpl

      protected Tokenizer createTokenizerImpl()
      Creates the tokenizer instance.
    • setTokenizer

      protected void setTokenizer(Tokenizer aTokenizer)
      Sets the tokenizer.
    • getToken

      public Token getToken()
      Returns the current token.
    • getNextToken

      @Nonnull protected Token getNextToken()
      Fetches and returns the next token.
    • getLookAheadToken

      protected Token getLookAheadToken(int anIndex)
      Returns the look ahead token at given index.
    • parse

      public ParseNode parse()
      Parses input and returns ParseNode.
    • parseCustom

      public <T> T parseCustom(Class<T> aClass)
      Parses input and returns custom parse tree node.
    • parse

      protected ParseNode parse(ParseRule aRule, ParseHandler aHandler)
      Returns a parse node if this rule matches string.
    • createNode

      protected ParseNode createNode(ParseRule aRule, Token aStartToken, Token anEndToken)
      Creates a node for given rule and start/end tokens (returns a shared node by default).
    • lookAhead

      protected int lookAhead(ParseRule aRule, int aLookAhead, int aTokenIndex, int aPathIndex, int aRuleIndex)
      Returns a parse node if this rule matches string.
    • parseFailed

      protected void parseFailed(ParseRule aRule, ParseHandler aHandler, ParseRule.Count aCount)
      Called when parse fails.
    • parse

      public ParseNode parse(CharSequence anInput)
      Parses a given input and returns ParseNode (convenience).
    • parseCustom

      public <T> T parseCustom(CharSequence anInput, Class<T> aClass)
      Parses given input and returns custom parse tree node (convenience).