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

Free up curly brace syntax. #8578

Merged
merged 7 commits into from
Oct 9, 2014
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add deprecation warnings for {} syntax
  • Loading branch information
jakebolewski committed Oct 7, 2014
commit 091ffc1c489ac54900e6ad2d603cdfdab1190b7e
62 changes: 54 additions & 8 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1427,7 +1427,7 @@
(loop lst nxt)
(let ((params (parse-arglist s closer)))
`(vcat ,@params ,@lst ,nxt))))
((#\])
((#\] #\})
(error (string "unexpected \"" t "\"")))
(else
(error "missing separator in array expression")))))))
Expand Down Expand Up @@ -1508,11 +1508,8 @@
(take-token s)
(parse-dict-comprehension s first closer))
(else
(if (eqv? closer #\})
(syntax-deprecation-warning s "{a=>b, ...}" "Dict{Any,Any}(a=>b, ...)")
(or
(and (pair? isdict) (car isdict))
(syntax-deprecation-warning s "[a=>b, ...]" "Dict(a=>b, ...)")))
(if (and (pair? isdict) (car isdict))
(syntax-deprecation-warning s "[a=>b, ...]" "Dict(a=>b, ...)"))
(parse-dict s first closer)))
(case (peek-token s)
((#\,)
Expand Down Expand Up @@ -1783,9 +1780,58 @@
(else
(error "missing separator in tuple")))))))))

;; TODO this awaits a decision on {} syntax in 0.4
;; cell expression
((eqv? t #\{ )
(error "{} syntax for Any arrays / dicts has been removed in 0.4dev"))
(take-token s)
(if (eqv? (require-token s) #\})
(begin
(syntax-deprecation-warning s "{}" "[]")
(take-token s)
'(cell1d))
(let ((vex (parse-cat s #\})))
(if (null? vex)
(begin
(syntax-deprecation-warning s "{}" "[]")
'(cell1d))
(case (car vex)
((comprehension)
(syntax-deprecation-warning s "{a for a in b}" "Any[a for a in b]")
`(typed_comprehension (top Any) ,@(cdr vex)))
((dict_comprehension)
(syntax-deprecation-warning 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-warning s "{a=>b, ...}" "Dict{Any,Any}(a=>b, ...)")
`(typed_dict (=> (top Any) (top Any)) ,@(cdr vex)))
((hcat)
(syntax-deprecation-warning 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-warning s "{[a,b] [c,d]}" "Any[[a,b] [c,d]]"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be {a b; c d} to Any[a b;c d]?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, should be fixed.

`(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-warning s "{a,b, ...}" "Any[a,b,...]")
`(cell1d ,@(cdr vex)))))))))))

;; cat expression
((eqv? t #\[ )
Expand Down