Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Apr 7, 2022
1 parent 6382efe commit e20a1e6
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 104 deletions.
14 changes: 11 additions & 3 deletions src/context.ts
Expand Up @@ -76,13 +76,21 @@ export class Context {
}

/* istanbul ignore next */
public throwUnexpectedTokenError(cst: CST.Token): ParseError {
public throwUnexpectedTokenError(cst: CST.Token | Token): ParseError {
const token = "source" in cst ? `'${cst.source}'` : cst.type
throw this.throwError(`Unexpected token: ${token}`, cst)
}

public throwError(message: string, cst: CST.Token | number): ParseError {
const offset = typeof cst === "number" ? cst : cst.offset
public throwError(
message: string,
cst: CST.Token | Token | number,
): ParseError {
const offset =
typeof cst === "number"
? cst
: "offset" in cst
? cst.offset
: cst.range[0]
const loc = this.getLocFromIndex(offset)
throw new ParseError(message, offset, loc.line, loc.column)
}
Expand Down

0 comments on commit e20a1e6

Please sign in to comment.