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 Jan 31, 2017
1 parent 78941c7 commit 3798fee
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,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 @@ -471,7 +471,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 @@ -73,7 +73,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 @@ -753,7 +753,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 @@ -893,11 +895,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 @@ -2049,9 +2049,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

0 comments on commit 3798fee

Please sign in to comment.