-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Change 'mixed left- and right-associative operators' to Message #1985
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
Changes from 1 commit
defbe7d
dcf7877
85dae44
835d24f
16b25a7
c5c1198
1f72283
2d2795e
e1dcd1a
f8a93f5
1df5ef7
de28414
ac2e14c
d4febc6
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 |
---|---|---|
|
@@ -1086,4 +1086,37 @@ object messages { | |
|""".stripMargin | ||
} | ||
|
||
case class MixedLeftAndRightAssociativeOps(op1: Name, op2: Name, op2LeftAssoc: Boolean)(implicit ctx: Context) | ||
extends Message(41) { | ||
val kind = "Syntax" | ||
val op1Asso = if (op2LeftAssoc) "which is right-associative" else "which is left-associative" | ||
val op2Asso = if (op2LeftAssoc) "which is left-associative" else "which is right-associative" | ||
val msg = s"${hl"`${op1}`"} (${op1Asso}) and ${hl"`${op2}`"} ($op2Asso) have same precedence and may not be mixed" | ||
val explanation = | ||
s"""|The operators ${hl"${op1}"} and ${hl"${op2}"} are used as infix operators in the same expression, | ||
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. why not use the Anyway, choose the lesser evil - if |
||
|but they bind to different sides: | ||
|${hl"${op1}"} is applied to the operand to its ${if (op2LeftAssoc) "right" else "left"} | ||
|${hl"${op2}"} is applied to the operand to its ${if (op2LeftAssoc) "left" else "right"} | ||
|As both have the same precedence the compiler can't decide which to apply first. | ||
| | ||
|You may use parenthesis to make the application order explicit, | ||
|or use method application syntax ${hl"`operand1.${op1}(operand2)`"}. | ||
| | ||
|Operators ending in a colon `:` are right-associative. All other operators are left-associative. | ||
| | ||
|Infix operator precedence is determined by the operator's first character: | ||
| (all letters) | ||
| | | ||
| ^ | ||
| & | ||
| = ! | ||
| < > | ||
| : | ||
| + - | ||
| * / % | ||
| (all other special characters) | ||
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. Hmm, just reading this with my noob-glasses on, I'd think that letters had the greatest precedence. Then I'd see the sentence on the next line... 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. You're right. I added a bit more from the language spec. |
||
|Operators starting with a letter have lowest precedence, followed by operators starting with `|', etc. | ||
|""".stripMargin | ||
} | ||
|
||
} |
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'm assuming you want to avoid a larger diff, but it looks weird that
op2
is at the end. If you want to refactor that - put it in a second commit and we'll merge both of them unsquished.