Class ProductionRule
- java.lang.Object
-
- org.vedantatree.expressionoasis.grammar.rules.ProductionRule
-
- All Implemented Interfaces:
IProductionRule
public class ProductionRule extends Object implements IProductionRule
This class provides the production rule based on regular expression. It uses the regular expression to define a production rule.
-
-
Constructor Summary
Constructors Constructor Description ProductionRule(String name, String regularExpression)
Constructs the ProductionRuleProductionRule(String name, String approachableRegex, String allowedRegex)
Constructs the ProductionRule
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getName()
Returns the name of production rule.boolean
isAllowed(String token)
Checks whether the token is allowed or not.boolean
isApproaching(String pattern)
Checks whether the given token is approachable using any of the pattern or not.
-
-
-
Constructor Detail
-
ProductionRule
public ProductionRule(String name, String regularExpression)
Constructs the ProductionRule- Parameters:
name
- name of the production ruleregularExpression
- regular expression, will be used as approachable and allowed regular expression- Throws:
IllegalArgumentException
- if the parameters are not valid
-
ProductionRule
public ProductionRule(String name, String approachableRegex, String allowedRegex)
Constructs the ProductionRule- Parameters:
name
- name of the production ruleapproachableRegex
- Regular Expression for checking the approachable tokenallowedRegex
- Expression for checking the approachable token- Throws:
IllegalArgumentException
- if the parameters are not valid
-
-
Method Detail
-
getName
public String getName()
Description copied from interface:IProductionRule
Returns the name of production rule.- Specified by:
getName
in interfaceIProductionRule
- Returns:
- the name of production rule
- See Also:
IProductionRule.getName()
-
isApproaching
public boolean isApproaching(String pattern)
Description copied from interface:IProductionRule
Checks whether the given token is approachable using any of the pattern or not. Given token can be partially or fully constructed token during parsing process. Parser/DefaultXMLGrammar generally calls this method to check whether the current token can be combined with next character of expression to form some meaningful token or not. If not, then it utilize the existing collected characters as one token, otherwise it keep collecting characters.- Specified by:
isApproaching
in interfaceIProductionRule
- Returns:
true
if the token pattern is approachablefalse
otherwise.- See Also:
IProductionRule.isApproaching(java.lang.String)
-
isAllowed
public boolean isAllowed(String token)
Description copied from interface:IProductionRule
Checks whether the token is allowed or not. A token is fully constructed token. DefaultXMLGrammar/Parser generally calls this method to check whether the current token is a valid token as per the production rules or not.- Specified by:
isAllowed
in interfaceIProductionRule
- Parameters:
token
- the token which is to be checked for its validity- Returns:
true
if the token is allowedfalse
otherwise.- See Also:
IProductionRule.isAllowed(java.lang.String)
-
-