Class ConfigurableParser

    • Constructor Detail

      • ConfigurableParser

        public ConfigurableParser()
        Create a configurable parser with no matchers set.
    • Method Detail

      • init

        public void init​(Jep jep1)
        Description copied from interface: JepComponent
        Initialize the component. This methods is called whenever a component is added to Jep. Hence it allows components to keep track of the other components they may rely on.
        Specified by:
        init in interface JepComponent
        Parameters:
        jep1 - the current Jep instance
      • parse

        public Node parse​(java.io.Reader stream)
                   throws ParseException
        Parse a single equation.
        Specified by:
        parse in interface Parser
        Parameters:
        stream - the input stream to read from
        Returns:
        top node of the expression
        Throws:
        ParseException - if there is a syntax error in the input or an empty expression
      • restart

        public void restart​(java.io.Reader stream)
        Load a new stream to read from.
        Specified by:
        restart in interface Parser
        Parameters:
        stream - input stream
        See Also:
        continueParse()
      • continueParse

        public Node continueParse()
                           throws ParseException
        Parse the next expressions from existing stream. Empty expressions such as ;; are silently ignored.
        Specified by:
        continueParse in interface Parser
        Returns:
        top node of the expression or null at end of file
        Throws:
        ParseException - if there is a syntax error in the input
        See Also:
        restart(java.io.Reader)
      • scan

        public java.util.List<Token> scan​(java.io.Reader stream)
                                   throws ParseException
        Scan the input. Just perform the tokenizing stage. Not for normal use.
        Parameters:
        stream - input
        Returns:
        a list of tokens, including white space and comments, null at end of input. An empty list is returned for empty equations.
        Throws:
        ParseException - if there is a syntax error in the input
      • scan

        public java.util.List<Token> scan()
                                   throws ParseException
        Scan next equations from an existing stream. Not for normal use.
        Returns:
        List of tokens, including white space and comments, null at end of input. An empty list is returned for empty equations.
        Throws:
        ParseException - if there is a syntax error in the input
      • filter

        public java.util.Iterator<Token> filter​(java.util.List<Token> input)
                                         throws ParseException
        Filters the tokens to remove whitespace etc. Not for normal use.
        Parameters:
        input - list of tokens
        Returns:
        and iterator with the filtered tokens
        Throws:
        ParseException - if there is a syntax error in the input
      • parse

        public Node parse​(java.util.Iterator<Token> it)
                   throws ParseException
        Perform the syntax analysis stage. Not for normal used.
        Parameters:
        it - an iterator with a list of tokens
        Returns:
        top node of the parsed expression
        Throws:
        ParseException - if there is a gramatical error in the input
      • getLightWeightInstance

        public JepComponent getLightWeightInstance()
        Returns a light weight instance, suitable for use in multiple evaluation threads. Always returns null.
        Specified by:
        getLightWeightInstance in interface JepComponent
        Returns:
        null
      • addTokenMatcher

        public TokenMatcher addTokenMatcher​(TokenMatcher tm)
        Adds a TokenMatcher.
        Parameters:
        tm - the TokenMatcher to add
        Returns:
        the TokenMatcher
      • getTokenMatchers

        public java.util.List<TokenMatcher> getTokenMatchers()
        Return the list of TokenMatchers
        Returns:
        the list
      • addGrammarMatcher

        public GrammarMatcher addGrammarMatcher​(GrammarMatcher gm)
        Adds a GrammarMatcher
        Parameters:
        gm - the GrammarMatcher to add
        Returns:
        the GrammarMatcher
      • getGrammarMatchers

        public java.util.List<GrammarMatcher> getGrammarMatchers()
        Return the list of GrammarMatchers.
        Returns:
        the list
      • addHashComments

        public TokenMatcher addHashComments()
        Recognize comments of the form #....
        Returns:
        the corresponding matcher.
      • addSlashComments

        public void addSlashComments()
        Recognize comments of the form //...  or /* ... */. Does not return a given matcher.
      • addDoubleQuoteStrings

        public TokenMatcher addDoubleQuoteStrings()
        Recognize double quote strings "...".
        Returns:
        the corresponding matcher.
      • addSingleQuoteStrings

        public TokenMatcher addSingleQuoteStrings()
        Recognize single quote strings '...'.
        Returns:
        the corresponding matcher.
      • addWhiteSpace

        public TokenMatcher addWhiteSpace()
        Recognize java white space characters.
        Returns:
        the corresponding matcher.
      • addWhiteSpaceCommentFilter

        public TokenFilter addWhiteSpaceCommentFilter()
        Filter out whitespace and comments between the tokenizing and grammar matching stages.
        Returns:
        the WhiteSpaceCommentFilter
      • addExponentNumbers

        public TokenMatcher addExponentNumbers()
        Recognize numbers with optional exponents, 1.2e3, 1.2E-3, 1.2, 1.
        Returns:
        the corresponding matcher.
      • addSimpleNumbers

        public TokenMatcher addSimpleNumbers()
        Recognize numbers without exponents 1.2.
        Returns:
        the corresponding matcher.
      • addOperatorTokenMatcher

        public TokenMatcher addOperatorTokenMatcher()
        Recognize operators.
        Returns:
        the OperatorTokenMatcher.
      • getOperatorTokenMatcher

        public TokenMatcher getOperatorTokenMatcher()
        Return the OperatorTokenMatcher. Note this matcher is only added if addOperatorTokenMatcher() is called.
        Returns:
        the OperatorTokenMatcher.
      • addSymbols

        public TokenMatcher addSymbols​(java.lang.String... symbols)
        Recognize given set of symbols.
        Parameters:
        symbols - one or more string for the symbols.
        Returns:
        the SymbolTokenMatcher.
      • getSymbolTokenMatcher

        public SymbolTokenMatcher getSymbolTokenMatcher()
        Return the SymbolTokenMatcher. Note this matcher is only added if addSymbols() is called.
        Returns:
        the SymbolTokenMatcher
      • getSymbolToken

        public SymbolToken getSymbolToken​(java.lang.String sym)
        Return the SymbolToken for the given string.
        Parameters:
        sym - string representing the symbol.
        Returns:
        the corresponding SymbolToken.
      • setImplicitMultiplicationSymbols

        public void setImplicitMultiplicationSymbols​(java.lang.String... symbols)
        Sets those symbols which can appear on the right hand side of implicit multiplication.
        Parameters:
        symbols - one or more string for the symbols.
      • addIdentifiers

        public TokenMatcher addIdentifiers()
        Adds java-style function and variable names. These start with A-Z, a-z, or _ and are followed by zero or more alpha-numeric characters or _.
        Returns:
        the IdentifierTokenMatcher.
      • addSemiColonTerminator

        public TokenMatcher addSemiColonTerminator()
        Adds a matcher which will terminate the parsing process when a semi-colon is encountered.
        Returns:
        the TerminatorTokenMatcher
      • addBracketMatcher

        public GrammarMatcher addBracketMatcher​(java.lang.String open,
                                                java.lang.String close)
        Matches bracketed expressions: (2+3).
        Parameters:
        open - symbol for opening brace
        close - symbol for closing brace
        Returns:
        the corresponding GrammarMatcher
      • addFunctionMatcher

        public GrammarMatcher addFunctionMatcher​(java.lang.String open,
                                                 java.lang.String close,
                                                 java.lang.String sep)
        Matches functions: atan2(y,x).
        Parameters:
        open - symbol for opening brace
        close - symbol for closing brace
        sep - symbol for argument separator
        Returns:
        the corresponding GrammarMatcher
      • addListMatcher

        public GrammarMatcher addListMatcher​(java.lang.String open,
                                             java.lang.String close,
                                             java.lang.String sep)
        Matches vectors/list: [1,2,3]
        Parameters:
        open - symbol for opening brace
        close - symbol for closing brace
        sep - symbol for argument separator
        Returns:
        the corresponding GrammarMatcher
      • addArrayAccessMatcher

        public GrammarMatcher addArrayAccessMatcher​(java.lang.String open,
                                                    java.lang.String close)
        Matches array access: a[3]
        Parameters:
        open - symbol for opening brace
        close - symbol for closing brace
        Returns:
        the corresponding GrammarMatcher
      • addListOrBracketMatcher

        public GrammarMatcher addListOrBracketMatcher​(java.lang.String open,
                                                      java.lang.String close,
                                                      java.lang.String sep)
        Matches bracketed expressions or lists depending on number of arguments.
        Parameters:
        open - symbol for opening brace
        close - symbol for closing brace
        sep - symbol for argument separator
        Returns:
        the corresponding GrammarMatcher
      • getJep

        public Jep getJep()
        The Jep instance used by the parser
        Returns:
        the instance
        Since:
        3.4
      • getTokenizerFactory

        public TokenizerFactory getTokenizerFactory()
        The factory used to create Tokenizers
        Returns:
        the factory
        Since:
        3.4
      • setTokenizerFactory

        public void setTokenizerFactory​(TokenizerFactory tf)
        Sets the TokenizerFactory used to create Tokenizers.
        Parameters:
        tf - factory to use
        Since:
        3.4
      • addTokenFilter

        public TokenFilter addTokenFilter​(TokenFilter tf1)
        Adds a TokenFilter.
        Parameters:
        tf1 - the TokenFilter to add
        Returns:
        the TokenFilter
      • getTokenFilters

        public java.util.List<TokenFilter> getTokenFilters()
        Return the list of filters.
        Returns:
        the list
      • getGrammarParserFactory

        public GrammarParserFactory getGrammarParserFactory()
        Factory used to create GrammarParsers
        Returns:
        the factory
        Since:
        3.4
      • setGrammarParserFactory

        public void setGrammarParserFactory​(GrammarParserFactory gpf)
        Sets the GrammarParserFactory
        Parameters:
        gpf - the factory
        Since:
        3.4