transcendental-lisp/src/main/kotlin/sexpression/LispNumber.kt
Mike Cifelli 347857fbb5 Restore main function
- Remove MessageFormat usages in kotlin where possible
 - Code cleanup
2018-10-20 10:09:53 -04:00

35 lines
795 B
Kotlin

package sexpression
import error.LispException
import java.math.BigInteger
@DisplayName("number")
class LispNumber : Atom {
override val isNumber = true
val value: BigInteger
constructor(text: String) : super(text.replaceFirst("^0+(?!$)".toRegex(), "")) {
try {
this.value = BigInteger(text)
} catch (e: NumberFormatException) {
throw InvalidNumberException(text)
}
}
constructor(value: BigInteger) : super(value.toString()) {
this.value = value
}
companion object {
val ZERO = LispNumber(BigInteger.ZERO)
val ONE = LispNumber(BigInteger.ONE)
}
class InvalidNumberException(text: String) : LispException() {
override val message = "$text is not a valid integer"
}
}