diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-08-16 17:21:01 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-08-16 17:21:01 -0400 |
| commit | c72b0406a32ffc3f04324f7b6c321486762fca41 (patch) | |
| tree | 244e51c858890ea2ffb8c74a2c33c81b79de376e /api/nums.md | |
| parent | 849fd423a759edf1b58b548a6148c177a6f8cd71 (diff) | |
Improved parsing and prefix/suffix matching using a `remainder`
parameter
Diffstat (limited to 'api/nums.md')
| -rw-r--r-- | api/nums.md | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/api/nums.md b/api/nums.md index 471a7739..ef771171 100644 --- a/api/nums.md +++ b/api/nums.md @@ -885,7 +885,7 @@ y | `Num` | The direction towards which to find the next representable value. | ## Num.parse ```tomo -Num.parse : func(text: Text -> Num?) +Num.parse : func(text: Text, remainder: &Text? = none -> Num?) ``` Converts a text representation of a number into a floating-point number. @@ -893,6 +893,7 @@ Converts a text representation of a number into a floating-point number. Argument | Type | Description | Default ---------|------|-------------|--------- text | `Text` | The text containing the number. | - +remainder | `&Text?` | If non-none, this argument will be set to the remainder of the text after the matching part. If none, parsing will only succeed if the entire text matches. | `none` **Return:** The number represented by the text or `none` if the entire text can't be parsed as a number. @@ -900,9 +901,17 @@ text | `Text` | The text containing the number. | - **Example:** ```tomo >> Num.parse("3.14") -= 3.14 += 3.14 : Num? >> Num.parse("1e3") -= 1000 += 1000 : Num? + +>> Num.parse("1.5junk") += none : Num? +remainder : Text +>> Num.parse("1.5junk", &remainder) += 1.5 : Num? +>> remainder += "junk" ``` ## Num.percent |
