Class 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 Detail

      • ProductionRule

        public ProductionRule​(String name,
                              String regularExpression)
        Constructs the ProductionRule
        Parameters:
        name - name of the production rule
        regularExpression - 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 rule
        approachableRegex - Regular Expression for checking the approachable token
        allowedRegex - Expression for checking the approachable token
        Throws:
        IllegalArgumentException - if the parameters are not valid
    • Method Detail

      • 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 interface IProductionRule
        Returns:
        true if the token pattern is approachable false 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 interface IProductionRule
        Parameters:
        token - the token which is to be checked for its validity
        Returns:
        true if the token is allowed false otherwise.
        See Also:
        IProductionRule.isAllowed(java.lang.String)