/** * 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(); }
public static RuleDefinition newRuleBuilder(RuleMatcher ruleMatcher) { RuleDefinition ruleBuilder = new RuleDefinition(); ruleBuilder.setRuleMatcher(ruleMatcher); return ruleBuilder; }
public static RuleDefinition newRuleBuilder(String ruleName) { RuleDefinition ruleBuilder = new RuleDefinition(); ruleBuilder.setRuleMatcher(new RuleMatcher(ruleName)); return ruleBuilder; }