got left recur msg in

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 6763]
This commit is contained in:
parrt 2010-03-22 12:35:33 -08:00
parent 3e81cbc786
commit 2e85e0d3a7
5 changed files with 28 additions and 11 deletions

View File

@ -283,10 +283,6 @@ RECURSION_OVERFLOW(alt,input,targetRules,callSiteStates) ::= <<
Alternative <alt>: after matching input such as <input> decision cannot predict what comes next due to recursion overflow <targetRules,callSiteStates:{t,c|to <t> from <c:{s|<s.enclosingRule.name>};separator=", ">}; separator=" and ">
>>
LEFT_RECURSION(targetRules,alt,callSiteStates) ::= <<
Alternative <alt> discovers infinite left-recursion <targetRules,callSiteStates:{t,c|to <t> from <c:{s|<s.enclosingRule>};separator=", ">}; separator=" and ">
>>
UNREACHABLE_TOKENS(tokens) ::= <<
The following token definitions can never be matched because prior tokens match the same input: <tokens; separator=",">
>>
@ -302,8 +298,8 @@ Multiple token rules can match input such as "<input>": <conflictingTokens; sepa
<if(disabled)><\n>As a result, token(s) <disabled; separator=","> were disabled for that input<endif><if(hasPredicateBlockedByAction)><\n>Semantic predicates were present but were hidden by actions.<endif>
>>
LEFT_RECURSION_CYCLES(listOfCycles) ::= <<
The following sets of rules are mutually left-recursive <listOfCycles:{c| [<c:{r|<r.name>}; separator=", ">]}; separator=" and ">
LEFT_RECURSION_CYCLES(arg) ::= <<
The following sets of rules are mutually left-recursive <arg:{c| [<c:{r|<r.name>}; separator=", ">]}; separator=" and ">
>>
NONREGULAR_DECISION(ruleName,alts) ::= <<

View File

@ -1,6 +1,7 @@
package org.antlr.v4.analysis;
import org.antlr.v4.automata.*;
import org.antlr.v4.tool.ErrorManager;
import org.antlr.v4.tool.Rule;
import java.util.ArrayList;
@ -32,6 +33,7 @@ public class LeftRecursionDetector {
check(start.rule, start, new HashSet<NFAState>());
}
//System.out.println("cycles="+listOfRecursiveCycles);
ErrorManager.leftRecursionCycles(listOfRecursiveCycles);
}
/** From state s, look for any transition to a rule that is currently
@ -87,7 +89,7 @@ public class LeftRecursionDetector {
* cycle.
*/
protected void addRulesToCycle(Rule enclosingRule, Rule targetRule) {
System.err.println("left-recursion to "+targetRule.name+" from "+enclosingRule.name);
//System.err.println("left-recursion to "+targetRule.name+" from "+enclosingRule.name);
boolean foundCycle = false;
for (int i = 0; i < listOfRecursiveCycles.size(); i++) {
Set<Rule> rulesInCycle = listOfRecursiveCycles.get(i);

View File

@ -319,14 +319,14 @@ public class ErrorManager {
DFA dfa,
Collection<Integer> unreachableAlts)
{
System.err.println("unreachable="+unreachableAlts);
state.get().warnings++;
//System.err.println("unreachable="+unreachableAlts);
state.get().errors++;
UnreachableAltsMessage msg =
new UnreachableAltsMessage(ErrorType.UNREACHABLE_ALTS,
fileName,
dfa,
unreachableAlts);
state.get().listener.warning(msg);
state.get().listener.error(msg);
}
public static void insufficientPredicates(String fileName,
@ -346,6 +346,12 @@ public class ErrorManager {
state.get().listener.warning(msg);
}
public static void leftRecursionCycles(Collection cycles) {
state.get().errors++;
Message msg = new LeftRecursionCyclesMessage(cycles);
state.get().listener.warning(msg);
}
/** Process a new message by sending it on to the error listener associated with the current thread
* and recording any information we need in the error state for the current thread.
*/

View File

@ -136,6 +136,7 @@ public enum ErrorType {
UNREACHABLE_ALTS(ErrorSeverity.ERROR, true, true),
RECURSION_OVERFLOW(ErrorSeverity.ERROR, true, true),
INSUFFICIENT_PREDICATES(ErrorSeverity.ERROR, true, true),
LEFT_RECURSION_CYCLES(ErrorSeverity.ERROR, true, true),
/** Documentation comment is unterminated */
//UNTERMINATED_DOC_COMMENT(ErrorSeverity.ERROR, true, true),

View File

@ -0,0 +1,12 @@
package org.antlr.v4.tool;
import java.util.Collection;
public class LeftRecursionCyclesMessage extends Message {
public Collection cycles;
public LeftRecursionCyclesMessage(Collection cycles) {
super(ErrorType.LEFT_RECURSION_CYCLES, cycles);
this.cycles = cycles;
}
}