Skip to content

Commit

Permalink
fix #7669, always parse assignments the same inside macro calls
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Jan 5, 2017
1 parent cfa2312 commit 4d6f70f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ This section lists changes that do not have deprecation warnings.

* `quadgk` has been moved from Base into a separate package. ([#19741])

* In macro calls with parentheses, e.g. `@m(a=1)`, assignments are now parsed as
`=` expressions, instead of as `kw` expressions. ([#7669])

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

Expand Down
45 changes: 28 additions & 17 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@
((#\") '_str)
((#\`) '_cmd)))

(define (parse-call-chain s ex one-call)
(define (parse-call-chain s ex macrocall?)
(let loop ((ex ex))
(let ((t (peek-token s)))
(if (or (and space-sensitive (ts:space? s)
Expand All @@ -997,20 +997,27 @@
((#\( )
(if (ts:space? s) (disallowed-space ex t))
(take-token s)
(let ((c (let ((al (parse-arglist s #\) )))
(receive
(params args) (separate (lambda (x)
(and (pair? x)
(eq? (car x) 'parameters)))
al)
(if (eq? (peek-token s) 'do)
(begin
(take-token s)
`(call ,ex ,@params ,(parse-do s) ,@args))
`(call ,ex ,@al))))))
(if one-call
c
(loop c))))
(if macrocall?
(let ((args (if (eqv? (require-token s) #\) )
(begin (take-token s) '())
(begin0 (with-normal-ops
(with-whitespace-newline
(parse-comma-separated s parse-eq* #t)))
(if (not (eqv? (require-token s) #\) ))
(error "missing ) in argument list"))
(take-token s)))))
`(call ,ex ,@args))
(loop (let ((al (parse-arglist s #\) )))
(receive
(params args) (separate (lambda (x)
(and (pair? x)
(eq? (car x) 'parameters)))
al)
(if (eq? (peek-token s) 'do)
(begin
(take-token s)
`(call ,ex ,@params ,(parse-do s) ,@args))
`(call ,ex ,@al)))))))
((#\[ )
(if (ts:space? s) (disallowed-space ex t))
(take-token s)
Expand Down Expand Up @@ -1400,11 +1407,15 @@
`(,word ,@(reverse path)))))))

;; parse comma-separated assignments, like "i=1:n,j=1:m,..."
(define (parse-comma-separated s what)
(define (parse-comma-separated s what (in-parens #f))
(let loop ((exprs '()))
(let ((r (what s)))
(case (peek-token s)
((#\,) (take-token s) (loop (cons r exprs)))
((#\,)
(take-token s)
(if (and in-parens (eqv? (require-token s) #\) ))
(reverse! (cons r exprs))
(loop (cons r exprs))))
(else (reverse! (cons r exprs)))))))

(define (parse-comma-separated-assignments s)
Expand Down
3 changes: 3 additions & 0 deletions test/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,9 @@ let ..(x,y) = x + y
@test 3 .. 4 === 7
end

# issue #7669
@test parse("@a(b=1, c=2)") == Expr(:macrocall, Symbol("@a"), :(b=1), :(c=2))

# issue #19685
let f = function (x; kw...)
return (x, kw)
Expand Down

0 comments on commit 4d6f70f

Please sign in to comment.