GrammarAST expandedAlt = expandOptionalQuantifiersForAlt(child); if (expandedAlt == null) { return false;
if (!translateLeftFactoredDecision(block, rules[0], false, DecisionFactorMode.COMBINED_FACTOR, true)) {
protected GrammarAST translateLeftFactoredAlternative(GrammarAST alternative, String factoredRule, boolean variant, DecisionFactorMode mode, boolean includeFactoredElement) { if (mode == DecisionFactorMode.PARTIAL_UNFACTORED && includeFactoredElement) { throw new IllegalArgumentException("Cannot include the factored element in unfactored alternatives."); } else if (mode == DecisionFactorMode.COMBINED_FACTOR && !includeFactoredElement) { throw new IllegalArgumentException("Cannot return a combined answer without the factored element."); } assert alternative.getChildCount() > 0; if (alternative.getChild(0).getType() == ANTLRParser.EPSILON) { if (mode == DecisionFactorMode.PARTIAL_UNFACTORED) { return alternative; } return null; } GrammarAST translatedElement = translateLeftFactoredElement((GrammarAST)alternative.getChild(0), factoredRule, variant, mode, includeFactoredElement); if (translatedElement == null) { return null; } alternative.replaceChildren(0, 0, translatedElement); if (alternative.getChildCount() == 0) { adaptor.addChild(alternative, adaptor.create(ANTLRParser.EPSILON, "EPSILON")); } assert alternative.getChildCount() > 0; return alternative; }
GrammarAST translatedChildElement = translateLeftFactoredElement((GrammarAST)element.getChild(1), factoredRule, variant, mode, includeFactoredElement); if (translatedChildElement == null) { return null; RuleVariants ruleVariants = createLeftFactoredRuleVariant(targetRule, factoredRule); switch (ruleVariants) { case NONE: if (!translateLeftFactoredDecision(cloned, factoredRule, variant, mode, includeFactoredElement)) { return null; GrammarAST translatedElement = translateLeftFactoredElement(originalChildElement.dupTree(), factoredRule, variant, mode, includeFactoredElement); if (translatedElement == null) { return null;
if (!expandOptionalQuantifiersForBlock(block, variant)) { return false; GrammarAST alternative = alternatives.get(i); if (mode.includeUnfactoredAlts()) { GrammarAST unfactoredAlt = translateLeftFactoredAlternative(alternative.dupTree(), factoredRule, variant, DecisionFactorMode.PARTIAL_UNFACTORED, false); unfactoredAlternatives[i] = unfactoredAlt; if (unfactoredAlt != null) { GrammarAST factoredAlt = translateLeftFactoredAlternative(alternative, factoredRule, variant, mode == DecisionFactorMode.COMBINED_FACTOR ? DecisionFactorMode.PARTIAL_FACTORED : DecisionFactorMode.FULL_FACTOR, includeFactoredElement); factoredAlternatives[i] = factoredAlt; if (factoredAlt != null) {
LeftFactoringRuleTransformer lftrans = new LeftFactoringRuleTransformer(g.ast, ruleCollector.rules, g); lftrans.translateLeftFactoredRules();
BlockAST unfactoredBlock = null; if (translateLeftFactoredDecision(block, factoredElement, true, DecisionFactorMode.FULL_FACTOR, false)) { if (!translateLeftFactoredDecision(block, factoredElement, true, DecisionFactorMode.PARTIAL_FACTORED, false)) { if (!translateLeftFactoredDecision(unfactoredBlock, factoredElement, true, DecisionFactorMode.PARTIAL_UNFACTORED, false)) { throw new IllegalStateException("expected unfactored alts for partial factorization");