summaryrefslogtreecommitdiff
path: root/modules/language/python
diff options
context:
space:
mode:
Diffstat (limited to 'modules/language/python')
-rw-r--r--modules/language/python/module/locale.scm60
-rw-r--r--modules/language/python/module/re/compile.scm5
-rw-r--r--modules/language/python/module/re/parser.scm22
-rw-r--r--modules/language/python/module/string.scm13
4 files changed, 58 insertions, 42 deletions
diff --git a/modules/language/python/module/locale.scm b/modules/language/python/module/locale.scm
index 5ed77f1..ed89724 100644
--- a/modules/language/python/module/locale.scm
+++ b/modules/language/python/module/locale.scm
@@ -1,5 +1,5 @@
(define-module (language python module locale)
- ;#:use-module (language python module re)
+ #:use-module (language python module re)
#:use-module (language python module sys)
#:use-module (language python module os)
#:use-module (language python list)
@@ -258,7 +258,7 @@ maps them to values suitable for passing to the C lib's setlocale() function.
(lambda (rpos amount)
(pylist-slice s lpos (+ rpos 1) None)))))))
-#;
+
(define _percent_re (compile (+ "%(?:\\((?P<key>.*?)\\))?"
"(?P<modifiers>[-#0-9 +*.hlL]*?)[eEfFgGdiouxXcrs%]")))
@@ -278,41 +278,41 @@ maps them to values suitable for passing to the C lib's setlocale() function.
(define _format
(lam (percent value (= grouping #f) (= monetary #f) (* additional))
- (let ((formated (py-apply py-mod percent
- (* (if additional
- (+ (list value) additional)
- (list value))))))
+ (let ((formated (py-mod percent
+ (if additional
+ (+ (list value) additional)
+ (list value)))))
;; floats and decimal ints need special action!
(when (in (pylist-ref percent -1) "eEfFgG")
- (let ((seps 0)
- (parts (py-split formated ".")))
- (when grouping
- (call-with-values
- (lambda () (_group (pylist-ref parts 0) #:monetary monetary))
- (lambda (p s)
- (pylist-set! parts 0 p)
- (set! seps s))))
-
- (let ((decimal_point (pylist-ref (localeconv)
- (or (and (bool monetary) "mon_decimal_point")
- "decimal_point"))))
- (set! formated (py-join decimal_point parts))
- (when (bool seps)
- (set! formated (_strip_padding formated seps))))))
+ (let ((seps 0)
+ (parts (py-split formated ".")))
+ (when grouping
+ (call-with-values
+ (lambda () (_group (pylist-ref parts 0) #:monetary monetary))
+ (lambda (p s)
+ (pylist-set! parts 0 p)
+ (set! seps s))))
+
+ (let ((decimal_point (pylist-ref (localeconv)
+ (or (and (bool monetary) "mon_decimal_point")
+ "decimal_point"))))
+ (set! formated (py-join decimal_point parts))
+ (when (bool seps)
+ (set! formated (_strip_padding formated seps))))))
- (when (in (pylist-ref percent -1) "diu")
- (let ((seps 0))
- (when grouping
- (call-with-values
- (lambda () (_group formated #:monetary monetary))
- (lambda (p s)
+ (when (in (pylist-ref percent -1) "diu")
+ (let ((seps 0))
+ (when grouping
+ (call-with-values
+ (lambda () (_group formated #:monetary monetary))
+ (lambda (p s)
(set! formated p)
(set! seps s))))
- (when (bool seps)
- (set! formated (_strip_padding formated seps)))))
+ (when (bool seps)
+ (set! formated (_strip_padding formated seps)))))
- formated)))
+ formated)))
(define format_string
(lam (f val (= grouping #f))
diff --git a/modules/language/python/module/re/compile.scm b/modules/language/python/module/re/compile.scm
index 927f833..3d7bdb1 100644
--- a/modules/language/python/module/re/compile.scm
+++ b/modules/language/python/module/re/compile.scm
@@ -213,7 +213,8 @@
((#:op x #:+?) (list #:op (reverse-form x) #:+?))
((#:op x #:??) (list #:op (reverse-form x) #:??))
((and a (#:ch (#:class x))) a)
- ((and a (#:ch x)) a)
+ ((and a (#:ch x)) a)
+ ((and a (#:range x)) a)
((and a (#:bracket not ch ...)) a)))
@@ -420,6 +421,8 @@
(let ((f (apply f-or!
(map (lambda (x)
(match x
+ ((#:range ch1 ch2)
+ (f-reg! (format #f "[~a-~a]" ch1 ch2)))
((#:ch (#:class ch))
(get-class ch))
((#:ch ch)
diff --git a/modules/language/python/module/re/parser.scm b/modules/language/python/module/re/parser.scm
index 144d974..89462ae 100644
--- a/modules/language/python/module/re/parser.scm
+++ b/modules/language/python/module/re/parser.scm
@@ -18,7 +18,7 @@
(define f-back
(f-or (f-list #:class (mk-token (f-reg! "[AZbBdDsSwntr]")))
- (mk-token (f-reg "."))))
+ (mk-token (f-reg! "."))))
(define anongroup (f-list #:?: "(?:" (Ds ee) ")"))
(define namegroup (f-list #:?P< "(?P<" (mk-token (f+ (f-not! (f-reg "[> ]")))) ">" (Ds ee) ")"))
@@ -53,27 +53,37 @@
(mk-token (f* (f-reg! "[aiLmsux]")))
")"))
-(define bbody (f-cons (ch (f-reg "[\\]")) (ff* (ch (f-reg "[]\\]")))))
+(define bbody (f-cons (f-or!
+ (f-list #:range (mk-token (f-reg! "."))
+ "-" (mk-token (f-reg! ".")))
+ (f-list #:ch (mk-token (f-reg! "."))))
+ (ff*
+ (f-or!
+ (f-list #:range (mk-token (f-not! (f-tag "]")))
+ "-"
+ (mk-token (f-not! (f-tag "]"))))
+ (f-list #:ch (mk-token (f-not! (f-tag "]"))))))))
(define (f-if a b c) (f-or! (f-seq a b) c))
(define choice
(f-cons #:bracket
(f-or!
- (f-seq "[^]" (f-out (list (list #:ch (f-out #f) "^"))))
+ (f-seq "[^]" (f-out (list (list #:ch (f-out #f) (f-out "^")))))
(f-cons*
(f-tag "[")
(f-if (f-tag "^") (f-out #t) (f-out #f))
- bbody))))
+ (f-seq bbody "]")))))
(define f-bar (f-tag "|"))
(define qq (ch (f-reg "[][?+|*.$^()\\]")))
-(define atom (f-or qq f-. flags2 flags choice subexpr anongroup namegroup incant coment lookh lookh! rev rev! f-^ f-$))
+(define atom (f-or qq f-. flags2 choice subexpr anongroup namegroup incant coment
+ lookh lookh! rev rev! f-^ f-$ flags))
(define spec (f-list #:op atom (f-or! q+? q?? q*? q* q? q+ repn? repnm? repn repnm)))
(define aatom (f-or! spec atom))
(define line (f-cons* #:seq aatom (ff* aatom )))
(define ee (f-cons* #:or line (ff* (f-seq f-bar line))))
-(define (parse-reg str) (parse str ee))
+(define (parse-reg str) (pk (parse str (f-seq ee f-eof))))
(define e-matcher ee)
diff --git a/modules/language/python/module/string.scm b/modules/language/python/module/string.scm
index d867226..fe0ccc8 100644
--- a/modules/language/python/module/string.scm
+++ b/modules/language/python/module/string.scm
@@ -54,15 +54,18 @@
((_ fill a)
(f s a (list fill)))))
-(define (convert-string s format-str)
+(define (convert-string format-str s)
(match (with-fluids ((*whitespace* f-true))
(stis-parse format-str (f-seq formatSpec f-eof)))
((align sign sharp zero width comma rec type)
(if width
(get-align s align width "")
- s))))
+ s))
+ (_ (raise (ValueError (+ "wrong format " format-str))))))
-(set! (@@ (language python string) format) convert-string)
+(set! (@@ (language python string) format)
+ (lambda (f s)
+ (py-format s f)))
(define (gen-sign s sign)
(let lp ((sign sign))
@@ -87,7 +90,7 @@
(lambda (s s-sign)
(let* ((prec (if prec prec 6))
(s (let lp ((type type))
- (match type
+ (pk (match type
(#f (lp "g"))
("f"
@@ -131,7 +134,7 @@
("%"
(set s (* s 100))
- (+ (lp "f") "%"))))))
+ (+ (lp "f") "%")))))))
(if width
(if zero