Skip to content

Commit

Permalink
clearer interface for parsing errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shahar Soel committed Nov 30, 2015
1 parent 4434309 commit 632ab14
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/parse/exceptions_public.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
namespace chevrotain.exceptions {

export interface IRecognitionException {
name:string,
message:string,
token:Token
}

// hacks to bypass no support for custom Errors in javascript/typescript
export function isRecognitionException(error:Error) {
let recognitionExceptions = [
Expand Down
7 changes: 4 additions & 3 deletions src/parse/parser_public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace chevrotain {
import checks = chevrotain.checks
import resolver = chevrotain.resolver
import exceptions = chevrotain.exceptions
import IRecognitionException = chevrotain.exceptions.IRecognitionException


export enum ParserDefinitionErrorType {
Expand Down Expand Up @@ -71,7 +72,7 @@ namespace chevrotain {
}

export interface IParserState {
errors: Error[]
errors: exceptions.IRecognitionException[]
inputIdx:number
RULE_STACK:string[]
}
Expand Down Expand Up @@ -134,7 +135,7 @@ namespace chevrotain {
}
}

public errors:Error[] = []
public errors:exceptions.IRecognitionException[] = []

/**
* This flag enables or disables error recovery (fault tolerance) of the parser.
Expand Down Expand Up @@ -235,7 +236,7 @@ namespace chevrotain {
return !(_.isEmpty(this.isBackTrackingStack))
}

protected SAVE_ERROR(error:Error):Error {
protected SAVE_ERROR(error:exceptions.IRecognitionException):IRecognitionException {
if (exceptions.isRecognitionException(error)) {
this.errors.push(error)
return error
Expand Down

0 comments on commit 632ab14

Please sign in to comment.