Class FunctionSequenceGrammarMatcher
- java.lang.Object
-
- com.singularsys.jep.configurableparser.matchers.FunctionSequenceGrammarMatcher
-
- All Implemented Interfaces:
GrammarMatcher
,java.io.Serializable
public class FunctionSequenceGrammarMatcher extends java.lang.Object implements GrammarMatcher
A GrammarMatcher which matches functions in the formatan2(seq)
whereseq
is a sequence of terms. This differs fromFunctionGrammarMatcher
in that the sequence operator (usually ",") is treated like a normal operator and parsed in the main ShuntingYard class. So arguments1,2,3,4
is parsed as a single subexpression rather than as four subexpressions. The function must be in the FunctionTable and brackets are required.To set up first a new sequence operator must be created. This should be a binary operator with right associativity. It should have a precedence level lower than all other operators. This operator should be passed to the constructor of the FunctionSequenceGrammarMatcher and possibly also the BracketedSequenceGrammarMatcher.
OperatorTable2 ot = new StandardOperatorTable2(); Operator seqOp = new Operator(",", null, Operator.BINARY+Operator.RIGHT); ot.appendOperator(new OperatorKey() {}, seqOp, optab.getAssign()); // lower precedence than assignment ConfigurableParser cp = new ConfigurableParser(); cp.addHashComments(); cp.addSlashComments(); cp.addSingleQuoteStrings(); cp.addDoubleQuoteStrings(); cp.addWhiteSpace(); cp.addExponentNumbers(); cp.addSymbols("(",")","[","]"); cp.setImplicitMultiplicationSymbols("(","["); cp.addOperatorTokenMatcher(); cp.addIdentifiers(); cp.addSemiColonTerminator(); cp.addWhiteSpaceCommentFilter(); cp.addBracketMatcher("(",")"); // Add the function matcher cp.addGrammarMatcher(new FunctionSequenceGrammarMatcher( cp.getSymbolToken("("), cp.getSymbolToken(")"), seqOp)); // Add the bracket matcher cp.addGrammarMatcher(new BracketedSequenceGrammarMatcher( cp.getSymbolToken("["), cp.getSymbolToken("]"), seqOp )); cp.addArrayAccessMatcher("[","]"); Jep jep = new Jep(ot,cp);
-
-
Constructor Summary
Constructors Constructor Description FunctionSequenceGrammarMatcher(Token open, Token close, Operator seqOp)
Create a FunctionGrammarMatcher
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
buildList(Node top, java.util.List<Node> seq)
protected Token
errorToken(Lookahead2Iterator<Token> it)
Generate a token to use in GrammarExecptionsvoid
init(Jep jep)
Delayed initialisation, this methods is called whenever components of the jep instance are changed.Node
match(Lookahead2Iterator<Token> it, GrammarParser parser)
Attempt to match a function, calls the GrammarParser.parseSubExpression() to match function arguments.
-
-
-
Method Detail
-
init
public void init(Jep jep)
Description copied from interface:GrammarMatcher
Delayed initialisation, this methods is called whenever components of the jep instance are changed.- Specified by:
init
in interfaceGrammarMatcher
- Parameters:
jep
- the current jep instance.
-
errorToken
protected Token errorToken(Lookahead2Iterator<Token> it)
Generate a token to use in GrammarExecptions- Parameters:
it
- used to get current position- Returns:
- a TerminatorToken
-
match
public Node match(Lookahead2Iterator<Token> it, GrammarParser parser) throws ParseException
Attempt to match a function, calls the GrammarParser.parseSubExpression() to match function arguments.- Specified by:
match
in interfaceGrammarMatcher
- Parameters:
it
- An iterator inspecting the inputparser
- the parser to use when evaluating sub expressions- Returns:
- if matched returns a node representing the content, return null is does not match
- Throws:
ParseException
- if there is a syntactical error in the input.
-
-