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

RFC: fix #26137, change parsing of unary ops on parenthesized expressions #26154

Merged
merged 3 commits into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
preserve empty parameters in parser
  • Loading branch information
JeffBezanson committed Feb 23, 2018
commit d6b75d1f5bf09d395c58e1129529eee747922348
4 changes: 2 additions & 2 deletions src/ast.scm
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
(if (has-parameters? l)
(string (string.join (map deparse (cdr l)) sep)
(if (length= (cdr l) 1) "," "")
"; "
(string.join (map deparse (cdar l)) ", "))
(deparse (car l)))
(string.join (map deparse l) sep)))

(define (deparse-prefix-call head args opn cls)
Expand Down Expand Up @@ -95,6 +94,7 @@
(if (length= e 3)
(deparse (caddr e))
(deparse (cons 'braces (cddr e))))))
((parameters) (string "; " (deparse-arglist (cdr e))))
;; bracket forms
((tuple)
(string #\( (deparse-arglist (cdr e))
Expand Down
17 changes: 7 additions & 10 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1740,15 +1740,12 @@
(reverse! lst)))
(if (eqv? t #\;)
(begin (take-token s)
(if (eqv? (peek-token s) closer)
;; allow f(a, b; )
(loop lst)
(let ((params (loop '()))
(lst (if (eqv? closer #\) )
(to-kws (reverse lst))
(reverse lst))))
(cons (cons 'parameters params)
lst))))
(let ((params (loop '()))
(lst (if (eqv? closer #\) )
(to-kws (reverse lst))
(reverse lst))))
(cons (cons 'parameters params)
lst)))
(let* ((nxt (parse-eq* s))
(c (require-token s)))
(cond ((eqv? c #\,)
Expand Down Expand Up @@ -1793,7 +1790,7 @@
(if (eqv? (require-token s) closer)
(loop lst nxt)
(let ((params (parse-call-arglist s closer)))
(if (null? params)
(if (or (null? params) (equal? params '((parameters))))
(begin (parser-depwarn s (deparse `(vect (parameters) ,@(reverse lst) ,nxt))
(deparse `(vcat ,@(reverse lst) ,nxt)))
;; TODO: post 0.7, remove deprecation and change parsing to 'vect
Expand Down
4 changes: 3 additions & 1 deletion test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ macro test999_str(args...); args; end
@test Meta.parse("(;x)") == Expr(:tuple, Expr(:parameters, :x))
@test Meta.parse("(;x,)") == Expr(:tuple, Expr(:parameters, :x))
@test Meta.parse("(x,)") == Expr(:tuple, :x)
@test Meta.parse("(x,;)") == Expr(:tuple, :x)
@test Meta.parse("(x,;)") == Expr(:tuple, Expr(:parameters), :x)
@test Meta.parse("(x;y)") == Expr(:block, :x, :y)
@test Meta.parse("(x=1;y=2)") == Expr(:block, Expr(:(=), :x, 1), Expr(:(=), :y, 2))
@test Meta.parse("(x,;y)") == Expr(:tuple, Expr(:parameters, :y), :x)
Expand All @@ -190,6 +190,8 @@ macro test999_str(args...); args; end
@test Meta.parse("(a=1, b=2)") == Expr(:tuple, Expr(:(=), :a, 1), Expr(:(=), :b, 2))
@test_throws ParseError Meta.parse("(1 2)") # issue #15248

@test Meta.parse("f(x;)") == Expr(:call, :f, Expr(:parameters), :x)

@test Meta.parse("1 == 2|>3") == Expr(:call, :(==), 1, Expr(:call, :(|>), 2, 3))

# issue #24153
Expand Down