tridactyl/compiler/types/NumberType.ts
glacambre 9ef99b0ab4
parsers/exmode.ts: replace macro-generated info with ts-generated info
I tested nearly all ex commands and this didn't seem to break anything.
2019-05-31 15:20:46 +02:00

23 lines
553 B
TypeScript

import { Type } from "./Type"
export class NumberType implements Type {
public kind = "number"
public constructor(public isDotDotDot = false, public isQuestion = false) {}
public toConstructor() {
return `new NumberType(${this.isDotDotDot}, ${this.isQuestion})`
}
public toString() {
return this.kind
}
public convert(argument) {
const n = parseFloat(argument)
if (!Number.isNaN(n)) {
return n
}
throw new Error(`Can't convert to number: ${argument}`)
}
}