/**
  * Constructs grammar.
  *
  * @throws GrammarException if some of rules were used, but not defined
  * @return grammar
  * @see #buildWithMemoizationOfMatchesForAllRules()
  */
 public Grammar build() {
   for (RuleDefinition rule : definitions.values()) {
     if (rule.getExpression() == null) {
       throw new GrammarException("The rule '" + rule.getRuleKey() + "' hasn't beed defined.");
     }
   }
   return new MutableGrammar(definitions, rootRuleKey);
 }
 /**
  * Constructs grammar with memoization of matches for all rules.
  *
  * @throws GrammarException if some of rules were used, but not defined
  * @return grammar
  * @see #build()
  */
 public Grammar buildWithMemoizationOfMatchesForAllRules() {
   for (RuleDefinition rule : definitions.values()) {
     rule.enableMemoization();
   }
   return build();
 }
Esempio n. 3
0
 public static RuleDefinition newRuleBuilder(RuleMatcher ruleMatcher) {
   RuleDefinition ruleBuilder = new RuleDefinition();
   ruleBuilder.setRuleMatcher(ruleMatcher);
   return ruleBuilder;
 }
Esempio n. 4
0
 public static RuleDefinition newRuleBuilder(String ruleName) {
   RuleDefinition ruleBuilder = new RuleDefinition();
   ruleBuilder.setRuleMatcher(new RuleMatcher(ruleName));
   return ruleBuilder;
 }