summaryrefslogtreecommitdiff
path: root/modules/language/python/string.scm
diff options
context:
space:
mode:
authorStefan Israelsson Tampe <stefan.itampe@gmail.com>2017-12-01 17:24:12 +0100
committerStefan Israelsson Tampe <stefan.itampe@gmail.com>2017-12-01 17:24:12 +0100
commitd4f5255498d07b424ba5d6b8535aedc3ec40808a (patch)
tree5075076b3beeec6f1c59e428d8b323bcf749ab65 /modules/language/python/string.scm
parente7bf554e568e74e1211186fe29b921a97893c60b (diff)
string formatter library
Diffstat (limited to 'modules/language/python/string.scm')
-rw-r--r--modules/language/python/string.scm53
1 files changed, 11 insertions, 42 deletions
diff --git a/modules/language/python/string.scm b/modules/language/python/string.scm
index 2a8fbcc..1b9883d 100644
--- a/modules/language/python/string.scm
+++ b/modules/language/python/string.scm
@@ -1,4 +1,5 @@
(define-module (language python string)
+ #:use-module (parser stis-parser)
#:use-module (oop goops)
#:use-module (oop pf-objects)
#:use-module (language python hash)
@@ -6,7 +7,6 @@
#:use-module (language python list)
#:use-module (language python exceptions)
#:use-module (language python for)
- #:use-module (parser stis-parser)
#:export (py-format py-capitalize py-center py-endswith
py-expandtabs py-find py-rfind
py-isalnum py-isalpha py-isdigit py-islower
@@ -133,44 +133,9 @@
(- n it (len sub))
-1)))))
-(define i (f-list #:i (mk-token (f+ (f-reg! "[0-9]")))))
-(define s (f-list #:s (mk-token (f+ (f-not! (f-tag "}"))))))
-(define e (f-list #:e (f-and (f-tag "}") f-true)))
-(define tagbody (f-or! e i s))
-
-(define tag (f-seq "{" tagbody "}"))
-(define nontag (f-list #:str (mk-token (f+ (f-or! (f-tag "{{")
- (f-not! tag))))))
-(define e (ff* (f-or! tag nontag)))
-
-(define (compile x args kwargs)
- (let lp ((l x) (r '()) (u '()) (i 0))
- (match l
- (((#:str x) . l)
- (lp l (cons x r) u i))
- (((#:i x) . l)
- (lp l (cons "~a" r) (cons (list-ref args (string->number x)) u) i))
- (((#:s x) . l)
- (lp l (cons "~a" r) (cons (hash-ref kwargs x None) u) i))
- (((#:e) . l)
- (lp l (cons "~a" r) (cons (list-ref args i) u) (+ i 1)))
- (()
- (apply format #f (string-join (reverse r) "") (reverse u))))))
-
-(define-py (py-format format s . l)
- (call-with-values
- (lambda ()
- (let lp ((l l) (args '()) (kwargs (make-hash-table)))
- (match l
- (((? keyword? key) x . l)
- (hash-set! kwargs (symbol->string (keyword->symbol key)) x)
- (lp l args kwargs))
- ((x . l)
- (lp l (cons x args) kwargs))
- (()
- (values (reverse args) kwargs)))))
- (lambda (args kwargs)
- (compile (parse s e) args kwargs))))
+(define format (lambda (a b) a))
+(define-py (py-format format s format-string)
+ (format s format-string))
(define-syntax-rule (mk-is py-isalnum isalnum x ...)
(define-py (py-isalnum isalnum s)
@@ -233,7 +198,9 @@
(let ((ret (make-string width ch)))
(let lp ((i 0))
(if (< i n)
- (string-set! ret i (string-ref s i))
+ (begin
+ (string-set! ret i (string-ref s i))
+ (lp (+ i 1)))
ret))))))
(define-py (py-rjust rjust s width . l)
@@ -250,7 +217,9 @@
(let ((ret (make-string width ch)))
(let lp ((i 0) (j (- width n)))
(if (< i n)
- (string-set! ret j (string-ref s i))
+ (begin
+ (string-set! ret j (string-ref s i))
+ (lp (+ i 1) (+ j 1)))
ret))))))
(define-py (py-lower lower s)
@@ -525,7 +494,7 @@
(for ((x : o)) ((l '()))
(cons (string-ref x 0) l)
#:final
- (format port "iter(~s)" (list->string (reverse l)))))
+ ((@ (guile) format) port "iter(~s)" (list->string (reverse l)))))
(define-method (wrap-in (o <string-iter> ))
(let ((out (make <string-iter>)))