Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand and improve pretty for core data types, vector and table. #11438

Merged
merged 27 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0f51df6
Improve pretty for `Date_Time` and `Time_Of_Day`.
jdunkerley Oct 29, 2024
0b6c5ef
Improve recovery of widget when a parameter panics.
jdunkerley Oct 29, 2024
157fab8
Fix Date_Time.
jdunkerley Oct 29, 2024
7dbd48c
Add pretty, text and js_object to `Enso_Secret`.
jdunkerley Oct 29, 2024
186f749
Fix pretty on Enso_Secret and HTTP to use `_` for the private methods.
jdunkerley Oct 29, 2024
ed6f61b
Fix pretty for Date_Time.
jdunkerley Oct 29, 2024
486aea1
Add doc comments for pretty.
jdunkerley Oct 29, 2024
4f18c02
Remove unneeded brackets.
jdunkerley Oct 29, 2024
6df9a71
Need type name in `pretty` for constructors.
jdunkerley Oct 29, 2024
2b36fc8
Tests for Date and Time_Of_Day pretty.
jdunkerley Oct 29, 2024
06c46e6
Vector.pretty and use it from Column and Table.
jdunkerley Oct 29, 2024
28c5ddc
Range.pretty.
jdunkerley Oct 29, 2024
da1a4a1
Work on tests.
jdunkerley Oct 29, 2024
2c37137
Add pretty to Array.
jdunkerley Oct 30, 2024
53d4281
Minor fixes.
jdunkerley Oct 30, 2024
28ea6b0
Add `pretty` to `Period`.
jdunkerley Oct 30, 2024
99291ad
Fix `Date_Time.pretty`.
jdunkerley Oct 30, 2024
ec1ba1f
Fix 'Column.pretty'.
jdunkerley Oct 30, 2024
8b72138
Fix `Range.pretty` and test.
jdunkerley Oct 30, 2024
33c0657
Remove dupe import.
jdunkerley Oct 30, 2024
05d97e6
Update distribution/lib/Standard/Base/0.0.0-dev/src/Enso_Cloud/Enso_S…
jdunkerley Oct 30, 2024
d24b95c
Test for `Array.pretty`.
jdunkerley Oct 30, 2024
32ef62d
Test for `Column.pretty` and `Table.pretty`.
jdunkerley Oct 30, 2024
30e4f90
Update test/Base_Tests/src/Data/Range_Spec.enso
jdunkerley Oct 30, 2024
6f71860
Update test/Base_Tests/src/Data/Range_Spec.enso
jdunkerley Oct 30, 2024
3fd6a95
Update test/Base_Tests/src/Data/Range_Spec.enso
jdunkerley Oct 30, 2024
8fd61aa
Fix tests.
jdunkerley Oct 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Any.enso
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,23 @@ type Any
to_text : Text
to_text self = @Builtin_Method "Any.to_text"

## ICON convert
Generic conversion of an arbitrary Enso value to a corresponding human-readable
representation.
## GROUP convert
ICON enso_logo
Convert the value to a corresponding Enso code representation.

> Example
Getting a human-readable representation of the number 7.
Getting the Enso code of the number 7.

7.to_text
7.pretty
## Returns a Text
7

> Example
Getting the Enso code of the text Hello World!.

"Hello World!".pretty
## Returns a Text
'Hello World!'
pretty : Text
pretty self = @Builtin_Method "Any.pretty"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,13 @@ type Array
to_display_text : Text
to_display_text self = self.short_display_text max_entries=40

## PRIVATE
GROUP convert
ICON enso_logo
Convert the value to a corresponding Enso code representation.
pretty : Text
pretty self = self.map .pretty . join ", " "[" "]"

## ICON column_add
Combines all the elements of a non-empty array using a binary operation.
If the array is empty, it returns `if_empty`.
Expand Down
17 changes: 17 additions & 0 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Data/Range.enso
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,23 @@ type Range
step = if self.step.abs == 1 then "" else " by " + self.step.to_display_text
start + step + "]"

## PRIVATE
GROUP convert
ICON enso_logo
Convert the value to a corresponding Enso code representation.

> Example
Getting the Enso code of the range 1 until 29.

1.up_to 29 . pretty
## Returns a Text
Range.new 1 29
pretty : Text
pretty self =
start = self.start.pretty
end = self.end.pretty
"Range.new " + start + " " + end + (if self.step.abs == 1 then "" else " step=" + self.step.abs.pretty)

## PRIVATE
throw_zero_step_error = Error.throw (Illegal_State.Error "A range with step = 0 is ill-formed.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import project.Panic.Panic
from project.Data.Boolean import Boolean, False, True
from project.Data.Text.Extensions import all
from project.Data.Time.Date_Time import ensure_in_epoch
from project.Metadata import Display, Widget
from project.Metadata import Display, make_single_choice, Widget
from project.Metadata.Choice import Option
from project.Widget_Helpers import make_date_format_selector

polyglot java import java.lang.ArithmeticException
Expand Down Expand Up @@ -335,7 +336,7 @@ type Date
Arguments:
- period: the period to add to self.
next : Date_Period -> Date
next self period=Date_Period.Day = self + period.to_period
next self period:Date_Period=..Day = self + period.to_period

## GROUP DateTime
ICON time
Expand All @@ -347,7 +348,7 @@ type Date
Arguments:
- period: the period to add to self.
previous : Date_Period -> Date
previous self period=Date_Period.Day = self - period.to_period
previous self period:Date_Period=..Day = self - period.to_period

## GROUP DateTime
ICON time
Expand Down Expand Up @@ -492,6 +493,8 @@ type Date
from Standard.Base import Date, Time_Of_Day, Time_Zone

example_to_time = Date.new 2020 2 3 . to_date_time Time_Of_Day.new Time_Zone.utc
@time_of_day (Time_Of_Day.default_widget include_now=False)
@zone Time_Zone.default_widget
to_date_time : Time_Of_Day -> Time_Zone -> Date_Time
to_date_time self (time_of_day=Time_Of_Day.new) (zone=Time_Zone.system) =
Time_Utils.make_zoned_date_time self time_of_day zone
Expand Down Expand Up @@ -827,9 +830,25 @@ type Date
format.format_date self

## PRIVATE
Convert to a Enso code representation of this Date.
GROUP convert
ICON enso_logo
Convert the value to a corresponding Enso code representation.

> Example
Getting the Enso code of the date 29-October-2024.

(Date.new 2024 10 29).pretty
## Returns a Text
Date.new 2024 10 29
pretty : Text
pretty self = "(Date.new " + self.year.to_text + " " + self.month.to_text + " " + self.day.to_text + ")"
pretty self = "Date.new " + self.year.to_text + " " + self.month.to_text + " " + self.day.to_text

## PRIVATE
Gets the default drop down option for Date.
default_widget : Boolean -> Widget
default_widget (include_today:Boolean=False) =
options = [Option "<Fixed Date>" "Date.new"] + (if include_today then [Option "<Today>" "Date.today"] else [])
Widget.Single_Choice values=options display=Display.When_Modified

## PRIVATE
week_days_between start end =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,22 @@ type Date_Range
start + step + "]"

## PRIVATE
Convert to a human-readable representation.
GROUP convert
ICON enso_logo
Convert the value to a corresponding Enso code representation.

> Example
Getting the Enso code of the date range 10-September-2024 until
29-October-2024.

(Date.new 2024 09 10).up_to (Date.new 2024 10 29) . pretty
## Returns a Text
Date_Range.new (Date.new 2024 09 10) (Date.new 2024 10 29)
pretty : Text
pretty self = self.to_text
pretty self =
start = self.start.pretty
end = self.end.pretty
"Date_Range.new (" + start + ") (" + end + (if self.step == (Period.new days=1) then ")" else ") (" + self.step.pretty + ")")

## PRIVATE
Converts this value to a JSON serializable object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -836,18 +836,28 @@ type Date_Time
self.format "yyyy-MM-dd "+time_format+zone_format

## PRIVATE
Convert to a Enso code representation of this Time_Of_Day.
pretty : Text
pretty self = "(Date_Time.new " + self.year.to_text + " " + self.month.to_text + " " + self.day.to_text
+ (if self.hour == 0 then "" else " hour="+self.hour.to_text)
+ (if self.minute == 0 then "" else " minute="+self.minute.to_text)
+ (if self.second == 0 then "" else " second="+self.second.to_text)
+ (if self.millisecond == 0 then "" else " millisecond="+self.millisecond.to_text)
+ (if self.microsecond == 0 then "" else " microsecond="+self.microsecond.to_text)
+ (if self.nanosecond == 0 then "" else " nanosecond="+self.nanosecond.to_text)
+ (if self.zone == Time_Zone.system then "" else " zone="+self.zone.pretty)
+ ")"
GROUP convert
ICON enso_logo
Convert the value to a corresponding Enso code representation.

> Example
Getting the Enso code of the date 29-October-2024 12:34.

(Date_Time.new 2024 10 29 12 34).pretty
## Returns a Text
Date_Time.new 2024 10 29 12 34
pretty : Text
pretty self =
parts = Vector.build builder->
builder.append ("Date_Time.new " + self.year.to_text + " " + self.month.to_text + " " + self.day.to_text)
if self.hour != 0 then builder.append ((if builder.length!=1 then " hour=" else " ") + self.hour.to_text)
if self.minute != 0 then builder.append ((if builder.length!=2 then " minute=" else " ") + self.minute.to_text)
if self.second != 0 then builder.append ((if builder.length!=3 then " second=" else " ") + self.second.to_text)
if self.millisecond != 0 then builder.append ((if builder.length!=4 then " millisecond=" else " ") + self.millisecond.to_text)
if self.microsecond != 0 then builder.append ((if builder.length!=5 then " microsecond=" else " ") + self.microsecond.to_text)
if self.nanosecond != 0 then builder.append ((if builder.length!=6 then " nanosecond=" else " ") + self.nanosecond.to_text)
if self.zone != Time_Zone.system then builder.append ((if builder.length!=7 then " zone=(" else " (") + self.zone.pretty + ")")
parts.join ""

## PRIVATE
Convert to a JavaScript Object representing a Date_Time.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,26 @@ type Period
if self.days==0 . not then builder.append ["days", self.days]
JS_Object.from_pairs v

## PRIVATE
GROUP convert
ICON enso_logo
Convert the value to a corresponding Enso code representation.

> Example
Getting the Enso code of the period 1 month and 2 days.

(Period.new months=1 days=2).pretty
## Returns a Text
Time_Of_Day.new 12 34 millisecond=500
pretty : Text
pretty self =
parts = Vector.build builder->
builder.append "Period.new"
if self.years != 0 then builder.append ((if builder.length!=1 then " years=" else " ") + self.years.to_text)
if self.months != 0 then builder.append ((if builder.length!=2 then " months=" else " ") + self.months.to_text)
if self.days != 0 then builder.append ((if builder.length!=3 then " days=" else " ") + self.days.to_text)
parts.join ""

## PRIVATE
catch_java_exceptions operation ~action =
handle_arithmetic_exception caught_panic =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import project.Data.Time.Duration.Duration
import project.Data.Time.Period.Period
import project.Data.Time.Time_Period.Time_Period
import project.Data.Time.Time_Zone.Time_Zone
import project.Data.Vector.Vector
import project.Error.Error
import project.Errors.Common.Type_Error
import project.Errors.Illegal_Argument.Illegal_Argument
Expand All @@ -20,7 +21,8 @@ import project.Nothing.Nothing
import project.Panic.Panic
from project.Data.Boolean import Boolean, False, True
from project.Data.Text.Extensions import all
from project.Metadata import Display, Widget
from project.Metadata import Display, make_single_choice, Widget
from project.Metadata.Choice import Option
from project.Widget_Helpers import make_time_format_selector

polyglot java import java.lang.Exception as JException
Expand Down Expand Up @@ -492,16 +494,34 @@ type Time_Of_Day
format.format_time self

## PRIVATE
Convert to a Enso code representation of this Time_Of_Day.
GROUP convert
ICON enso_logo
Convert the value to a corresponding Enso code representation.

> Example
Getting the Enso code of the time 12:34:00.5

(Time_Of_Day.new 12 34 0 500).pretty
## Returns a Text
Time_Of_Day.new 12 34 millisecond=500
pretty : Text
pretty self = "(Time_Of_Day.new"
+ (if self.hour == 0 then "" else " hour="+self.hour.to_text)
+ (if self.minute == 0 then "" else " minute="+self.minute.to_text)
+ (if self.second == 0 then "" else " second="+self.second.to_text)
+ (if self.millisecond == 0 then "" else " millisecond="+self.millisecond.to_text)
+ (if self.microsecond == 0 then "" else " microsecond="+self.microsecond.to_text)
+ (if self.nanosecond == 0 then "" else " nanosecond="+self.nanosecond.to_text)
+ ")"
pretty self =
parts = Vector.build builder->
builder.append "Time_Of_Day.new"
if self.hour != 0 then builder.append ((if builder.length!=1 then " hour=" else " ") + self.hour.to_text)
if self.minute != 0 then builder.append ((if builder.length!=2 then " minute=" else " ") + self.minute.to_text)
if self.second != 0 then builder.append ((if builder.length!=3 then " second=" else " ") + self.second.to_text)
if self.millisecond != 0 then builder.append ((if builder.length!=4 then " millisecond=" else " ") + self.millisecond.to_text)
if self.microsecond != 0 then builder.append ((if builder.length!=5 then " microsecond=" else " ") + self.microsecond.to_text)
if self.nanosecond != 0 then builder.append ((if builder.length!=6 then " nanosecond=" else " ") + self.nanosecond.to_text)
parts.join ""

## PRIVATE
Gets the default drop down option for Time_Of_Day.
default_widget : Boolean -> Widget
default_widget (include_now:Boolean=False) =
options = [Option "<Fixed Time>" "Time_Of_Day.new"] + (if include_now then [Option "<Now>" "Time_Of_Day.now"] else [])
Widget.Single_Choice values=options display=Display.When_Modified

## PRIVATE
Time_Of_Day.from (that:JS_Object) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,11 @@ type Time_Zone
zone_names = Time_Utils.getZoneNames

## PRIVATE
Convert to a Enso code representation of this Time_Of_Day.
GROUP convert
ICON enso_logo
Convert the value to a corresponding Enso code representation.
pretty : Text
pretty self = "(Time_Zone.parse '" + self.zone_id + "')"

pretty self = "Time_Zone.parse " + self.zone_id.pretty

## PRIVATE
Time_Zone.from (that:JS_Object) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,14 @@ type Vector a
short_display_text self (max_entries : Integer = 10) =
Array_Like_Helpers.short_display_text self max_entries

## PRIVATE
GROUP convert
ICON enso_logo
Convert the value to a corresponding Enso code representation.
pretty : Text
pretty self = self.map .pretty . join ", " "[" "]"


## ALIAS append, concatenate, union
GROUP Operators
ICON union
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ type Enso_File
"Enso_File "+self.path

## PRIVATE
Converts the file descriptor to a JSON object.
to_js_object : JS_Object
to_js_object self =
JS_Object.from_pairs [["type", "Enso_File"], ["constructor", "new"], ["path", self.path.to_text]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,19 @@ polyglot java import org.enso.base.enso_cloud.HideableValue.SecretValue
## A reference to a secret stored in the Enso Cloud.
type Enso_Secret
## PRIVATE
Value name:Text id:Text path:Enso_Path
private Value internal_name:Text id:Text internal_path:Enso_Path

## GROUP Metadata
ICON metadata
The name of the secret.
name : Text
name self = self.internal_name

## GROUP Metadata
ICON metadata
The path of the secret.
path : Text
path self = self.internal_path.to_text

## GROUP Output
ICON edit
Expand Down Expand Up @@ -146,6 +158,29 @@ type Enso_Secret
EnsoSecretHelper.deleteSecretFromCache self.id
self

## PRIVATE
Returns a text representation of the secret.
to_text : Text
to_text self = "Enso_Secret " + self.path.to_text

## PRIVATE
Returns a display text representation of the secret.
to_display_text : Text
to_display_text self = "Enso_Secret {" + self.name + "}"

## PRIVATE
Converts the secret to a JSON object.
to_js_object : JS_Object
to_js_object self =
JS_Object.from_pairs [["type", "Enso_Secret"], ["constructor", "get"], ["path", self.path.to_text]]

## PRIVATE
GROUP convert
ICON enso_logo
Convert the value to a corresponding Enso code representation.
pretty : Text
pretty self = "Enso_Secret.get " + self.path.to_text.pretty

## PRIVATE
type Enso_Secret_Error
## PRIVATE
Expand Down
Loading
Loading