| java.lang.Object org.antlr.tool.GrammarSanity
GrammarSanity | public class GrammarSanity (Code) | | Factor out routines that check sanity of rules, alts, grammars, etc..
|
Method Summary | |
protected void | addRulesToCycle(String targetRuleName, String enclosingRuleName, List listOfRecursiveCycles) enclosingRuleName calls targetRuleName, find the cycle containing
the target and add the caller. | public List | checkAllRulesForLeftRecursion() Check all rules for infinite left recursion before analysis. | public void | checkRuleReference(GrammarAST refAST, GrammarAST argsAST, String currentRuleName) | public void | ensureAltIsSimpleNodeOrTree(GrammarAST altAST, GrammarAST elementAST, int outerAltNum) Rules in tree grammar that use -> rewrites and are spitting out
templates via output=template and then use rewrite=true must only
use -> on alts that are simple nodes or trees or single rule refs
that match either nodes or trees. | protected boolean | isNextNonActionElementEOA(GrammarAST t) | protected boolean | isValidSimpleElementNode(GrammarAST t) | protected boolean | traceStatesLookingForLeftRecursion(NFAState s, Set visitedStates, List listOfRecursiveCycles) From state s, look for any transition to a rule that is currently
being traced. |
addRulesToCycle | protected void addRulesToCycle(String targetRuleName, String enclosingRuleName, List listOfRecursiveCycles)(Code) | | enclosingRuleName calls targetRuleName, find the cycle containing
the target and add the caller. Find the cycle containing the caller
and add the target. If no cycles contain either, then create a new
cycle. listOfRecursiveCycles is List> that holds a list
of cycles (sets of rule names).
|
checkAllRulesForLeftRecursion | public List checkAllRulesForLeftRecursion()(Code) | | Check all rules for infinite left recursion before analysis. Return list
of troublesome rule cycles. This method has two side-effects: it notifies
the error manager that we have problems and it sets the list of
recursive rules that we should ignore during analysis.
Return type: List>.
|
ensureAltIsSimpleNodeOrTree | public void ensureAltIsSimpleNodeOrTree(GrammarAST altAST, GrammarAST elementAST, int outerAltNum)(Code) | | Rules in tree grammar that use -> rewrites and are spitting out
templates via output=template and then use rewrite=true must only
use -> on alts that are simple nodes or trees or single rule refs
that match either nodes or trees. The altAST is the ALT node
for an ALT. Verify that its first child is simple. Must be either
( ALT ^( A B ) ) or ( ALT A ) or
other element.
Ignore predicates in front and labels.
|
isNextNonActionElementEOA | protected boolean isNextNonActionElementEOA(GrammarAST t)(Code) | | |
isValidSimpleElementNode | protected boolean isValidSimpleElementNode(GrammarAST t)(Code) | | |
traceStatesLookingForLeftRecursion | protected boolean traceStatesLookingForLeftRecursion(NFAState s, Set visitedStates, List listOfRecursiveCycles)(Code) | | From state s, look for any transition to a rule that is currently
being traced. When tracing r, visitedDuringRecursionCheck has r
initially. If you reach an accept state, return but notify the
invoking rule that it is nullable, which implies that invoking
rule must look at follow transition for that invoking state.
The visitedStates tracks visited states within a single rule so
we can avoid epsilon-loop-induced infinite recursion here. Keep
filling the cycles in listOfRecursiveCycles and also, as a
side-effect, set leftRecursiveRules.
|
|
|