Package snap.parse
Class Parser
java.lang.Object
snap.parse.Parser
- Direct Known Subclasses:
GrammarParser
,JSParser
,KeyChainParser
,XMLParser
A class to parse a given input (string) using given rule(s).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
A class to pass Handler by reference, allowing it to be created lazily, but used higher up in stack. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Clears any currently set tokens.protected Grammar
Creates the grammar.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).protected Tokenizer
Creates the tokenizer instance.int
Returns the current parse char location.Returns the grammar.getInput()
Returns the current parse character input.Returns the last token that was parsed or attempted to parse.Returns the last successfully parsed token.protected ParseToken
getLookAheadToken
(int anIndex) Returns the look ahead token at given index.protected ParseToken
Fetches and returns the next token.Returns the primary rule.getRuleForName
(String aName) Returns a named rule.getToken()
Returns the current token.Returns the tokenizer.protected void
Initializes grammar.protected int
Looks ahead given number of tokens and returns the remainder or -1 if it fails.parse()
Parses input and returns ParseNode.parse
(CharSequence anInput) Parses a given input and returns ParseNode (convenience).Parses input and returns ParseNode.protected ParseNode
parse
(ParseRule aRule, Parser.HandlerRef aHRef) Returns a parse node if this rule matches string.<T> T
parseCustom
(Class<T> aClass) Parses input and returns custom parse tree node.<T> T
parseCustom
(ParseRule aRule, Class<T> aClass) Parses input and returns custom parse tree node.protected void
parseFailed
(ParseRule aRule, ParseHandler<?> aHandler) Called when parse fails.void
setCharIndex
(int aLoc) Sets the current parse location.void
setInput
(CharSequence aSequence) Sets the current parse string.protected void
setTokenizer
(Tokenizer aTokenizer) Sets the tokenizer.
-
Constructor Details
-
Parser
public Parser()Constructor.
-
-
Method Details
-
getGrammar
Returns the grammar. -
createGrammar
Creates the grammar. -
initGrammar
protected void initGrammar()Initializes grammar. -
getPrimaryRule
Returns the primary rule. -
getRuleForName
Returns a named rule. -
getInput
Returns the current parse character input. -
setInput
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
Returns the tokenizer. -
createTokenizer
Creates the tokenizer instance. -
setTokenizer
Sets the tokenizer. -
getToken
Returns the current token. -
getNextToken
Fetches and returns the next token. -
getLookAheadToken
Returns the look ahead token at given index. -
getLastValidToken
Returns the last successfully parsed token. -
getLastProcessedToken
Returns the last token that was parsed or attempted to parse. -
clearTokens
protected void clearTokens()Clears any currently set tokens. -
parse
Parses a given input and returns ParseNode (convenience). -
parse
Parses input and returns ParseNode. -
parse
Parses input and returns ParseNode. -
parseCustom
Parses input and returns custom parse tree node. -
parseCustom
Parses input and returns custom parse tree node. -
parse
Returns a parse node if this rule matches string. -
lookAhead
Looks ahead given number of tokens and returns the remainder or -1 if it fails. -
createNode
Creates a node for given rule and start/end tokens (returns a shared node by default). -
parseFailed
Called when parse fails.
-