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 unary-related parsing regressions caused by #26154 #26239

Merged
merged 1 commit into from
Feb 28, 2018
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
24 changes: 14 additions & 10 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1039,11 +1039,13 @@
(if (cdr parens) ;; found an argument list
(if opspc
(disallowed-space op #\( )
(parse-factor-with-initial-ex
s
(fix-syntactic-unary (cons op (tuple-to-arglist (car parens))))))
(parse-juxtapose
(parse-factor-with-initial-ex
s
(fix-syntactic-unary (cons op (tuple-to-arglist (car parens)))))
s))
(fix-syntactic-unary
(list op (parse-factor-with-initial-ex s (car parens)))))))
(list op (parse-juxtapose (parse-factor-with-initial-ex s (car parens)) s))))))
((not un)
(error (string "\"" op "\" is not a unary operator")))
(else
Expand Down Expand Up @@ -1098,10 +1100,10 @@
;; -2^3 is parsed as -(2^3), so call parse-decl for the first argument,
;; and parse-unary from then on (to handle 2^-3)
(define (parse-factor s)
(parse-factor-with-initial-ex s (parse-call s)))
(parse-factor-with-initial-ex s (parse-unary-prefix s)))

(define (parse-factor-with-initial-ex s ex0)
(let* ((ex (parse-decl-with-initial-ex s ex0))
(let* ((ex (parse-decl-with-initial-ex s (parse-call-with-initial-ex s ex0)))
(t (peek-token s)))
(if (is-prec-power? t)
(begin (take-token s)
Expand Down Expand Up @@ -1130,10 +1132,12 @@
;; parse function call, indexing, dot, and transpose expressions
;; also handles looking for syntactic reserved words
(define (parse-call s)
(let ((ex (parse-unary-prefix s)))
(if (or (initial-reserved-word? ex) (eq? ex 'mutable) (eq? ex 'primitive) (eq? ex 'abstract))
(parse-resword s ex)
(parse-call-chain s ex #f))))
(parse-call-with-initial-ex s (parse-unary-prefix s)))

(define (parse-call-with-initial-ex s ex)
(if (or (initial-reserved-word? ex) (eq? ex 'mutable) (eq? ex 'primitive) (eq? ex 'abstract))
(parse-resword s ex)
(parse-call-chain s ex #f)))

(define (parse-unary-prefix s)
(let ((op (peek-token s)))
Expand Down
10 changes: 10 additions & 0 deletions test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1341,3 +1341,13 @@ end

@test Meta.parse("1 -+(a=1, b=2)") == Expr(:call, :-, 1,
Expr(:call, :+, Expr(:kw, :a, 1), Expr(:kw, :b, 2)))

@test Meta.parse("-(2)(x)") == Expr(:call, :-, Expr(:call, :*, 2, :x))
@test Meta.parse("-(x)y") == Expr(:call, :-, Expr(:call, :*, :x, :y))
@test Meta.parse("-(x,)y") == Expr(:call, :*, Expr(:call, :-, :x), :y)
@test Meta.parse("-(f)(x)") == Expr(:call, :-, Expr(:call, :f, :x))
@test Meta.parse("-(2)(x)^2") == Expr(:call, :-, Expr(:call, :*, 2, Expr(:call, :^, :x, 2)))
@test Meta.parse("Y <- (x->true)(X)") ==
Expr(:call, :<, :Y,
Expr(:call, :-, Expr(:call, Expr(:->, :x, Expr(:block, LineNumberNode(1,:none), true)),
:X)))