diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg index 4e7a52183..ca0e56979 100644 --- a/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg +++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg @@ -205,6 +205,7 @@ RuleFunction(currentRule,code,locals,ruleCtx,altLabelCtxs,namedActions,finallyAc } + catch (RecognitionException re) { _localctx.exception = re; _errHandler.reportError(this, re); diff --git a/tool/src/org/antlr/v4/codegen/model/RuleFunction.java b/tool/src/org/antlr/v4/codegen/model/RuleFunction.java index 66aace43a..cbd0c579a 100644 --- a/tool/src/org/antlr/v4/codegen/model/RuleFunction.java +++ b/tool/src/org/antlr/v4/codegen/model/RuleFunction.java @@ -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]; diff --git a/tool/src/org/antlr/v4/semantics/AttributeChecks.java b/tool/src/org/antlr/v4/semantics/AttributeChecks.java index 31805cb85..289be300c 100644 --- a/tool/src/org/antlr/v4/semantics/AttributeChecks.java +++ b/tool/src/org/antlr/v4/semantics/AttributeChecks.java @@ -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(); } diff --git a/tool/src/org/antlr/v4/semantics/SymbolCollector.java b/tool/src/org/antlr/v4/semantics/SymbolCollector.java index d9a737419..f2cb55a0b 100644 --- a/tool/src/org/antlr/v4/semantics/SymbolCollector.java +++ b/tool/src/org/antlr/v4/semantics/SymbolCollector.java @@ -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; } diff --git a/tool/src/org/antlr/v4/tool/Rule.java b/tool/src/org/antlr/v4/tool/Rule.java index e029c493f..a98ecbc91 100644 --- a/tool/src/org/antlr/v4/tool/Rule.java +++ b/tool/src/org/antlr/v4/tool/Rule.java @@ -101,10 +101,10 @@ public class Rule implements AttributeResolver { public Map namedActions = new HashMap(); - /** 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 exceptionActions = new ArrayList(); + public List exceptions = new ArrayList(); /** Track all executable actions other than named actions like @init * and catch/finally (not in an alt). Also tracks predicates, rewrite actions.