Skip to content

Commit

Permalink
add => to operator precedence table (#28026)
Browse files Browse the repository at this point in the history
  • Loading branch information
swissr authored and JeffBezanson committed Jul 11, 2018
1 parent 3a4c05e commit 060e51b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -869,8 +869,9 @@ julia> Base.operator_precedence(:sin), Base.operator_precedence(:+=), Base.opera
operator_precedence(s::Symbol) = Int(ccall(:jl_operator_precedence, Cint, (Cstring,), s))
operator_precedence(x::Any) = 0 # fallback for generic expression nodes
const prec_assignment = operator_precedence(:(=))
const prec_arrow = operator_precedence(:(-->))
const prec_pair = operator_precedence(:(=>))
const prec_control_flow = operator_precedence(:(&&))
const prec_arrow = operator_precedence(:(-->))
const prec_comparison = operator_precedence(:(>))
const prec_power = operator_precedence(:(^))
const prec_decl = operator_precedence(:(::))
Expand All @@ -892,7 +893,7 @@ julia> Base.operator_associativity(:⊗), Base.operator_associativity(:sin), Bas
```
"""
function operator_associativity(s::Symbol)
if operator_precedence(s) in (prec_arrow, prec_assignment, prec_control_flow, prec_power) ||
if operator_precedence(s) in (prec_arrow, prec_assignment, prec_control_flow, prec_pair, prec_power) ||
(isunaryoperator(s) && !is_unary_and_binary_operator(s)) || s === :<|
return :right
elseif operator_precedence(s) in (0, prec_comparison) || s in (:+, :++, :*)
Expand Down
1 change: 1 addition & 0 deletions doc/src/manual/mathematical-operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ Julia applies the following order and associativity of operations, from highest
| Syntax | `<\|` | Right |
| Comparisons | `> < >= <= == === != !== <:` | Non-associative |
| Control flow | `&&` followed by `\|\|` followed by `?` | Right |
| Pair | `=>` | Right |
| Assignments | `= += -= *= /= //= \= ^= ÷= %= \|= &= ⊻= <<= >>= >>>=` | Right |

[^1]:
Expand Down

0 comments on commit 060e51b

Please sign in to comment.