Package snap.parse
Class Parser
java.lang.Object
snap.parse.Parser
- Direct Known Subclasses:
JSParser
,KeyChainParser
,ParseRuleParser
,XMLParser
A class to parse a given input (string) using given rule(s).
-
Nested Class Summary
Modifier 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
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
Clears any currently set tokens.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 ParseRule
Creates the top level rule.protected Tokenizer
Creates the tokenizer instance.int
Returns the current parse char location.getInput()
Returns the current parse character input.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.getRule()
Returns the top level rule.Returns a named rule.getToken()
Returns the current token.Returns the tokenizer.protected void
initRule()
Initializes rule(s).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
(CharSequence anInput, Class<T> aClass) Parses given input and returns custom parse tree node (convenience).<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.void
Sets the top level rule.protected void
setTokenizer
(Tokenizer aTokenizer) Sets the tokenizer.
-
Constructor Details
-
Parser
public Parser()Constructor. -
Parser
Constructor for given rule.
-
-
Method Details
-
getRule
Returns the top level rule. -
setRule
Sets the top level rule. -
createRule
Creates the top level rule. Default version tries to load rules from ClassName.txt. -
initRule
protected void initRule()Initializes rule(s). -
getRule
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. -
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. -
parseCustom
Parses given input and returns custom parse tree node (convenience).
-