diff options
-rw-r--r-- | modules/language/python/compile.scm | 17 | ||||
-rw-r--r-- | modules/language/python/string.scm | 24 |
2 files changed, 24 insertions, 17 deletions
diff --git a/modules/language/python/compile.scm b/modules/language/python/compile.scm index 2edba8a..50376f6 100644 --- a/modules/language/python/compile.scm +++ b/modules/language/python/compile.scm @@ -148,7 +148,7 @@ (define (defs x vs) (match x - ((#:def ((#:identifier f) . _) . _) + ((#:def (#:identifier f) . _) (union (list (string->symbol f)) vs)) ((#:lambdef . _) vs) @@ -188,7 +188,12 @@ ((sort) (L 'pylist-sort!)) ;; String - ((format) (S 'py-format)) + ((format) (S 'py-format)) + ((capitalize) (S 'py-capitalize)) + ((center) (S 'py-center)) + ((endswith) (S 'py-endswith)) + ((expandtabs) (S 'py-expandtabs)) + ((find) (S 'py-find)) (else #f))) (define (get-kwarg vs arg) @@ -232,7 +237,7 @@ (cons (match x - (((#:identifier . _) . _) + ((#:identifier . _) (let* ((tag (exp vs x)) (xs (gensym "xs")) (is-fkn? (aif it (and is-fkn? (fastfkn tag)) @@ -242,7 +247,7 @@ #f))) (if is-fkn? is-fkn? - `((#:identifier ',tag) . _)))) + `(#:identifier ',tag)))) ((#:arglist args apply #f) (call-with-values (lambda () (get-kwarg vs args)) @@ -293,7 +298,7 @@ ("//=" 'floor-quotient))) (match x - ((#:test (#:power kind ((#:identifier v . _) . _) addings . _) . _) + ((#:test (#:power kind (#:identifier v . _) addings . _) . _) (let ((addings (get-addings vs addings))) (define q (lambda (x) `',x)) (if kind @@ -367,7 +372,7 @@ (_ #f)))) (match (pr x) - (((#:identifier . _) . _) + ((#:identifier . _) (let* ((tag (exp vs x)) (xs (gensym "xs")) (is-fkn? (aif it (and is-fkn? (fastfkn tag)) diff --git a/modules/language/python/string.scm b/modules/language/python/string.scm index c68b9ae..156cc43 100644 --- a/modules/language/python/string.scm +++ b/modules/language/python/string.scm @@ -3,7 +3,8 @@ #:use-module (oop pf-objects) #:use-module (ice-9 match) #:use-module (parser stis-parser) - #:export (py-format)) + #:export (py-format py-capitalize py-center py-endswith + py-expandtabs py-find)) (define-syntax-rule (aif it p x y) (let ((it p)) (if it x y))) @@ -12,7 +13,6 @@ (define-method (f (o <string>) . u) code ...) (define-method (f (o <p>) . l) (apply (ref o 'n) l)))) -#| (define-py (py-capitalize capitalize o) (string-capitalize o)) @@ -23,7 +23,7 @@ (n (string-length o)) (w (if (< w n) n w)) (d (- w n)) - (e (floor-quotient (- w n) / 2)) + (e (floor-quotient (- w n) 2)) (s (make-string w #\space))) (let lp ((i 0) (j e)) (if (< i n) @@ -34,19 +34,21 @@ -;py-decode -;py-encode +;;;py-decode +;;;py-encode + + (define-py (py-endswith endswith o (suff <string>) . l) - (let ((n (string-length o)) - (ns (string-length suff)) - (f (lambda (x) (< x 0) (+ n x) x))) + (let* ((n (string-length o)) + (ns (string-length suff)) + (f (lambda (x) (< x 0) (+ n x) x))) (call-with-values (lambda () (match l (() (values 0 n )) ((x) (values (f x) n )) ((x y) (values (f x) (f y))))) (lambda (start end) - (string-suffix? o suff start end))))) + (string-suffix? suff o 0 ns start end))))) (define-py (py-expandtabs expandtabs s . l) (let* ((tabsize (match l (() 8) ((x) x))) @@ -61,7 +63,8 @@ (list->string (reverse r)))))) (define-py (py-find find s sub . l) - (let ((f (lambda (x) (< x 0) (+ n x) x))) + (let* ((n (string-length s)) + (f (lambda (x) (< x 0) (+ n x) x))) (call-with-values (lambda () (match l (() (values 0 n )) @@ -71,7 +74,6 @@ (aif it (string-contains s sub start end) it -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 "}")))))) |