Skip to content

Commit

Permalink
Merge pull request #11333 from yuyichao/parse-import
Browse files Browse the repository at this point in the history
Do not require new line or ";" at the end of import expression
  • Loading branch information
JeffBezanson committed May 26, 2015
2 parents 58b44a7 + b2c2d42 commit 97072c8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1298,9 +1298,9 @@
(from (and (eq? next ':) (not (ts:space? s))))
(done (cond ((or from (eqv? next #\,))
(begin (take-token s) #f))
((memv next '(#\newline #\;)) #t)
((eof-object? next) #t)
(else #f)))
((or (eq? next '|.|)
(eqv? (string.sub (string next) 0 1) ".")) #f)
(else #t)))
(rest (if done
'()
(parse-comma-separated s (lambda (s)
Expand Down Expand Up @@ -1346,7 +1346,7 @@
(loop (cons (symbol (string.sub (string nxt) 1))
path)))
(else
(error (string "invalid \"" word "\" statement")))))))
`(,word ,@(reverse path)))))))

; parse comma-separated assignments, like "i=1:n,j=1:m,..."
(define (parse-comma-separated s what)
Expand Down
23 changes: 23 additions & 0 deletions test/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,26 @@ macro test999_str(args...); args; end

# issue #10985
@test expand(:(f(::Int...) = 1)).head == :method

# issue #10910
@test parse(":(using A)") == Expr(:quote, Expr(:using, :A))
@test parse(":(using A.b, B)") == Expr(:quote,
Expr(:toplevel,
Expr(:using, :A, :b),
Expr(:using, :B)))
@test parse(":(using A: b, c.d)") == Expr(:quote,
Expr(:toplevel,
Expr(:using, :A, :b),
Expr(:using, :A, :c, :d)))

@test parse(":(importall A)") == Expr(:quote, Expr(:importall, :A))

@test parse(":(import A)") == Expr(:quote, Expr(:import, :A))
@test parse(":(import A.b, B)") == Expr(:quote,
Expr(:toplevel,
Expr(:import, :A, :b),
Expr(:import, :B)))
@test parse(":(import A: b, c.d)") == Expr(:quote,
Expr(:toplevel,
Expr(:import, :A, :b),
Expr(:import, :A, :c, :d)))

0 comments on commit 97072c8

Please sign in to comment.