Class BracketedRangeSequenceGrammarMatcher

  • All Implemented Interfaces:
    GrammarMatcher, java.io.Serializable

    public class BracketedRangeSequenceGrammarMatcher
    extends java.lang.Object
    implements GrammarMatcher
    A GrammarMatcher which matches lists of items with the syntax [a..b], or a simple list [1,2,3,4]. Differs from ListOrRangeGrammarMatcher as both the sequence operator and range operator are parsed using the standard parser. So 1,2,3,4 is parsed as a single subexpression rather than as four subexpressions.

    The precedence of operator should be: ...; Or "||"; Range ".."; Ternary "?:"; Lambda "=>"; Equals "="; Sequence ","

    A typical setup might be:

                    OperatorTable2 ot = new StandardOperatorTable2();
                    Operator rangeOp = new RangeOperator("..", "[", "]", new Range(), Operator.BINARY);
                    Operator seqOp = new Operator(",", null, Operator.BINARY+Operator.RIGHT);
                    Operator lambdaOp = new Operator("=>", new LambdaFunGenerator(), Operator.BINARY);
                    TernaryOperator ternOp = new TernaryOperator("cond", "?", ":", 
                                    new TernaryConditional(), 
                                    Operator.TERNARY+Operator.NARY+Operator.LEFT);
                                    
                    ot.insertOperator(new OperatorKey() {}, rangeOp, ot.getAssign());
                    ot.insertOperator(new OperatorKey() {}, ternOp,ot.getAssign());
                    ot.insertOperator(new OperatorKey() {}, lambdaOp, ot.getAssign());
                    ot.appendOperator(new OperatorKey() {}, seqOp, ot.getAssign());
    
                    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("(",")"); 
            cp.addGrammarMatcher(new FunctionSequenceGrammarMatcher(
                            cp.getSymbolToken("("),
                            cp.getSymbolToken(")"),
                            seqOp));
            cp.addGrammarMatcher(new BracketedRangeSequenceGrammarMatcher(
                            cp.getSymbolToken("["),
                            cp.getSymbolToken("]"),
                            rangeOp,seqOp
                            )); 
            cp.addArrayAccessMatcher("[","]"); //$NON-NLS-1$ //$NON-NLS-2$
    
            lp = new StandardListProcessor();
                    jep = new Jep(ot,cp, lp);
     
    See Also:
    LambdaFunSeqTest, Serialized Form
    • Constructor Detail

      • BracketedRangeSequenceGrammarMatcher

        public BracketedRangeSequenceGrammarMatcher​(Token open,
                                                    Token close,
                                                    Operator rangeOp,
                                                    Operator seqOp)
        Create a ListGrammarMatcher
        Parameters:
        open - token representing an opening bracket
        close - token representing a closing bracket
        rangeOp - operator representing the range
        seqOp - operator representing sequences
    • 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 interface GrammarMatcher
        Parameters:
        jep - the current jep instance.
      • match

        public Node match​(Lookahead2Iterator<Token> it,
                          GrammarParser parser)
                   throws ParseException
        Description copied from interface: GrammarMatcher
        Test whether the input matches this pattern.
        Specified by:
        match in interface GrammarMatcher
        Parameters:
        it - An iterator inspecting the input
        parser - 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.