Skip to content

Commit

Permalink
parse A=>B as a call
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Feb 2, 2017
1 parent ebf2b57 commit d56eef2
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ This section lists changes that do not have deprecation warnings.
that internally uses twice-precision arithmetic. These two
outcomes exhibit differences in both precision and speed.

* `A=>B` expressions are now parsed as calls instead of using `=>` as the
expression head ([#20327]).

Library improvements
--------------------

Expand Down
2 changes: 1 addition & 1 deletion base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ const uni_ops = Set{Symbol}([:(+), :(-), :(!), :(¬), :(~), :(<:), :(>:), :(√)
const expr_infix_wide = Set{Symbol}([
:(=), :(+=), :(-=), :(*=), :(/=), :(\=), :(^=), :(&=), :(|=), :(÷=), :(%=), :(>>>=), :(>>=), :(<<=),
:(.=), :(.+=), :(.-=), :(.*=), :(./=), :(.\=), :(.^=), :(.&=), :(.|=), :(.÷=), :(.%=), :(.>>>=), :(.>>=), :(.<<=),
:(&&), :(||), :(<:), :(=>), :($=), :(⊻=)]) # `$=` should be removed after deprecation is removed, issue #18977
:(&&), :(||), :(<:), :($=), :(⊻=)]) # `$=` should be removed after deprecation is removed, issue #18977
const expr_infix = Set{Symbol}([:(:), :(->), Symbol("::")])
const expr_infix_any = union(expr_infix, expr_infix_wide)
const all_ops = union(quoted_syms, uni_ops, expr_infix_any)
Expand Down
2 changes: 1 addition & 1 deletion base/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ function parse_testset_args(args)
elseif isa(arg, Expr) && arg.head == :(=)
# we're building up a Dict literal here
key = Expr(:quote, arg.args[1])
push!(options.args, Expr(:(=>), key, arg.args[2]))
push!(options.args, Expr(:call, :(=>), key, arg.args[2]))
else
error("Unexpected argument $arg to @testset")
end
Expand Down
12 changes: 5 additions & 7 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
; operators that are special forms, not function names
(define syntactic-operators
(append! (add-dots '(= += -= *= /= //= |\\=| ^= ÷= %= <<= >>= >>>= |\|=| &= ⊻=))
'(:= --> $= => && |\|\|| |.| ... ->)))
'(:= --> $= && |\|\|| |.| ... ->)))
(define syntactic-unary-operators '($ & |::|))

(define syntactic-op? (Set syntactic-operators))
Expand Down Expand Up @@ -754,7 +754,9 @@
(let ((args (parse-chain s down '~)))
`(macrocall @~ ,ex ,@(butlast args)
,(loop (last args) (peek-token s)))))
(list t ex (parse-assignment s down)))))))
(if (eq? t '=>) ;; => is the only non-syntactic assignment-precedence operator
(list 'call t ex (parse-assignment s down))
(list t ex (parse-assignment s down))))))))

(define (parse-eq s)
(let ((lno (input-port-line (ts:port s))))
Expand Down Expand Up @@ -894,11 +896,7 @@
(else ex))))

(define (invalid-identifier-name? ex)
;; TODO: remove this hack when we remove the special Dict syntax
;; TODO: Dict syntax removed, but need to decide whether to change the parsing
;; of `a=>b` to use `call`.
(or (and (not (eq? ex '=>)) (syntactic-op? ex))
(eq? ex '....)))
(or (syntactic-op? ex) (eq? ex '....)))

(define (parse-unary s)
(let ((t (require-token s)))
Expand Down
3 changes: 0 additions & 3 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2050,9 +2050,6 @@
(error "assignment not allowed inside tuple"))
(expand-forms `(call (core tuple) ,@(cdr e))))

'=>
(lambda (e) `(call => ,(expand-forms (cadr e)) ,(expand-forms (caddr e))))

'cell1d (lambda (e) (error "{ } vector syntax is discontinued"))
'cell2d (lambda (e) (error "{ } matrix syntax is discontinued"))

Expand Down
2 changes: 2 additions & 0 deletions test/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,8 @@ end
@test_throws ParseError parse("{x=>y for (x,y) in zip([1,2,3],[4,5,6])}")
#@test_throws ParseError parse("{:a=>1, :b=>2}")

@test parse("A=>B") == Expr(:call, :(=>), :A, :B)

# this now is parsed as getindex(Pair{Any,Any}, ...)
@test_throws MethodError eval(parse("(Any=>Any)[]"))
@test_throws MethodError eval(parse("(Any=>Any)[:a=>1,:b=>2]"))
Expand Down

0 comments on commit d56eef2

Please sign in to comment.