Skip to content

Commit

Permalink
allow x[i,j;k] syntax to be parsed #7225
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebolewski committed Sep 20, 2014
1 parent c4dc379 commit 6a70d54
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 @@ -1677,7 +1677,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 @@ -1692,9 +1695,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 @@ -1777,7 +1780,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 @@ -1896,20 +1901,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 6a70d54

Please sign in to comment.