Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #7669, always parse assignments the same inside macro calls #19868

Merged
merged 1 commit into from
Jan 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ This section lists changes that do not have deprecation warnings.
* The `RepString` type has been moved to the
[LegacyStrings.jl package](https://github.com/JuliaArchive/LegacyStrings.jl).

* 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