Class ConfigurableParser
java.lang.Object
com.singularsys.jep.configurableparser.ConfigurableParser
- All Implemented Interfaces:
JepComponent
,Parser
,Serializable
- Direct Known Subclasses:
StandardConfigurableParser
A configurable parser.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected final List<TokenFilter>
protected final List<GrammarMatcher>
protected GrammarParserFactory
protected Jep
protected final List<TokenMatcher>
protected OperatorTokenMatcher
protected SymbolTokenMatcher
protected TokenizerFactory
protected Tokenizer
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddArrayAccessMatcher
(String open, String close) Matches array access: a[3]addBracketMatcher
(String open, String close) Matches bracketed expressions: (2+3).Recognize double quote strings "...".Recognize numbers with optional exponents, 1.2e3, 1.2E-3, 1.2, 1.addFunctionMatcher
(String open, String close, String sep) Matches functions: atan2(y,x).Adds a GrammarMatcherRecognize comments of the form #....Adds java-style function and variable names.addListMatcher
(String open, String close, String sep) Matches vectors/list: [1,2,3]addListOrBracketMatcher
(String open, String close, String sep) Matches bracketed expressions or lists depending on number of arguments.Recognize operators.Adds a matcher which will terminate the parsing process when a semicolon is encountered.Recognize numbers without exponents 1.2.Recognize single quote strings '...'.void
Recognize comments of the form //... or /* ... */.addSymbols
(String... symbols) Recognize given set of symbols.Adds a TokenFilter.Adds a TokenMatcher.Recognize java white space characters.Filter out whitespace and comments between the tokenizing and grammar matching stages.Parse the next expressions from existing stream.Filters the tokens to remove whitespace etc.Return the list of GrammarMatchers.Factory used to create GrammarParsersgetJep()
The Jep instance used by the parserReturns a lightweight instance, suitable for use in multiple evaluation threads.Return the OperatorTokenMatcher.getSymbolToken
(String sym) Return the SymbolToken for the given string.Return the SymbolTokenMatcher.Return the list of filters.The factory used to create TokenizersReturn the list of TokenMatchersvoid
Initialize the component.Parse a single equation.Perform the syntax analysis stage.void
Load a new stream to read from.scan()
Scan next equations from an existing stream.Scan the input.void
Sets the GrammarParserFactoryvoid
setImplicitMultiplicationSymbols
(String... symbols) Sets those symbols which can appear on the right-hand side of implicit multiplication.void
Sets the TokenizerFactory used to create Tokenizers.
-
Field Details
-
m
-
filters
-
g
-
tk
-
jep
-
otm
-
stm
-
gpf
-
tf
-
-
Constructor Details
-
ConfigurableParser
public ConfigurableParser()Create a configurable parser with no matchers set.
-
-
Method Details
-
init
Description copied from interface:JepComponent
Initialize the component. This method 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 interfaceJepComponent
- Parameters:
jep1
- the current Jep instance
-
parse
Parse a single equation.- Specified by:
parse
in interfaceParser
- 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
Load a new stream to read from. -
continueParse
Parse the next expressions from existing stream. Empty expressions such as;;
are silently ignored.- Specified by:
continueParse
in interfaceParser
- 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:
-
scan
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
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
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
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 grammatical error in the input
-
getLightWeightInstance
Returns a lightweight instance, suitable for use in multiple evaluation threads. Always returns null.- Specified by:
getLightWeightInstance
in interfaceJepComponent
- Returns:
- null
-
addTokenMatcher
Adds a TokenMatcher.- Parameters:
tm
- the TokenMatcher to add- Returns:
- the TokenMatcher
-
getTokenMatchers
Return the list of TokenMatchers- Returns:
- the list
-
addGrammarMatcher
Adds a GrammarMatcher- Parameters:
gm
- the GrammarMatcher to add- Returns:
- the GrammarMatcher
-
getGrammarMatchers
Return the list of GrammarMatchers.- Returns:
- the list
-
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
Recognize double quote strings "...".- Returns:
- the corresponding matcher.
-
addSingleQuoteStrings
Recognize single quote strings '...'.- Returns:
- the corresponding matcher.
-
addWhiteSpace
Recognize java white space characters.- Returns:
- the corresponding matcher.
-
addWhiteSpaceCommentFilter
Filter out whitespace and comments between the tokenizing and grammar matching stages.- Returns:
- the WhiteSpaceCommentFilter
-
addExponentNumbers
Recognize numbers with optional exponents, 1.2e3, 1.2E-3, 1.2, 1.- Returns:
- the corresponding matcher.
-
addSimpleNumbers
Recognize numbers without exponents 1.2.- Returns:
- the corresponding matcher.
-
addOperatorTokenMatcher
Recognize operators.- Returns:
- the OperatorTokenMatcher.
-
getOperatorTokenMatcher
Return the OperatorTokenMatcher. Note this matcher is only added if addOperatorTokenMatcher() is called.- Returns:
- the OperatorTokenMatcher.
-
addSymbols
Recognize given set of symbols.- Parameters:
symbols
- one or more string for the symbols.- Returns:
- the SymbolTokenMatcher.
-
getSymbolTokenMatcher
Return the SymbolTokenMatcher. Note this matcher is only added if addSymbols() is called.- Returns:
- the SymbolTokenMatcher
-
getSymbolToken
Return the SymbolToken for the given string.- Parameters:
sym
- string representing the symbol.- Returns:
- the corresponding SymbolToken.
-
setImplicitMultiplicationSymbols
Sets those symbols which can appear on the right-hand side of implicit multiplication.- Parameters:
symbols
- one or more string for the symbols.
-
addIdentifiers
Adds java-style function and variable names. These start with A-Z, a-z, or _ and are followed by zero or more alphanumeric characters or _.- Returns:
- the IdentifierTokenMatcher.
-
addSemiColonTerminator
Adds a matcher which will terminate the parsing process when a semicolon is encountered.- Returns:
- the TerminatorTokenMatcher
-
addBracketMatcher
Matches bracketed expressions: (2+3).- Parameters:
open
- symbol for opening braceclose
- symbol for closing brace- Returns:
- the corresponding GrammarMatcher
-
addFunctionMatcher
Matches functions: atan2(y,x).- Parameters:
open
- symbol for opening braceclose
- symbol for closing bracesep
- symbol for argument separator- Returns:
- the corresponding GrammarMatcher
-
addListMatcher
Matches vectors/list: [1,2,3]- Parameters:
open
- symbol for opening braceclose
- symbol for closing bracesep
- symbol for argument separator- Returns:
- the corresponding GrammarMatcher
-
addArrayAccessMatcher
Matches array access: a[3]- Parameters:
open
- symbol for opening braceclose
- symbol for closing brace- Returns:
- the corresponding GrammarMatcher
-
addListOrBracketMatcher
Matches bracketed expressions or lists depending on number of arguments.- Parameters:
open
- symbol for opening braceclose
- symbol for closing bracesep
- symbol for argument separator- Returns:
- the corresponding GrammarMatcher
-
getJep
The Jep instance used by the parser- Returns:
- the instance
- Since:
- 3.4
-
getTokenizerFactory
The factory used to create Tokenizers- Returns:
- the factory
- Since:
- 3.4
-
setTokenizerFactory
Sets the TokenizerFactory used to create Tokenizers.- Parameters:
tf
- factory to use- Since:
- 3.4
-
addTokenFilter
Adds a TokenFilter.- Parameters:
tf1
- the TokenFilter to add- Returns:
- the TokenFilter
-
getTokenFilters
Return the list of filters.- Returns:
- the list
-
getGrammarParserFactory
Factory used to create GrammarParsers- Returns:
- the factory
- Since:
- 3.4
-
setGrammarParserFactory
Sets the GrammarParserFactory- Parameters:
gpf
- the factory- Since:
- 3.4
-