-
Notifications
You must be signed in to change notification settings - Fork 326
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
:
operator is left-associative
#11671
Conversation
Allows chained conversions, like `3.14 : Integer : Text`. I have verified with `parse_all_enso_files.sh` that this doesn't change the interpretation of any of the libs or .enso tests; no one is likely relying on the current behavior.
This actually conflicts with a syntax that is covered by unit tests, but not currently used--using
I will see if I can reconcile this syntax with chained conversions by adjusting precedence also. |
} | ||
|
||
/// Return the precedence for any operator. | ||
/// Return the lowest precedence for any operator. | ||
pub fn min_valid() -> Self { |
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.
min_valid
is relatively cryptic name.
'*' | '/' | '%' => 16, | ||
'^' => 17, | ||
_ => 18, | ||
'!' => token::Precedence::Not, |
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.
The use of enum
makes the code more readable.
pub fn min_valid() -> Self { | ||
Precedence { value: 1 } | ||
debug_assert_eq!(Precedence::Assignment as u8, Precedence::Min as u8 + 1); |
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.
An assert that two enum
values are next to each other!? Can it be false? Shouldn't it be apparent or a check to verify in a test and not code?
lhs_section_termination: Some(SectionTermination::Reify), | ||
is_right_associative: true, |
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 have it! This is the line that changes the behavior! The rests are just refactorings.
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.
This and the precedence change--:
and =
both had precedence 2, and now they have different levels in the named level order.
Some simplification enabled by the refactor in #11671. Inspired by review from @JaroslavTulach.
Pull Request Description
Adjust operator parsing to allow chained conversions, like
3.14 : Integer : Text
.Change the precedence and associativity of the
:
operator, when used as a binary operator in an expression:->
(previously they were equal)Important Notes
One previously-reasonable syntax has changed interpretation:
x->x:Type
is no longer a valid way to write a casting function, and would likely result in a type error. There was 1 instance of this syntax in our .enso sources.Checklist
Please ensure that the following checklist has been satisfied before submitting the PR:
Scala,
Java,
TypeScript,
and
Rust
style guides. In case you are using a language not listed above, follow the Rust style guide.
or the Snowflake database integration, a run of the Extra Tests has been scheduled.