public GrammarAST stripLeftRecursion(GrammarAST altAST) { GrammarAST lrlabel=null; GrammarAST first = (GrammarAST)altAST.getChild(0); int leftRecurRuleIndex = 0; if ( first.getType() == ELEMENT_OPTIONS ) { first = (GrammarAST)altAST.getChild(1); leftRecurRuleIndex = 1; } Tree rref = first.getChild(1); // if label=rule if ( (first.getType()==RULE_REF && first.getText().equals(ruleName)) || (rref!=null && rref.getType()==RULE_REF && rref.getText().equals(ruleName)) ) { if ( first.getType()==ASSIGN || first.getType()==PLUS_ASSIGN ) lrlabel = (GrammarAST)first.getChild(0); // remove rule ref (first child unless options present) altAST.deleteChild(leftRecurRuleIndex); // reset index so it prints properly (sets token range of // ALT to start to right of left recur rule we deleted) GrammarAST newFirstChild = (GrammarAST)altAST.getChild(leftRecurRuleIndex); altAST.setTokenStartIndex(newFirstChild.getTokenStartIndex()); } return lrlabel; }
public GrammarAST stripLeftRecursion(GrammarAST altAST) { GrammarAST lrlabel=null; GrammarAST first = (GrammarAST)altAST.getChild(0); int leftRecurRuleIndex = 0; if ( first.getType() == ELEMENT_OPTIONS ) { first = (GrammarAST)altAST.getChild(1); leftRecurRuleIndex = 1; } Tree rref = first.getChild(1); // if label=rule if ( (first.getType()==RULE_REF && first.getText().equals(ruleName)) || (rref!=null && rref.getType()==RULE_REF && rref.getText().equals(ruleName)) ) { if ( first.getType()==ASSIGN || first.getType()==PLUS_ASSIGN ) lrlabel = (GrammarAST)first.getChild(0); // remove rule ref (first child unless options present) altAST.deleteChild(leftRecurRuleIndex); // reset index so it prints properly (sets token range of // ALT to start to right of left recur rule we deleted) GrammarAST newFirstChild = (GrammarAST)altAST.getChild(leftRecurRuleIndex); altAST.setTokenStartIndex(newFirstChild.getTokenStartIndex()); } return lrlabel; }
public GrammarAST stripLeftRecursion(GrammarAST altAST) { GrammarAST lrlabel=null; GrammarAST first = (GrammarAST)altAST.getChild(0); int leftRecurRuleIndex = 0; if ( first.getType() == ELEMENT_OPTIONS ) { first = (GrammarAST)altAST.getChild(1); leftRecurRuleIndex = 1; } Tree rref = first.getChild(1); // if label=rule if ( (first.getType()==RULE_REF && first.getText().equals(ruleName)) || (rref!=null && rref.getType()==RULE_REF && rref.getText().equals(ruleName)) ) { if ( first.getType()==ASSIGN || first.getType()==PLUS_ASSIGN ) lrlabel = (GrammarAST)first.getChild(0); // remove rule ref (first child unless options present) altAST.deleteChild(leftRecurRuleIndex); // reset index so it prints properly (sets token range of // ALT to start to right of left recur rule we deleted) GrammarAST newFirstChild = (GrammarAST)altAST.getChild(leftRecurRuleIndex); altAST.setTokenStartIndex(newFirstChild.getTokenStartIndex()); } return lrlabel; }
public GrammarAST stripLeftRecursion(GrammarAST altAST) { GrammarAST lrlabel=null; GrammarAST first = (GrammarAST)altAST.getChild(0); int leftRecurRuleIndex = 0; if ( first.getType() == ELEMENT_OPTIONS ) { first = (GrammarAST)altAST.getChild(1); leftRecurRuleIndex = 1; } Tree rref = first.getChild(1); // if label=rule if ( (first.getType()==RULE_REF && first.getText().equals(ruleName)) || (rref!=null && rref.getType()==RULE_REF && rref.getText().equals(ruleName)) ) { if ( first.getType()==ASSIGN || first.getType()==PLUS_ASSIGN ) lrlabel = (GrammarAST)first.getChild(0); // remove rule ref (first child unless options present) altAST.deleteChild(leftRecurRuleIndex); // reset index so it prints properly (sets token range of // ALT to start to right of left recur rule we deleted) GrammarAST newFirstChild = (GrammarAST)altAST.getChild(leftRecurRuleIndex); altAST.setTokenStartIndex(newFirstChild.getTokenStartIndex()); } return lrlabel; }
public GrammarAST stripLeftRecursion(GrammarAST altAST) { GrammarAST lrlabel=null; GrammarAST first = (GrammarAST)altAST.getChild(0); int leftRecurRuleIndex = 0; if ( first.getType() == ELEMENT_OPTIONS ) { first = (GrammarAST)altAST.getChild(1); leftRecurRuleIndex = 1; } Tree rref = first.getChild(1); // if label=rule if ( (first.getType()==RULE_REF && first.getText().equals(ruleName)) || (rref!=null && rref.getType()==RULE_REF && rref.getText().equals(ruleName)) ) { if ( first.getType()==ASSIGN || first.getType()==PLUS_ASSIGN ) lrlabel = (GrammarAST)first.getChild(0); // remove rule ref (first child unless options present) altAST.deleteChild(leftRecurRuleIndex); // reset index so it prints properly (sets token range of // ALT to start to right of left recur rule we deleted) GrammarAST newFirstChild = (GrammarAST)altAST.getChild(leftRecurRuleIndex); altAST.setTokenStartIndex(newFirstChild.getTokenStartIndex()); } return lrlabel; }