forked from cucumber/gherkin-javascript
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTokenExceptions.ts
44 lines (38 loc) · 1.14 KB
/
TokenExceptions.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 IToken from './IToken'
import createLocation from './cli/createLocation'
import { GherkinException } from './Errors'
export class UnexpectedTokenException extends GherkinException {
public static create<TokenType>(
token: IToken<TokenType>,
expectedTokenTypes: string[]
) {
const message = `expected: ${expectedTokenTypes.join(
', '
)}, got '${token.getTokenValue().trim()}'`
const location = tokenLocation(token)
return this._create(message, location)
}
}
export class UnexpectedEOFException extends GherkinException {
public static create<TokenType>(
token: IToken<TokenType>,
expectedTokenTypes: string[]
) {
const message = `unexpected end of file, expected: ${expectedTokenTypes.join(
', '
)}`
const location = tokenLocation(token)
return this._create(message, location)
}
}
function tokenLocation<TokenType>(token: IToken<TokenType>) {
return token.location &&
token.location.line &&
token.line &&
token.line.indent !== undefined
? createLocation({
line: token.location.line,
column: token.line.indent + 1,
})
: token.location
}