diff --git a/stdlib/number.gr b/stdlib/number.gr index a6bc87300b..518541ef2b 100644 --- a/stdlib/number.gr +++ b/stdlib/number.gr @@ -30,6 +30,9 @@ include "runtime/atof/parse" as Atof include "runtime/unsafe/tags" include "runtime/exception" +from Atoi use { type ParseIntError } + +provide { type ParseIntError } /** * Pi represented as a Number value. * diff --git a/stdlib/number.md b/stdlib/number.md index d4a784cafd..afcec33a92 100644 --- a/stdlib/number.md +++ b/stdlib/number.md @@ -13,6 +13,22 @@ No other changes yet. include "number" ``` +## Types + +Type declarations included in the Number module. + +### Number.**ParseIntError** + +```grain +enum ParseIntError { + EmptyString, + InvalidDigit, + InvalidRadix, +} +``` + +Represents an error that can occur when parsing ints. + ## Values Functions and constants included in the Number module. @@ -709,7 +725,8 @@ No other changes yet. ```grain -parseInt : (string: String, radix: Number) => Result +parseInt : + (string: String, radix: Number) => Result ``` Parses a string representation of an integer into a `Number` using the @@ -731,7 +748,7 @@ Returns: |type|description| |----|-----------| -|`Result`|`Ok(value)` containing the parsed number on a successful parse or `Err(msg)` containing an error message string otherwise| +|`Result`|`Ok(value)` containing the parsed number on a successful parse or `Err(msg)` containing an error message string otherwise| ### Number.**parseFloat** @@ -767,7 +784,7 @@ No other changes yet. ```grain -parse : (input: String) => Result +parse : (input: String) => Result ``` Parses a string representation of an integer, float, or rational into a `Number`. @@ -783,7 +800,7 @@ Returns: |type|description| |----|-----------| -|`Result`|`Ok(value)` containing the parsed number on a successful parse or `Err(msg)` containing an error message string otherwise| +|`Result`|`Ok(value)` containing the parsed number on a successful parse or `Err(msg)` containing an error message string otherwise| ### Number.**sin** diff --git a/stdlib/runtime/atoi/parse.gr b/stdlib/runtime/atoi/parse.gr index 589c620eb4..7efabf8a45 100644 --- a/stdlib/runtime/atoi/parse.gr +++ b/stdlib/runtime/atoi/parse.gr @@ -20,9 +20,14 @@ include "runtime/bigint" as BI include "runtime/numbers" from Numbers use { reducedInteger } -provide exception EmptyString -provide exception InvalidDigit -provide exception InvalidRadix +/** + * Represents an error that can occur when parsing ints. + */ +provide enum ParseIntError { + EmptyString, + InvalidDigit, + InvalidRadix, +} primitive (&&) = "@and" primitive (||) = "@or" diff --git a/stdlib/runtime/atoi/parse.md b/stdlib/runtime/atoi/parse.md index 92d29ceb3a..2b2b1913e3 100644 --- a/stdlib/runtime/atoi/parse.md +++ b/stdlib/runtime/atoi/parse.md @@ -2,6 +2,22 @@ title: Parse --- +## Types + +Type declarations included in the Parse module. + +### Parse.**ParseIntError** + +```grain +enum ParseIntError { + EmptyString, + InvalidDigit, + InvalidRadix, +} +``` + +Represents an error that can occur when parsing ints. + ## Values Functions and constants included in the Parse module. @@ -9,6 +25,6 @@ Functions and constants included in the Parse module. ### Parse.**parseInt** ```grain -parseInt : (string: String, radix: Number) => Result +parseInt : (string: String, radix: Number) => Result ```