[Swift] Fix parse-cancellation in BailErrorStrategy.

BailErrorStrategy is supposed to throw an error that's different from
the ordinary recognition error, specifically so that it can be handled
differently by client code.  This was not ported over from Java correctly.

Fix this by moving parseCancellation from ANTLRError to ANTLRException,
adding its RecognitionException argument, and throwing it from the
two handlers in BailErrorStrategy.

Also remove ANTLRException.cannotInvokeStartRule, which is unused.
(The Java runtime uses it when ParseTreePatternMatcher throws a generic
exception, but we don't have that.)
This commit is contained in:
Ewan Mellor 2017-11-10 23:49:00 -08:00
parent b4c34da1f0
commit eb9124fff8
No known key found for this signature in database
GPG Key ID: 7CE1C6BC9EC8645D
4 changed files with 3 additions and 8 deletions

View File

@ -290,8 +290,6 @@ public class BaseSwiftTest implements RuntimeTestSupport {
"let tree = try parser.<parserStartRuleName>()\n" + "let tree = try parser.<parserStartRuleName>()\n" +
"<if(profile)>print(profiler.getDecisionInfo().description)<endif>\n" + "<if(profile)>print(profiler.getDecisionInfo().description)<endif>\n" +
"try ParseTreeWalker.DEFAULT.walk(TreeShapeListener(), tree)\n" + "try ParseTreeWalker.DEFAULT.walk(TreeShapeListener(), tree)\n" +
"}catch ANTLRException.cannotInvokeStartRule {\n" +
" print(\"error occur: cannotInvokeStartRule\")\n" +
"}catch ANTLRException.recognition(let e ) {\n" + "}catch ANTLRException.recognition(let e ) {\n" +
" print(\"error occur\\(e)\")\n" + " print(\"error occur\\(e)\")\n" +
"}catch {\n" + "}catch {\n" +
@ -333,8 +331,6 @@ public class BaseSwiftTest implements RuntimeTestSupport {
"do {\n" + "do {\n" +
" try tokens.fill()\n" + " try tokens.fill()\n" +
"} catch ANTLRException.cannotInvokeStartRule {\n" +
" print(\"error occur: cannotInvokeStartRule\")\n" +
"} catch ANTLRException.recognition(let e ) {\n" + "} catch ANTLRException.recognition(let e ) {\n" +
" print(\"error occur\\(e)\")\n" + " print(\"error occur\\(e)\")\n" +
"} catch {\n" + "} catch {\n" +

View File

@ -47,7 +47,7 @@ public class BailErrorStrategy: DefaultErrorStrategy {
context = (contextWrap.getParent() as? ParserRuleContext) context = (contextWrap.getParent() as? ParserRuleContext)
} }
throw ANTLRException.recognition(e: e) throw ANTLRException.parseCancellation(e: e)
} }
/// ///
@ -63,7 +63,7 @@ public class BailErrorStrategy: DefaultErrorStrategy {
context = (contextWrap.getParent() as? ParserRuleContext) context = (contextWrap.getParent() as? ParserRuleContext)
} }
throw ANTLRException.recognition(e: e) throw ANTLRException.parseCancellation(e: e)
} }
/// ///

View File

@ -19,5 +19,4 @@ public enum ANTLRError: Error {
case illegalState(msg:String) case illegalState(msg:String)
case illegalArgument(msg:String) case illegalArgument(msg:String)
case negativeArraySize(msg:String) case negativeArraySize(msg:String)
case parseCancellation
} }

View File

@ -15,6 +15,6 @@
import Foundation import Foundation
public enum ANTLRException: Error { public enum ANTLRException: Error {
case cannotInvokeStartRule case parseCancellation(e: RecognitionException)
case recognition(e: RecognitionException) case recognition(e: RecognitionException)
} }