Skip to content

Commit

Permalink
Remove deprecated syntax and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebolewski committed Sep 11, 2015
1 parent 105312f commit bbe3e05
Show file tree
Hide file tree
Showing 15 changed files with 123 additions and 301 deletions.
4 changes: 2 additions & 2 deletions base/pkg/entry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -509,11 +509,11 @@ function register(pkg::AbstractString, url::AbstractString)
isfile("METADATA",pkg,"url") && error("$pkg already registered")
tags = split(Git.readall(`tag -l v*`, dir=pkg))
filter!(tag->ismatch(Base.VERSION_REGEX,tag), tags)
versions = [
versions = Dict([
convert(VersionNumber,tag) =>
Git.readchomp(`rev-parse --verify $tag^{commit}`, dir=pkg)
for tag in tags
]
])
Git.transact(dir="METADATA") do
cd("METADATA") do
info("Registering $pkg at $url")
Expand Down
3 changes: 2 additions & 1 deletion base/pkg/resolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ function sanity_check(deps::Dict{ByteString,Dict{VersionNumber,Available}}, pkgs

nv = length(vers)

svdict = (Tuple{ByteString,VersionNumber}=>Int)[ vers[i][1:2]=>i for i = 1:nv ]
svdict = Dict{Tuple{ByteString,VersionNumber},Int}(
[vers[i][1:2]=>i for i = 1:nv ])

checked = falses(nv)

Expand Down
2 changes: 1 addition & 1 deletion base/pkg/resolve/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type Interface
np = length(pkgs)

# generate pdict
pdict = (ByteString=>Int)[ pkgs[i] => i for i = 1:np ]
pdict = Dict{ByteString,Int}([ pkgs[i] => i for i = 1:np ])

# generate spp and pvers
spp = Array(Int, np)
Expand Down
7 changes: 2 additions & 5 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -578,18 +578,15 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int)
show_call(io, head, ex.args[1], ex.args[2:end], indent)

# comprehensions
elseif (head === :typed_comprehension || head === :typed_dict_comprehension) && length(args) == 3
isdict = (head === :typed_dict_comprehension)
isdict && print(io, '(')
elseif head === :typed_comprehension && length(args) == 3
show_unquoted(io, args[1], indent)
isdict && print(io, ')')
print(io, '[')
show_unquoted(io, args[2], indent)
print(io, " for ")
show_unquoted(io, args[3], indent)
print(io, ']')

elseif (head === :comprehension || head === :dict_comprehension) && length(args) == 2
elseif head === :comprehension && length(args) == 2
print(io, '[')
show_unquoted(io, args[1], indent)
print(io, " for ")
Expand Down
177 changes: 34 additions & 143 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@
(define (kwarg? e)
(and (pair? e) (eq? (car e) 'kw)))

(define (dict-literal? l)
(and (length= l 3) (eq? (car l) '=>)))

;; Parser state variables

; disable range colon for parsing ternary conditional operator
Expand Down Expand Up @@ -187,8 +184,6 @@
(loop newop (peek-char port)))
str))
str))))
(if (equal? str "--")
(syntax-deprecation port str ""))
(string->symbol str))))

(define (accum-digits c pred port lz)
Expand Down Expand Up @@ -937,11 +932,6 @@
(parse-resword s ex)
(parse-call-chain s ex #f))))

(define (deprecated-dict-replacement ex)
(if (dict-literal? ex)
(string "Dict{" (deparse (cadr ex)) #\, (deparse (caddr ex)) "}")
"Dict"))

(define (parse-call-chain s ex one-call)
(let loop ((ex ex))
(let ((t (peek-token s)))
Expand All @@ -954,9 +944,7 @@
(case t
((#\( )
(if (ts:space? s)
(syntax-deprecation s
(string (deparse ex) " " (deparse t))
(string (deparse ex) (deparse t))))
(error (string "invalid space \"" (deparse ex) " " (deparse t) "\"")))
(take-token s)
(let ((c
(let ((al (parse-arglist s #\) )))
Expand All @@ -975,44 +963,29 @@
(loop c))))
((#\[ )
(if (ts:space? s)
(syntax-deprecation s
(string (deparse ex) " " (deparse t))
(string (deparse ex) (deparse t))))
(error (string "invalid space \"" (deparse ex) " " (deparse t) "\"")))
(take-token s)
;; ref is syntax, so we can distinguish
;; a[i] = x from
;; ref(a,i) = x
(let ((al (with-end-symbol (parse-cat s #\] (dict-literal? ex)))))
(let ((al (with-end-symbol (parse-cat s #\]))))
(if (null? al)
(if (dict-literal? ex)
(begin
(syntax-deprecation
s (string #\( (deparse ex) #\) "[]")
(string (deprecated-dict-replacement ex) "()"))
(loop (list 'typed_dict ex)))
(loop (list 'ref ex)))
(case (car al)
((dict)
(if (dict-literal? ex)
(begin (syntax-deprecation
s (string #\( (deparse ex) #\) "[a=>b, ...]")
(string (deprecated-dict-replacement ex) "(a=>b, ...)"))
(loop (list* 'typed_dict ex (cdr al))))
(loop (list* 'ref ex (cdr al)))))
((vect) (loop (list* 'ref ex (cdr al))))
((hcat) (loop (list* 'typed_hcat ex (cdr al))))
((vcat)
(loop (list* 'typed_vcat ex (cdr al))))
((comprehension)
(loop (list* 'typed_comprehension ex (cdr al))))
((dict_comprehension)
(loop (list* 'typed_dict_comprehension ex (cdr al))))
(else (error "unknown parse-cat result (internal error)"))))))
(loop (list 'ref ex))
(case (car al)
((dict)
(loop (list* 'ref ex (cdr al))))
((vect)
(loop (list* 'ref ex (cdr al))))
((hcat)
(loop (list* 'typed_hcat ex (cdr al))))
((vcat)
(loop (list* 'typed_vcat ex (cdr al))))
((comprehension)
(loop (list* 'typed_comprehension ex (cdr al))))
(else (error "unknown parse-cat result (internal error)"))))))
((|.|)
(if (ts:space? s)
(syntax-deprecation s
(string (deparse ex) " " (deparse t))
(string (deparse ex) (deparse t))))
(error (string "invalid space \"" (deparse ex) " " (deparse t) "\"")))
(take-token s)
(loop
(cond ((eqv? (peek-token s) #\()
Expand All @@ -1035,9 +1008,7 @@
(loop (list t ex)))
((#\{ )
(if (ts:space? s)
(syntax-deprecation s
(string (deparse ex) " " (deparse t))
(string (deparse ex) (deparse t))))
(error (string "invalid space \"" (deparse ex) " " (deparse t) "\"")))
(take-token s)
(loop (list* 'curly ex
(map subtype-syntax (parse-arglist s #\} )))))
Expand Down Expand Up @@ -1148,8 +1119,7 @@
(if const
`(const ,expr)
expr)))
((stagedfunction function macro)
(if (eq? word 'stagedfunction) (syntax-deprecation s "stagedfunction" "@generated function"))
((function macro)
(let* ((paren (eqv? (require-token s) #\())
(sig (parse-call s)))
(if (and (eq? word 'function) (not paren) (symbol? sig))
Expand Down Expand Up @@ -1378,9 +1348,7 @@
(cond
((eq? nxt '|.|)
(if (ts:space? s)
(syntax-deprecation s
(string (deparse word) " " (deparse nxt))
(string (deparse word) (deparse nxt))))
(error (string "invalid space \"" (deparse word) " " (deparse nxt) "\"")))
(take-token s)
(loop (cons (macrocall-to-atsym (parse-unary-prefix s)) path)))
((or (memv nxt '(#\newline #\; #\, :))
Expand Down Expand Up @@ -1509,26 +1477,13 @@
(else
(error "missing separator in array expression")))))))

(define (parse-dict s first closer)
(let ((v (parse-vect s first closer)))
(if (any dict-literal? (cdr v))
(if (every dict-literal? (cdr v))
`(dict ,@(cdr v))
(error "invalid dict literal")))))

(define (parse-comprehension s first closer)
(let ((r (parse-comma-separated-iters s)))
(if (not (eqv? (require-token s) closer))
(error (string "expected " closer))
(take-token s))
`(comprehension ,first ,@r)))

(define (parse-dict-comprehension s first closer)
(let ((c (parse-comprehension s first closer)))
(if (dict-literal? (cadr c))
`(dict_comprehension ,@(cdr c))
(error "invalid dict comprehension"))))

(define (parse-matrix s first closer gotnewline)
(define (fix head v) (cons head (reverse v)))
(define (update-outer v outer)
Expand Down Expand Up @@ -1574,36 +1529,26 @@
(loop (peek-token s)))
t)))

(define (parse-cat s closer . isdict)
(define (parse-cat s closer)
(with-normal-ops
(with-inside-vec
(if (eqv? (require-token s) closer)
(begin (take-token s)
'())
(let ((first (parse-eq* s)))
(if (and (dict-literal? first)
(or (null? isdict) (car isdict)))
(case (peek-non-newline-token s)
((for)
(take-token s)
(parse-dict-comprehension s first closer))
(else
(if (or (null? isdict) (not (car isdict)))
(syntax-deprecation s "[a=>b, ...]" "Dict(a=>b, ...)"))
(parse-dict s first closer)))
(let ((t (peek-token s)))
(cond ((or (eqv? t #\,) (eqv? t closer))
(parse-vect s first closer))
((eq? t 'for)
(take-token s)
(parse-comprehension s first closer))
((eqv? t #\newline)
(take-token s)
(if (memv (peek-token s) (list #\, closer))
(parse-vect s first closer)
(parse-matrix s first closer #t)))
(else
(parse-matrix s first closer #f))))))))))
(let ((t (peek-token s)))
(cond ((or (eqv? t #\,) (eqv? t closer))
(parse-vect s first closer))
((eq? t 'for)
(take-token s)
(parse-comprehension s first closer))
((eqv? t #\newline)
(take-token s)
(if (memv (peek-token s) (list #\, closer))
(parse-vect s first closer)
(parse-matrix s first closer #t)))
(else
(parse-matrix s first closer #f)))))))))

; for sequenced evaluation inside expressions: e.g. (a;b, c;d)
(define (parse-stmts-within-expr s)
Expand Down Expand Up @@ -1959,60 +1904,6 @@
(else
(error "missing separator in tuple")))))))))

;; cell expression
((eqv? t #\{ )
(take-token s)
(if (eqv? (require-token s) #\})
(begin (syntax-deprecation s "{}" "[]")
(take-token s)
'(cell1d))
(let ((vex (parse-cat s #\} #t)))
(if (null? vex)
(begin (syntax-deprecation s "{}" "[]")
'(cell1d))
(case (car vex)
((vect)
(syntax-deprecation s "{a,b, ...}" "Any[a,b, ...]")
`(cell1d ,@(cdr vex)))
((comprehension)
(syntax-deprecation s "{a for a in b}" "Any[a for a in b]")
`(typed_comprehension (top Any) ,@(cdr vex)))
((dict_comprehension)
(syntax-deprecation s "{a=>b for (a,b) in c}" "Dict{Any,Any}([a=>b for (a,b) in c])")
`(typed_dict_comprehension (=> (top Any) (top Any)) ,@(cdr vex)))
((dict)
(syntax-deprecation s "{a=>b, ...}" "Dict{Any,Any}(a=>b, ...)")
`(typed_dict (=> (top Any) (top Any)) ,@(cdr vex)))
((hcat)
(syntax-deprecation s "{a b ...}" "Any[a b ...]")
`(cell2d 1 ,(length (cdr vex)) ,@(cdr vex)))
(else ; (vcat ...)
(if (and (pair? (cadr vex)) (eq? (caadr vex) 'row))
(let ((nr (length (cdr vex)))
(nc (length (cdadr vex))))
;; make sure all rows are the same length
(if (not (every
(lambda (x)
(and (pair? x)
(eq? (car x) 'row)
(length= (cdr x) nc)))
(cddr vex)))
(error "inconsistent shape in cell expression"))
(begin
(syntax-deprecation s "{a b; c d}" "Any[a b; c d]")
`(cell2d ,nr ,nc
,@(apply append
;; transpose to storage order
(apply map list
(map cdr (cdr vex)))))))
(if (any (lambda (x) (and (pair? x)
(eq? (car x) 'row)))
(cddr vex))
(error "inconsistent shape in cell expression")
(begin
(syntax-deprecation s "{a,b, ...}" "Any[a,b, ...]")
`(cell1d ,@(cdr vex)))))))))))

;; cat expression
((eqv? t #\[ )
(take-token s)
Expand Down
Loading

0 comments on commit bbe3e05

Please sign in to comment.