Skip to content

Commit

Permalink
Merge pull request JuliaLang#8250 from jakebolewski/jcb/newarraysyntax
Browse files Browse the repository at this point in the history
allow x[i,j;k] syntax to be parsed
  • Loading branch information
JeffBezanson committed Sep 30, 2014
2 parents 8b3aca4 + 6a70d54 commit beb5486
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
5 changes: 4 additions & 1 deletion src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,10 @@
(cons 'vcat (reverse (cons nxt lst))))
(loop (cons nxt lst) (parse-eq* s))))
((#\;)
(error "unexpected semicolon in array expression"))
(if (eqv? (require-token s) closer)
(loop lst nxt)
(let ((params (parse-arglist s closer)))
`(vcat ,@params ,@lst ,nxt))))
((#\] #\})
(error (string "unexpected \"" t "\"")))
(else
Expand Down
35 changes: 21 additions & 14 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1691,7 +1691,10 @@

'ref
(lambda (e)
(expand-forms (partially-expand-ref e)))
(let ((args (cddr e)))
(if (has-parameters? args)
(error "unexpected semicolon in array expression")
(expand-forms (partially-expand-ref e)))))

'curly
(lambda (e)
Expand All @@ -1706,9 +1709,9 @@
(eq? (car (caddr e)) 'parameters))
;; (call f (parameters . kwargs) ...)
(expand-forms
(receive
(kws args) (separate kwarg? (cdddr e))
(lower-kw-call f (append kws (cdr (caddr e))) args))))
(receive
(kws args) (separate kwarg? (cdddr e))
(lower-kw-call f (append kws (cdr (caddr e))) args))))
((any kwarg? (cddr e))
;; (call f ... (kw a b) ...)
(expand-forms
Expand Down Expand Up @@ -1791,7 +1794,9 @@
'cell1d
(lambda (e)
(let ((args (cdr e)))
(cond ((any vararg? args)
(cond ((has-parameters? args)
(error "unexpected semicolon in array expression"))
((any vararg? args)
(expand-forms
`(call (top cell_1d) ,@args)))
(else
Expand Down Expand Up @@ -1910,20 +1915,22 @@
'vcat
(lambda (e)
(let ((a (cdr e)))
(expand-forms
(if (any (lambda (x)
(and (pair? x) (eq? (car x) 'row)))
a)
;; convert nested hcat inside vcat to hvcat
(let ((rows (map (lambda (x)
(if (has-parameters? a)
(error "unexpected semicolon in array expression")
(expand-forms
(if (any (lambda (x)
(and (pair? x) (eq? (car x) 'row)))
a)
;; convert nested hcat inside vcat to hvcat
(let ((rows (map (lambda (x)
(if (and (pair? x) (eq? (car x) 'row))
(cdr x)
(list x)))
a)))
`(call hvcat
(tuple ,.(map length rows))
`(call hvcat
(tuple ,.(map length rows))
,.(apply nconc rows)))
`(call vcat ,@a)))))
`(call vcat ,@a))))))

'typed_hcat
(lambda (e)
Expand Down

0 comments on commit beb5486

Please sign in to comment.