[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:
parent
b4c34da1f0
commit
eb9124fff8
|
@ -290,8 +290,6 @@ public class BaseSwiftTest implements RuntimeTestSupport {
|
|||
"let tree = try parser.<parserStartRuleName>()\n" +
|
||||
"<if(profile)>print(profiler.getDecisionInfo().description)<endif>\n" +
|
||||
"try ParseTreeWalker.DEFAULT.walk(TreeShapeListener(), tree)\n" +
|
||||
"}catch ANTLRException.cannotInvokeStartRule {\n" +
|
||||
" print(\"error occur: cannotInvokeStartRule\")\n" +
|
||||
"}catch ANTLRException.recognition(let e ) {\n" +
|
||||
" print(\"error occur\\(e)\")\n" +
|
||||
"}catch {\n" +
|
||||
|
@ -333,8 +331,6 @@ public class BaseSwiftTest implements RuntimeTestSupport {
|
|||
|
||||
"do {\n" +
|
||||
" try tokens.fill()\n" +
|
||||
"} catch ANTLRException.cannotInvokeStartRule {\n" +
|
||||
" print(\"error occur: cannotInvokeStartRule\")\n" +
|
||||
"} catch ANTLRException.recognition(let e ) {\n" +
|
||||
" print(\"error occur\\(e)\")\n" +
|
||||
"} catch {\n" +
|
||||
|
|
|
@ -47,7 +47,7 @@ public class BailErrorStrategy: DefaultErrorStrategy {
|
|||
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)
|
||||
}
|
||||
|
||||
throw ANTLRException.recognition(e: e)
|
||||
throw ANTLRException.parseCancellation(e: e)
|
||||
}
|
||||
|
||||
///
|
||||
|
|
|
@ -19,5 +19,4 @@ public enum ANTLRError: Error {
|
|||
case illegalState(msg:String)
|
||||
case illegalArgument(msg:String)
|
||||
case negativeArraySize(msg:String)
|
||||
case parseCancellation
|
||||
}
|
||||
|
|
|
@ -15,6 +15,6 @@
|
|||
import Foundation
|
||||
|
||||
public enum ANTLRException: Error {
|
||||
case cannotInvokeStartRule
|
||||
case parseCancellation(e: RecognitionException)
|
||||
case recognition(e: RecognitionException)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue