예제 #1
0
 /**
  * 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);
 }
예제 #2
0
 /**
  * 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();
 }
예제 #3
0
 public static RuleDefinition newRuleBuilder(RuleMatcher ruleMatcher) {
   RuleDefinition ruleBuilder = new RuleDefinition();
   ruleBuilder.setRuleMatcher(ruleMatcher);
   return ruleBuilder;
 }
예제 #4
0
 public static RuleDefinition newRuleBuilder(String ruleName) {
   RuleDefinition ruleBuilder = new RuleDefinition();
   ruleBuilder.setRuleMatcher(new RuleMatcher(ruleName));
   return ruleBuilder;
 }