-
Notifications
You must be signed in to change notification settings - Fork 323
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
Adding type annotations and enabling auto-scoping #10173
Changes from all commits
3fc1925
ba5cd27
397086e
0251163
2dab8ab
9d32c2f
568f9e5
2f1338b
352be81
6096ec1
e98a123
795f56f
dd6a2b8
6f8b36f
19b16cd
98359bb
982f4ab
5508f50
0a93ce7
b1733b4
32c16a7
df74d11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,12 @@ import project.Data.Text.Text | |
import project.Data.Vector.Vector | ||
import project.Error.Error | ||
import project.Errors.Common.Incomparable_Values | ||
import project.Errors.Common.Missing_Argument | ||
import project.Errors.Illegal_Argument.Illegal_Argument | ||
import project.Function.Function | ||
import project.Meta | ||
import project.Nothing.Nothing | ||
import project.Panic.Panic | ||
from project.Data.Boolean import Boolean, False, True | ||
from project.Data.Filter_Condition.Filter_Condition import all | ||
from project.Data.Text.Extensions import all | ||
|
@@ -22,25 +24,25 @@ polyglot java import org.enso.base.Regex_Utils | |
|
||
type Filter_Condition | ||
## Is less than a value (or another column, in case of Table operations)? | ||
Less than:Any action:Filter_Action=Filter_Action.Keep | ||
Less than=(Missing_Argument.throw "than") action:Filter_Action=Filter_Action.Keep | ||
|
||
## Is less than or equal to a value (or another column, in case of Table operations)? | ||
Equal_Or_Less than:Any action:Filter_Action=Filter_Action.Keep | ||
Equal_Or_Less than=(Missing_Argument.throw "than") action:Filter_Action=Filter_Action.Keep | ||
|
||
## Is equal to a value (or another column, in case of Table operations)? | ||
Equal to:Any action:Filter_Action=Filter_Action.Keep | ||
Equal to=(Missing_Argument.throw "to") action:Filter_Action=Filter_Action.Keep | ||
|
||
## Is greater than or equal to a value (or another column, in case of Table operations)? | ||
Equal_Or_Greater than:Any action:Filter_Action=Filter_Action.Keep | ||
Equal_Or_Greater than=(Missing_Argument.throw "than") action:Filter_Action=Filter_Action.Keep | ||
|
||
## Is greater than a value (or another column, in case of Table operations)? | ||
Greater than:Any action:Filter_Action=Filter_Action.Keep | ||
Greater than=(Missing_Argument.throw "than") action:Filter_Action=Filter_Action.Keep | ||
|
||
## Is not equal to a value (or another column, in case of Table operations)? | ||
Not_Equal to:Any action:Filter_Action=Filter_Action.Keep | ||
Not_Equal to=(Missing_Argument.throw "to") action:Filter_Action=Filter_Action.Keep | ||
|
||
## Is between (inclusive) two values (or columns, in case of Table operations)? | ||
Between lower:Any upper:Any action:Filter_Action=Filter_Action.Keep | ||
Between lower=(Missing_Argument.throw "lower") upper=(Missing_Argument.throw "upper") action:Filter_Action=Filter_Action.Keep | ||
|
||
## Is equal to another value, ignoring case (Text only)? | ||
|
||
|
@@ -55,31 +57,31 @@ type Filter_Condition | |
This ensures that different ways of expressing the same character in | ||
the underlying binary representation are considered equal. | ||
@locale Locale.default_widget | ||
Equal_Ignore_Case (to : Text | Any) (locale:Locale=Locale.default) action:Filter_Action=Filter_Action.Keep | ||
Equal_Ignore_Case (to = (Missing_Argument.throw "to")) (locale:Locale=Locale.default) action:Filter_Action=Filter_Action.Keep | ||
|
||
## Does the value start with a prefix (Text only)? | ||
|
||
? Table Operations | ||
It accepts a Text value to check if the value contains it. In case of | ||
Table operations, it can accept another column - then the corresponding | ||
values from the source column and the provided column are checked. | ||
Starts_With (prefix : Text | Any) (case_sensitivity:Case_Sensitivity=Case_Sensitivity.Default) action:Filter_Action=Filter_Action.Keep | ||
Starts_With (prefix = (Missing_Argument.throw "prefix")) (case_sensitivity:Case_Sensitivity=Case_Sensitivity.Default) action:Filter_Action=Filter_Action.Keep | ||
|
||
## Does the value end with a suffix (Text only)? | ||
|
||
? Table Operations | ||
It accepts a Text value to check if the value contains it. In case of | ||
Table operations, it can accept another column - then the corresponding | ||
values from the source column and the provided column are checked. | ||
Ends_With (suffix : Text | Any) (case_sensitivity:Case_Sensitivity=Case_Sensitivity.Default) action:Filter_Action=Filter_Action.Keep | ||
Ends_With (suffix = (Missing_Argument.throw "suffix")) (case_sensitivity:Case_Sensitivity=Case_Sensitivity.Default) action:Filter_Action=Filter_Action.Keep | ||
|
||
## Does the value contain the substring (Text only)? | ||
|
||
? Table Operations | ||
It accepts a Text value to check if the value contains it. In case of | ||
Table operations, it can accept another column - then the corresponding | ||
values from the source column and the provided column are checked. | ||
Contains (substring : Text | Any) (case_sensitivity:Case_Sensitivity=Case_Sensitivity.Default) action:Filter_Action=Filter_Action.Keep | ||
Contains (substring = (Missing_Argument.throw "substring")) (case_sensitivity:Case_Sensitivity=Case_Sensitivity.Default) action:Filter_Action=Filter_Action.Keep | ||
|
||
## Is equal to Nothing? | ||
Is_Nothing action:Filter_Action=Filter_Action.Keep | ||
|
@@ -127,7 +129,7 @@ type Filter_Condition | |
Due to this limitation, Unicode normalization has been disabled for | ||
this function, so beware that some equivalent graphemes like 'ś' and | ||
's\u0301' will not be matched. | ||
Like (pattern : Text | Any) action:Filter_Action=Filter_Action.Keep | ||
Like (pattern = (Missing_Argument.throw "pattern")) action:Filter_Action=Filter_Action.Keep | ||
|
||
## Is the value contained in `values`? | ||
|
||
|
@@ -141,7 +143,16 @@ type Filter_Condition | |
Using Columns can be particularly useful for Database operations, as | ||
uploading a temporary table and using its column for an `Is_In` check | ||
will likely be faster than using the vector directly. | ||
Is_In values:Vector|Any action:Filter_Action=Filter_Action.Keep | ||
Is_In values=[] action:Filter_Action=Filter_Action.Keep | ||
|
||
## PRIVATE | ||
Resolves a possibly auto-scoped value to a concrete value. | ||
resolve_auto_scoped : Any -> Any | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't in this case as used across different libraries but yes will do. |
||
resolve_auto_scoped filter = | ||
resolve filter:Filter_Condition = filter | ||
case filter of | ||
_ : Function -> Panic.catch Any (resolve filter) _->filter | ||
_ -> filter | ||
|
||
## ICON convert | ||
Converts a `Filter_Condition` condition into a predicate taking an | ||
|
@@ -295,43 +306,15 @@ unify_condition_or_predicate : Filter_Condition | (Any -> Boolean) -> (Any -> Bo | |
unify_condition_or_predicate (condition_or_predicate : Filter_Condition | (Any -> Boolean)) = | ||
case condition_or_predicate of | ||
condition : Filter_Condition -> condition.to_predicate | ||
predicate -> handle_constructor_missing_arguments predicate predicate | ||
predicate -> predicate | ||
|
||
## PRIVATE | ||
unify_condition_predicate_or_element condition = | ||
case condition of | ||
condition : Filter_Condition -> condition.to_predicate | ||
predicate : Function -> handle_constructor_missing_arguments predicate predicate | ||
predicate : Function -> predicate | ||
element -> (== element) | ||
|
||
## PRIVATE | ||
Checks if the given `function` is actually a `Filter_Condition` constructor | ||
that is just missing arguments. If so, it will report a more friendly error. | ||
Otherwise it will run the `continuation`. | ||
handle_constructor_missing_arguments function ~continuation = | ||
Comment on lines
-304
to
-311
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good that we no longer need this :) |
||
is_filter_condition_constructor = case Meta.meta function of | ||
constructor : Meta.Constructor -> | ||
constructor.declaring_type == Meta.meta Filter_Condition | ||
## Special case for multi-argument constructors with some but not all | ||
arguments applied. | ||
|
||
For example, `Meta.meta (Filter_Condition.Between 10)` will return a `Meta.Primitive`. | ||
We rely on its text representation being of the form `Filter_Condition.Between[Filter_Condition.enso:41-343]`. | ||
_ : Meta.Primitive -> | ||
text = function.to_text | ||
prefix = "Filter_Condition." | ||
if (text.starts_with prefix && text.contains "[Filter_Condition.enso:") . not then False else | ||
## The additional check for capital letter is needed, because otherwise, we get false positives: | ||
`(Filter_Condition.Greater 1).to_predicate` evaluates to function whose text representation | ||
may start with `Filter_Condition.handle_nothing`. Such functions are not constructors. | ||
constructor_letter = text.get prefix.length "" | ||
constructor_letter >= "A" && constructor_letter <= "Z" | ||
|
||
_ -> False | ||
if is_filter_condition_constructor.not then continuation else | ||
message = "Got a Filter_Condition constructor without all required arguments provided. Please provide the missing arguments." | ||
Error.throw (Illegal_Argument.Error message) | ||
|
||
## PRIVATE | ||
Extends the provided predicate to handle `Nothing` values without error. | ||
The new predicate will return `False` for `Nothing`. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ type Case_Sensitivity | |
|
||
Arguments: | ||
- locale: The locale used for the comparison. | ||
@locale Locale.default_widget | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a defect somewhere else that you need to add this? |
||
Insensitive (locale : Locale = Locale.default) | ||
|
||
## PRIVATE | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enso/distribution/lib/Standard/Base/0.0.0-dev/src/Errors/Common.enso
Line 79 in 4aa3d52
feel free to reformulate the sentece anyway you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will try this in the next PR and if it works switch to then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @jdunkerley, does the
approach work for you? Can it be used instead of `Missing_Argument.throw "than", please? CCing @GregoryTravis
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the best solution now because it requires no changes to Numbers.enso type signatures. It adds a special case to the error class but that seems acceptable.