Skip to content

Commit

Permalink
Add parse extensions to Text type. #6330 (#6404)
Browse files Browse the repository at this point in the history
Add type-specific parse stubs to Text, e.g.:
Text.parse_json self -> Json =
Text.parse_url self -> Url =
Text.parse_number self -> Number =
  • Loading branch information
GregoryTravis authored and Akirathan committed Apr 26, 2023
1 parent 054abee commit 4a2720b
Show file tree
Hide file tree
Showing 9 changed files with 423 additions and 62 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@
for thousands and decimal point automatic detection.][6253]
- [Implemented `Table.parse_text_to_table`.][6294]
- [Added `Table.parse_to_columns`.][6383]
- [Added parsing methods for `Integer`, `Decimal`, `Json`, `Date`, `Date_Time`,
`Time_Of_Day`, `Time_Zone`, and `URI` to `Text`.][6404]

[debug-shortcuts]:
https://github.com/enso-org/enso/blob/develop/app/gui/docs/product/shortcuts.md#debug
Expand Down Expand Up @@ -593,6 +595,7 @@
[6253]: https://github.com/enso-org/enso/pull/6253
[6294]: https://github.com/enso-org/enso/pull/6294
[6383]: https://github.com/enso-org/enso/pull/6383
[6404]: https://github.com/enso-org/enso/pull/6404

#### Enso Compiler

Expand Down
10 changes: 9 additions & 1 deletion distribution/lib/Standard/Base/0.0.0-dev/src/Data/Json.enso
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@ from project.Data.Boolean import Boolean, True, False

## Methods for serializing from and to JSON.
type Json
## Parse a Text value into a `JS_Object` or an Enso primitive value (like `Text`, `Number`, `Boolean`, `Nothing`), or a `Vector` of values.
## ALIAS From Text

Parse a Text value into a `JS_Object` or an Enso primitive value (like
`Text`, `Number`, `Boolean`, `Nothing`), or a `Vector` of values.

> Example
Parse the text "[null, null, true, false]".

Json.parse "[null, null, true, false]"
parse : Text -> JS_Object | Boolean | Number | Nothing | Text | Vector ! Invalid_JSON
parse json =
error_handler js_exception =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -926,13 +926,14 @@ type Integer

Arguments:
- text: The text to parse into a integer.
- radix: The number base to use for parsing (defaults to 10).
- radix: The number base to use for parsing (defaults to 10). `radix`
must be between 2 and 36 (inclusive) -- see https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/lang/Character.html#MIN_RADIX.

> Example
Parse the text "20220216" into an integer number.

Integer.parse "20220216"
parse : Text -> Text -> Integer ! Number_Parse_Error
parse : Text -> Integer -> Integer ! Number_Parse_Error
parse text (radix=10) = Integer.parse_builtin text radix

## PRIVATE
Expand Down
Loading

0 comments on commit 4a2720b

Please sign in to comment.