From 6a70d54a98c717055fb7a5d5f5b2a63404b755be Mon Sep 17 00:00:00 2001 From: jake bolewski Date: Thu, 18 Sep 2014 00:49:26 -0400 Subject: [PATCH] allow x[i,j;k] syntax to be parsed #7225 --- src/julia-parser.scm | 5 ++++- src/julia-syntax.scm | 35 +++++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/julia-parser.scm b/src/julia-parser.scm index 32999aacc3d91..e741672205920 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -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 diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index 44201134d8228..7061c9210f22c 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -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) @@ -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 @@ -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 @@ -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)