Skip to content
Browse files

fixing parse of {[a b],[c d]}

  • Loading branch information...
1 parent cee284b commit 064396f3d7ff0872c89a452f3857745a76057e83 @JeffBezanson JeffBezanson committed Apr 17, 2012
Showing with 22 additions and 28 deletions.
  1. +9 −27 src/julia-parser.scm
  2. +13 −1 src/julia-syntax.scm
View
36 src/julia-parser.scm
@@ -858,42 +858,24 @@
(else
(error "missing separator in array expression")))))))
-(define (cat-to-hvcat closer e)
- (if (and
- (eqv? closer #\])
- (eq? (car e) 'vcat)
- (any (lambda (x) (and (pair? x) (eq? (car x) 'hcat))) (cdr e)))
- ;; convert nested hcat inside vcat to hvcat
- (let ((rows (map (lambda (x)
- (if (and (pair? x) (eq? (car x) 'hcat))
- (cdr x)
- (list x)))
- (cdr e))))
- `(call (top hvcat)
- (tuple ,@(map length rows))
- ,@(apply nconc rows)))
- e))
-
(define (parse-matrix s first closer)
(define (fix head v) (cons head (reverse v)))
(define (update-outer v outer)
(cond ((null? v) outer)
((null? (cdr v)) (cons (car v) outer))
- (else (cons (fix 'hcat v) outer))))
+ (else (cons (fix 'row v) outer))))
(let loop ((vec (list first))
(outer '()))
(let ((t (if (eqv? (peek-token s) #\newline)
#\newline
(require-token s))))
(if (eqv? t closer)
(begin (take-token s)
- (cat-to-hvcat
- closer
- (if (pair? outer)
- (fix 'vcat (update-outer vec outer))
- (if (or (null? vec) (null? (cdr vec)))
- (fix 'vcat vec) ; [x] => (vcat x)
- (fix 'hcat vec))))) ; [x y] => (hcat x y)
+ (if (pair? outer)
+ (fix 'vcat (update-outer vec outer))
+ (if (or (null? vec) (null? (cdr vec)))
+ (fix 'vcat vec) ; [x] => (vcat x)
+ (fix 'hcat vec)))) ; [x y] => (hcat x y)
(case t
((#\; #\newline)
(take-token s) (loop '() (update-outer vec outer)))
@@ -1113,14 +1095,14 @@
((eq? (car vex) 'hcat)
`(cell2d 1 ,(length (cdr vex)) ,@(cdr vex)))
(else ; (vcat ...)
- (if (and (pair? (cadr vex)) (eq? (caadr vex) 'hcat))
+ (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) 'hcat)
+ (eq? (car x) 'row)
(length= (cdr x) nc)))
(cddr vex)))
(error "inconsistent shape in cell expression"))
@@ -1130,7 +1112,7 @@
(apply map list
(map cdr (cdr vex))))))
(if (any (lambda (x) (and (pair? x)
- (eq? (car x) 'hcat)))
+ (eq? (car x) 'row)))
(cddr vex))
(error "inconsistent shape in cell expression")
`(cell1d ,@(cdr vex)))))))))
View
14 src/julia-syntax.scm
@@ -933,7 +933,19 @@
`(call (top hcat) ,@a))
(pattern-lambda (vcat . a)
- `(call (top vcat) ,@a))
+ (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 (top hvcat)
+ (tuple ,@(map length rows))
+ ,@(apply nconc rows)))
+ `(call (top vcat) ,@a)))
;; transpose operator
(pattern-lambda (|'| a) `(call ctranspose ,a))

0 comments on commit 064396f

Please sign in to comment.
Something went wrong with that request. Please try again.