-
Notifications
You must be signed in to change notification settings - Fork 0
/
causes.ts
44 lines (42 loc) · 1.15 KB
/
causes.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { annotate } from 'annotate-code'
import { Impl, Token } from './'
export class ParserErrorCause {
name = 'ParserUnknownError'
index: number
input: string
line!: number
col!: number
message!: string
constructor(public token: Token, public short?: string) {
this.index = token.index
this.input = token.source.input
const message = `${short || this.name}: [${token.group}]: ${token.value}`
Object.assign(
this,
annotate({
message,
index: token.index,
input: token.source.input,
})
)
this.message = message + '\n' + this.message
}
}
export class UnexpectedToken extends ParserErrorCause {
name = 'ParserUnexpectedToken'
constructor(token: Token, public group: string, public value?: string) {
super(token, `Expected: '${value}' [${group}], instead received`)
}
}
export class BadImpl extends ParserErrorCause {
name = 'ParserBadImpl'
constructor(token: Token, public impl: keyof Impl) {
super(token, `Bad ${impl}`)
}
}
export class BadToken extends ParserErrorCause {
name = 'ParserBadToken'
}
export class BadOp extends ParserErrorCause {
name = 'ParserBadOp'
}