Class Parser
- java.lang.Object
-
- com.inductiveautomation.snap.parse.Parser
-
- Direct Known Subclasses:
JavaParser,ParseUtils.DebugParser
public class Parser extends java.lang.ObjectA class to parse a given input (string) using given rule(s).
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ParseNodecreateNode(ParseRule aRule, Token aStartToken, Token anEndToken)Creates a node for given rule and start/end tokens (returns a shared node by default).protected ParseRulecreateRule()Creates the top level rule.protected TokenizercreateTokenizer()Creates the tokenizer instance and initializes patters from rule.protected TokenizercreateTokenizerImpl()Creates the tokenizer instance.java.lang.CharSequencegetInput()Returns the current parse character input.protected TokengetLookAheadToken(int anIndex)Returns the look ahead token at given index.protected TokengetNextToken()Fetches and returns the next token.ParseRulegetRule()Returns the top level rule.TokengetToken()Returns the current token.TokenizergetTokenizer()Returns the tokenizer.protected intlookAhead(ParseRule aRule, int aLookAhead, int aTokenIndex, int aPathIndex, int aRuleIndex)Returns a parse node if this rule matches string.ParseNodeparse()Parses input and returns ParseNode.protected ParseNodeparse(ParseRule aRule, ParseHandler aHandler)Returns a parse node if this rule matches string.ParseNodeparse(java.lang.CharSequence anInput)Parses a given input and returns ParseNode (convenience).<T> TparseCustom(java.lang.CharSequence anInput, java.lang.Class<T> aClass)Parses given input and returns custom parse tree node (convenience).<T> TparseCustom(java.lang.Class<T> aClass)Parses input and returns custom parse tree node.protected voidparseFailed(ParseRule aRule, ParseHandler aHandler, ParseRule.Count aCount)Called when parse fails.ParsersetInput(java.lang.CharSequence aSequence)Sets the current parse string.voidsetRule(ParseRule aRule)Sets the top level rule.protected voidsetTokenizer(Tokenizer aTokenizer)Sets the tokenizer.
-
-
-
Constructor Detail
-
Parser
public Parser()
Creates a new Parser.
-
Parser
public Parser(ParseRule aRule)
Creates a new Parser for given rule.
-
-
Method Detail
-
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 java.lang.CharSequence getInput()
Returns the current parse character input.
-
setInput
public Parser setInput(java.lang.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(java.lang.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(java.lang.CharSequence anInput)
Parses a given input and returns ParseNode (convenience).
-
parseCustom
public <T> T parseCustom(java.lang.CharSequence anInput, java.lang.Class<T> aClass)Parses given input and returns custom parse tree node (convenience).
-
-