diff options
author | Stefan Israelsson Tampe <stefan.itampe@gmail.com> | 2018-07-23 15:34:36 +0200 |
---|---|---|
committer | Stefan Israelsson Tampe <stefan.itampe@gmail.com> | 2018-07-23 15:34:36 +0200 |
commit | e81fc8b27caa57c158b0f33d839404ddd44db17b (patch) | |
tree | 196f1aa4f21c2aa1654d7d2cd7526c53e8af4b63 /modules/language/python/module/re | |
parent | 26f5f9714cfaf1f39c4c30003de9d2221b55175a (diff) |
regexp ranges
Diffstat (limited to 'modules/language/python/module/re')
-rw-r--r-- | modules/language/python/module/re/compile.scm | 5 | ||||
-rw-r--r-- | modules/language/python/module/re/parser.scm | 22 |
2 files changed, 20 insertions, 7 deletions
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) |