Package snap.parse

Class Parser

java.lang.Object
snap.parse.Parser
Direct Known Subclasses:
JSParser, KeyChainParser, ParseRuleParser, XMLParser

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

    • Parser

      public Parser()
      Constructor.
    • Parser

      public Parser(ParseRule aRule)
      Constructor 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. Default version tries to load rules from ClassName.txt.
    • initRule

      protected void initRule()
      Initializes rule(s).
    • getRule

      public ParseRule getRule(String aName)
      Returns a named rule.
    • getInput

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

      public void setInput(CharSequence aSequence)
      Sets the current parse string.
    • getCharIndex

      public int getCharIndex()
      Returns the current parse char location.
    • setCharIndex

      public void setCharIndex(int aLoc)
      Sets the current parse location.
    • getTokenizer

      public Tokenizer getTokenizer()
      Returns the tokenizer.
    • createTokenizer

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

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

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

      protected ParseToken getNextToken()
      Fetches and returns the next token.
    • getLookAheadToken

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

      public ParseToken getLastValidToken()
      Returns the last successfully parsed token.
    • clearTokens

      protected void clearTokens()
      Clears any currently set tokens.
    • parse

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

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

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

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

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

      protected ParseNode parse(ParseRule aRule, Parser.HandlerRef aHRef)
      Returns a parse node if this rule matches string.
    • lookAhead

      protected int lookAhead(ParseRule aRule, int aTokenCount, int aTokenIndex)
      Looks ahead given number of tokens and returns the remainder or -1 if it fails.
    • createNode

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

      protected void parseFailed(ParseRule aRule, ParseHandler<?> aHandler)
      Called when parse fails.
    • parseCustom

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