diff options
Diffstat (limited to 'modules/language/python/format2.scm')
-rw-r--r-- | modules/language/python/format2.scm | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/modules/language/python/format2.scm b/modules/language/python/format2.scm index f8c4c69..70ee212 100644 --- a/modules/language/python/format2.scm +++ b/modules/language/python/format2.scm @@ -6,6 +6,7 @@ #:use-module ((language python module re) #:select (splitm splitmm)) #:use-module (language python exceptions) #:use-module (language python number) + #:use-module (language python dict) #:export (format fnm)) (define-syntax-rule (aif it p x y) (let ((it p)) (if it x y))) @@ -120,7 +121,8 @@ ("" (let ((kind (get-intkind tp))) (if min - (let ((pat (string-append "~" (number->string min) ",' " kind))) + (let ((pat (string-append "~" + (number->string min) ",' " kind))) (lambda (x) (scm-format #f pat x))) (let ((pat (string-append "~" kind))) @@ -159,29 +161,34 @@ (member #\0 c)) "-" "")) - (d (string-append pre kpre "~" - (number->string - (- min - (if (= (string-length kpre) 0) 0 2) - (if (= (string-length pre ) 0) 0 1))) - ",'" - padchar - kind))) + (d (string-append + pre kpre "~" + (number->string + (- min + (if (= (string-length kpre) 0) 0 2) + (if (= (string-length pre ) 0) 0 1))) + ",'" + padchar + kind))) (if (= (string-length pre) 0) (lambda (x) (if (and (number? x) (integer? x)) (scm-format #f d x) - (raise (ValueError "not a integer, format spec %d")))) + (raise + (ValueError "not a integer, format spec %d")))) (lambda (x) (if (and (number? x) (integer? x)) (scm-format #f d (if (< x 0) neg pos) (abs x)) - (raise (ValueError "not a integer, format spec %d"))))))) + (raise + (ValueError + "not a integer, format spec %d"))))))) (let* ((kind (get-intkind tp)) (pat (string-append "~" kind))) (lambda (x) (if (and (number? x) (integer? x)) (scm-format #f pat x) - (raise (ValueError "not a integer, format spec %d")))))))))))) + (raise + (ValueError "not a integer, format spec %d")))))))))))) (define (analyze p) @@ -219,6 +226,7 @@ (() (lambda (x) '())))) + (let lp ((l l)) (match l ((a p . l) @@ -234,7 +242,8 @@ (cons* a (f (car x) (cadr x)) (rest (cddr x))))) ((2) (lambda (x) - (cons* a (f (car x) (cadr x) (caddr x)) (rest (cdddr x)))))))) + (cons* a (f (car x) (cadr x) (caddr x)) + (rest (cdddr x)))))))) ((a) (lambda (x) (list a))) @@ -242,7 +251,13 @@ (lambda (x) '()))))))) +(define (id? x) + (or (pair? x) + (hash-table? x) + (is-a? x <py-hashtable>))) + (define (format-- s l ha) + (set! l (if (id? l) l (list l))) (aif it (hashq-ref ha s #f) (string-join (it l) "") (begin @@ -250,7 +265,7 @@ (format-- s l ha)))) (define (format- str l) - (string-join ((compile str) l) "")) + (string-join ((compile str) (if (id? l) l (list l))) "")) (define formatters (make-hash-table)) |