Skip to content

Commit 4ceecb2

Browse files
committed
chore: Switch to using an enum
1 parent f76ab1c commit 4ceecb2

File tree

4 files changed

+49
-8
lines changed

4 files changed

+49
-8
lines changed

stdlib/number.gr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ include "runtime/atof/parse" as Atof
3030
include "runtime/unsafe/tags"
3131
include "runtime/exception"
3232

33+
from Atoi use { type ParseIntError }
34+
35+
provide { type ParseIntError }
3336
/**
3437
* Pi represented as a Number value.
3538
*

stdlib/number.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,22 @@ No other changes yet.
1313
include "number"
1414
```
1515

16+
## Types
17+
18+
Type declarations included in the Number module.
19+
20+
### Number.**ParseIntError**
21+
22+
```grain
23+
enum ParseIntError {
24+
EmptyString,
25+
InvalidDigit,
26+
InvalidRadix,
27+
}
28+
```
29+
30+
Represents an error that can occur when parsing ints.
31+
1632
## Values
1733

1834
Functions and constants included in the Number module.
@@ -709,7 +725,8 @@ No other changes yet.
709725
</details>
710726

711727
```grain
712-
parseInt : (string: String, radix: Number) => Result<Number, Exception>
728+
parseInt :
729+
(string: String, radix: Number) => Result<Number, Atoi.ParseIntError>
713730
```
714731

715732
Parses a string representation of an integer into a `Number` using the
@@ -731,7 +748,7 @@ Returns:
731748

732749
|type|description|
733750
|----|-----------|
734-
|`Result<Number, Exception>`|`Ok(value)` containing the parsed number on a successful parse or `Err(msg)` containing an error message string otherwise|
751+
|`Result<Number, Atoi.ParseIntError>`|`Ok(value)` containing the parsed number on a successful parse or `Err(msg)` containing an error message string otherwise|
735752

736753
### Number.**parseFloat**
737754

@@ -767,7 +784,7 @@ No other changes yet.
767784
</details>
768785

769786
```grain
770-
parse : (input: String) => Result<Number, Exception>
787+
parse : (input: String) => Result<Number, Atoi.ParseIntError>
771788
```
772789

773790
Parses a string representation of an integer, float, or rational into a `Number`.
@@ -783,7 +800,7 @@ Returns:
783800

784801
|type|description|
785802
|----|-----------|
786-
|`Result<Number, Exception>`|`Ok(value)` containing the parsed number on a successful parse or `Err(msg)` containing an error message string otherwise|
803+
|`Result<Number, Atoi.ParseIntError>`|`Ok(value)` containing the parsed number on a successful parse or `Err(msg)` containing an error message string otherwise|
787804

788805
### Number.**sin**
789806

stdlib/runtime/atoi/parse.gr

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ include "runtime/bigint" as BI
2020
include "runtime/numbers"
2121
from Numbers use { reducedInteger }
2222

23-
provide exception EmptyString
24-
provide exception InvalidDigit
25-
provide exception InvalidRadix
23+
/**
24+
* Represents an error that can occur when parsing ints.
25+
*/
26+
provide enum ParseIntError {
27+
EmptyString,
28+
InvalidDigit,
29+
InvalidRadix,
30+
}
2631

2732
primitive (&&) = "@and"
2833
primitive (||) = "@or"

stdlib/runtime/atoi/parse.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,29 @@
22
title: Parse
33
---
44

5+
## Types
6+
7+
Type declarations included in the Parse module.
8+
9+
### Parse.**ParseIntError**
10+
11+
```grain
12+
enum ParseIntError {
13+
EmptyString,
14+
InvalidDigit,
15+
InvalidRadix,
16+
}
17+
```
18+
19+
Represents an error that can occur when parsing ints.
20+
521
## Values
622

723
Functions and constants included in the Parse module.
824

925
### Parse.**parseInt**
1026

1127
```grain
12-
parseInt : (string: String, radix: Number) => Result<Number, Exception>
28+
parseInt : (string: String, radix: Number) => Result<Number, ParseIntError>
1329
```
1430

0 commit comments

Comments
 (0)