Skip to content

Commit

Permalink
fix: custom Exception extends Error
Browse files Browse the repository at this point in the history
  • Loading branch information
luomingtao committed Mar 29, 2019
1 parent 1d9c5cc commit e620e30
Show file tree
Hide file tree
Showing 7 changed files with 377 additions and 368 deletions.
2 changes: 2 additions & 0 deletions src/FailedPredicateException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export class FailedPredicateException extends RecognitionException {
recognizer.inputStream,
recognizer.context,
FailedPredicateException.formatMessage(predicate, message));
Object.setPrototypeOf(this, FailedPredicateException.prototype);

let s: ATNState = recognizer.interpreter.atn.states[recognizer.state];

let trans = s.transition(0) as AbstractPredicateTransition;
Expand Down
1 change: 1 addition & 0 deletions src/InputMismatchException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class InputMismatchException extends RecognitionException {
}

super(recognizer, recognizer.inputStream, context);
Object.setPrototypeOf(this, InputMismatchException.prototype);

if (state !== undefined) {
this.setOffendingState(state);
Expand Down
2 changes: 2 additions & 0 deletions src/LexerNoViableAltException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export class LexerNoViableAltException extends RecognitionException {
startIndex: number,
deadEndConfigs: ATNConfigSet | undefined) {
super(lexer, input);
Object.setPrototypeOf(this, LexerNoViableAltException.prototype);

this._startIndex = startIndex;
this._deadEndConfigs = deadEndConfigs;
}
Expand Down
2 changes: 2 additions & 0 deletions src/NoViableAltException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export class NoViableAltException extends RecognitionException {
}

super(recognizer, input, ctx);
Object.setPrototypeOf(this, NoViableAltException.prototype);

this._deadEndConfigs = deadEndConfigs;
this._startToken = startToken as Token;
this.setOffendingToken(recognizer, offendingToken);
Expand Down
2 changes: 2 additions & 0 deletions src/RecognitionException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export class RecognitionException extends Error {
if (recognizer) {
this._offendingState = recognizer.state;
}
// see https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
Object.setPrototypeOf(this, RecognitionException.prototype);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/

export * from "./ParserInterpreter";
export * from "./Parser";

export * from "./ANTLRErrorListener";
export * from "./ANTLRErrorStrategy";
// export * from "./ANTLRFileStream";
export * from "./ANTLRInputStream";
export * from "./BailErrorStrategy";
export * from "./BufferedTokenStream";
export * from "./CharStream";
export * from "./CharStreams";
Expand All @@ -17,6 +19,7 @@ export * from "./CommonToken";
export * from "./CommonTokenFactory";
export * from "./CommonTokenStream";
export * from "./ConsoleErrorListener";
export * from "./Decorators";
export * from "./DefaultErrorStrategy";
export * from "./Dependents";
export * from "./DiagnosticErrorListener";
Expand Down Expand Up @@ -44,12 +47,9 @@ export * from "./TokenFactory";
export * from "./TokenSource";
export * from "./TokenStream";
export * from "./TokenStreamRewriter";
// export * from "./UnbufferedCharStream";
// export * from "./UnbufferedTokenStream";
export * from "./Vocabulary";
export * from "./VocabularyImpl";
export * from "./WritableToken";
export * from "./BailErrorStrategy";

export * from "./atn";
export * from "./dfa";
Expand Down
Loading

0 comments on commit e620e30

Please sign in to comment.