@@ -1131,6 +1131,10 @@ function isidentifier(s::AbstractString)
1131
1131
end
1132
1132
isidentifier (s:: Symbol ) = isidentifier (string (s))
1133
1133
1134
+ is_op_suffix_char (c:: AbstractChar ) = ccall (:jl_op_suffix_char , Cint, (UInt32,), c) != 0
1135
+
1136
+ _isoperator (s) = ccall (:jl_is_operator , Cint, (Cstring,), s) != 0
1137
+
1134
1138
"""
1135
1139
isoperator(s::Symbol)
1136
1140
@@ -1142,7 +1146,7 @@ julia> Base.isoperator(:+), Base.isoperator(:f)
1142
1146
(true, false)
1143
1147
```
1144
1148
"""
1145
- isoperator (s:: Union{Symbol,AbstractString} ) = ccall ( :jl_is_operator , Cint, (Cstring,), s) != 0
1149
+ isoperator (s:: Union{Symbol,AbstractString} ) = _isoperator (s) || ispostfixoperator (s)
1146
1150
1147
1151
"""
1148
1152
isunaryoperator(s::Symbol)
@@ -1169,7 +1173,26 @@ julia> Base.isbinaryoperator(:-), Base.isbinaryoperator(:√), Base.isbinaryoper
1169
1173
(true, false, false)
1170
1174
```
1171
1175
"""
1172
- isbinaryoperator (s:: Symbol ) = isoperator (s) && (! isunaryoperator (s) || is_unary_and_binary_operator (s))
1176
+ function isbinaryoperator (s:: Symbol )
1177
+ return _isoperator (s) && (! isunaryoperator (s) || is_unary_and_binary_operator (s)) &&
1178
+ s != = Symbol (" '" )
1179
+ end
1180
+
1181
+ """
1182
+ ispostfixoperator(s::Union{Symbol,AbstractString})
1183
+
1184
+ Return `true` if the symbol can be used as a postfix operator, `false` otherwise.
1185
+
1186
+ # Examples
1187
+ ```jldoctest
1188
+ julia> Base.ispostfixoperator(Symbol("'")), Base.ispostfixoperator(Symbol("'ᵀ")), Base.ispostfixoperator(:-)
1189
+ (true, true, false)
1190
+ ```
1191
+ """
1192
+ function ispostfixoperator (s:: Union{Symbol,AbstractString} )
1193
+ s = String (s)
1194
+ return startswith (s, ' \' ' ) && all (is_op_suffix_char, SubString (s, 2 ))
1195
+ end
1173
1196
1174
1197
"""
1175
1198
operator_precedence(s::Symbol)
@@ -1594,6 +1617,20 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In
1594
1617
end
1595
1618
head != = :row && print (io, cl)
1596
1619
1620
+ # transpose
1621
+ elseif (head === Symbol (" '" ) && nargs == 1 ) || (
1622
+ # ' with unicode suffix is a call expression
1623
+ head === :call && nargs == 2 && args[1 ] isa Symbol &&
1624
+ ispostfixoperator (args[1 ]) && args[1 ] != = Symbol (" '" )
1625
+ )
1626
+ op, arg1 = head === Symbol (" '" ) ? (head, args[1 ]) : (args[1 ], args[2 ])
1627
+ if isa (arg1, Expr) || (isa (arg1, Symbol) && isoperator (arg1))
1628
+ show_enclosed_list (io, ' (' , [arg1], " , " , ' )' , indent, 0 )
1629
+ else
1630
+ show_unquoted (io, arg1, indent, 0 , quote_level)
1631
+ end
1632
+ print (io, op)
1633
+
1597
1634
# function call
1598
1635
elseif head === :call && nargs >= 1
1599
1636
func = args[1 ]
@@ -1622,7 +1659,7 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In
1622
1659
end
1623
1660
1624
1661
# unary operator (i.e. "!z")
1625
- elseif isa (func,Symbol) && func in uni_ops && length (func_args) == 1
1662
+ elseif isa (func,Symbol) && length (func_args) == 1 && func in uni_ops
1626
1663
show_unquoted (io, func, indent, 0 , quote_level)
1627
1664
arg1 = func_args[1 ]
1628
1665
if isa (arg1, Expr) || (isa (arg1, Symbol) && isoperator (arg1))
@@ -1959,17 +1996,6 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In
1959
1996
parens && print (io, " )" )
1960
1997
end
1961
1998
1962
- # transpose
1963
- elseif head === Symbol (' \' ' ) && nargs == 1
1964
- if isa (args[1 ], Symbol)
1965
- show_unquoted (io, args[1 ], 0 , 0 , quote_level)
1966
- else
1967
- print (io, " (" )
1968
- show_unquoted (io, args[1 ], 0 , 0 , quote_level)
1969
- print (io, " )" )
1970
- end
1971
- print (io, head)
1972
-
1973
1999
# `where` syntax
1974
2000
elseif head === :where && nargs > 1
1975
2001
parens = 1 <= prec
0 commit comments