working on fix for rule exceptions

This commit is contained in:
Terence Parr 2012-09-21 18:26:09 -07:00
parent ff0c658af5
commit 8a928d4326
5 changed files with 14 additions and 5 deletions

View File

@ -205,6 +205,7 @@ RuleFunction(currentRule,code,locals,ruleCtx,altLabelCtxs,namedActions,finallyAc
<postamble; separator="\n">
<namedActions.after>
}
<currentRule.exceptions>
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);

View File

@ -47,6 +47,7 @@ import org.antlr.v4.runtime.misc.OrderedHashSet;
import org.antlr.v4.runtime.misc.Triple;
import org.antlr.v4.tool.Attribute;
import org.antlr.v4.tool.Rule;
import org.antlr.v4.tool.ast.ActionAST;
import org.antlr.v4.tool.ast.AltAST;
import org.antlr.v4.tool.ast.GrammarAST;
@ -116,7 +117,11 @@ public class RuleFunction extends OutputModelObject {
ruleLabels = r.getElementLabelNames();
tokenLabels = r.getTokenRefs();
exceptions = Utils.nodesToStrings(r.exceptionActions);
for (GrammarAST e : r.exceptions) {
// TODO:Made new exception object here!!!
ActionAST a = (ActionAST)e.getChild(1);
exceptions = Utils.nodesToStrings(r.exceptions);
}
if ( r.finallyAction!=null ) finallyAction = new Action(factory, r.finallyAction);
startState = factory.getGrammar().atn.ruleToStartState[r.index];

View File

@ -41,6 +41,7 @@ import org.antlr.v4.tool.LabelElementPair;
import org.antlr.v4.tool.LabelType;
import org.antlr.v4.tool.Rule;
import org.antlr.v4.tool.ast.ActionAST;
import org.antlr.v4.tool.ast.GrammarAST;
import java.util.List;
@ -83,7 +84,8 @@ public class AttributeChecks implements ActionSplitterListener {
checker.examineAction();
}
}
for (ActionAST a : r.exceptionActions) {
for (GrammarAST e : r.exceptions) {
ActionAST a = (ActionAST)e.getChild(1);
AttributeChecks checker = new AttributeChecks(g, r, null, a, a.token);
checker.examineAction();
}

View File

@ -124,7 +124,8 @@ public class SymbolCollector extends GrammarTreeVisitor {
@Override
public void ruleCatch(GrammarAST arg, ActionAST action) {
currentRule.exceptionActions.add(action);
GrammarAST catchme = (GrammarAST)action.getParent();
currentRule.exceptions.add(catchme);
action.resolver = currentRule;
}

View File

@ -101,10 +101,10 @@ public class Rule implements AttributeResolver {
public Map<String, ActionAST> namedActions =
new HashMap<String, ActionAST>();
/** Track exception handler actions (exception type is prev child);
/** Track exception handlers; points at "catch" node of (catch exception action)
* don't track finally action
*/
public List<ActionAST> exceptionActions = new ArrayList<ActionAST>();
public List<GrammarAST> exceptions = new ArrayList<GrammarAST>();
/** Track all executable actions other than named actions like @init
* and catch/finally (not in an alt). Also tracks predicates, rewrite actions.