diff --git a/src/julia-parser.scm b/src/julia-parser.scm index 08c23232dff0f..b58e6c0610d67 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -926,6 +926,14 @@ (else (list op (parse-unary-prefix s))))) (parse-atom s)))) +(define (parse-atom-or-interpolate s) + (if (eq? (peek-token s) '$) + (begin (take-token s) + (if (let ((op (peek-token s))) + (or (newline? op) (closing-token? op))) + '$ (list '$ (parse-atom s)))) + (parse-atom s))) + ;; parse function call, indexing, dot, and transpose expressions ;; also handles looking for syntactic reserved words (define (parse-call s) @@ -1250,7 +1258,7 @@ body)))) ((export) (let ((es (map macrocall-to-atsym - (parse-comma-separated s parse-unary-prefix)))) + (parse-comma-separated s parse-atom-or-interpolate)))) (if (not (every symbol-or-interpolate? es)) (error "invalid \"export\" statement")) `(export ,@es))) @@ -1332,7 +1340,7 @@ (begin (take-token s) (loop (list* '|.| '|.| '|.| '|.| l) (peek-token s)))) (else - (cons (macrocall-to-atsym (parse-unary-prefix s)) l))))) + (cons (macrocall-to-atsym (parse-atom-or-interpolate s)) l))))) (define (parse-import s word) (let loop ((path (parse-import-dots s))) @@ -1342,7 +1350,7 @@ (cond ((eq? nxt '|.|) (take-token s) - (loop (cons (macrocall-to-atsym (parse-unary-prefix s)) path))) + (loop (cons (macrocall-to-atsym (parse-atom-or-interpolate s)) path))) ((or (memv nxt '(#\newline #\; #\, :)) (eof-object? nxt)) `(,word ,@(reverse path))) diff --git a/test/parser.jl b/test/parser.jl index 1bc6595937d61..b5e53b81e9bc0 100644 --- a/test/parser.jl +++ b/test/parser.jl @@ -1,5 +1,21 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license +function parseall(str) + pos = start(str) + exs = [] + while !done(str, pos) + ex, pos = parse(str, pos) + push!(exs, ex) + end + if length(exs) == 0 + throw(ParseError("end of input")) + elseif length(exs) == 1 + return exs[1] + else + return Expr(:block, exs...) + end +end + # issue #9684 let for (ex1, ex2) in [("5.≠x", "5.!=x"), @@ -120,3 +136,9 @@ macro test999_str(args...); args; end @test parse("using \$a: \$b, \$c.\$d") == Expr(:toplevel, Expr(:using, Expr(:$, :a), Expr(:$, :b)), Expr(:using, Expr(:$, :a), Expr(:$, :c), Expr(:$, :d))) + +# fix pr #11338 +@test parseall("using \$\na") == Expr(:block, Expr(:using, :$), :a) +@test parseall("using \$,\na") == Expr(:toplevel, Expr(:using, :$), + Expr(:using, :a)) +@test parseall("using &\na") == Expr(:block, Expr(:using, :&), :a)