diff --git a/src/julia-parser.scm b/src/julia-parser.scm index 24511fb6aef6d..1ac93141b6406 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -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 @@ -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) @@ -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))) diff --git a/test/syntax.jl b/test/syntax.jl index 04e982cb7ebb8..28afb15ba3b1e 100644 --- a/test/syntax.jl +++ b/test/syntax.jl @@ -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)))