diff options
-rwxr-xr-x | Biz/Bot.scm | 16 | ||||
-rw-r--r-- | bs/re.scm | 4 | ||||
-rw-r--r-- | bs/string.scm | 45 |
3 files changed, 35 insertions, 30 deletions
diff --git a/Biz/Bot.scm b/Biz/Bot.scm index 7fa5933..af06585 100755 --- a/Biz/Bot.scm +++ b/Biz/Bot.scm @@ -4,14 +4,14 @@ ;; ;; tail -f \#biz/out | guile -L $BIZ_ROOT -s Biz/Bot.scm ;; -(define-module (Biz Bot) - #:use-module (ice-9 rdelim) - #:use-module (ice-9 match) - #:use-module (ice-9 regex) - #:use-module (ice-9 receive) - #:use-module (bs core) - #:use-module ((bs string) #:prefix string.) - #:export (main)) +(define-module (Biz Bot) #:export (main)) + +(import (ice-9 rdelim)) +(import (ice-9 match)) +(import (ice-9 regex)) +(import (ice-9 receive)) +(import (bs core)) +(import (prefix (bs string) string.)) (define (log msg) (display msg (current-error-port))) @@ -1,4 +1,4 @@ -(library (bs re (0)) +(library (bs re) ;; Similar to Python's `re` module. One big difference is that the ;; string object to be searched is always the first argument to a @@ -16,6 +16,7 @@ ;; TODO: make `match` and `search` do different things (export match group sub search compile + EXTENDED ;; I IGNORECASE M MULTILINE ) (import (rnrs base) @@ -26,6 +27,7 @@ ;; (define IGNORECASE regexp/icase) ;; (define M regexp/newline) ;; (define MULTILINE regexp/newline) + (define EXTENDED 'regexp/extended) (define (compile pattern . flags) "Compile `pattern` into a regular expression object." diff --git a/bs/string.scm b/bs/string.scm index 58f86a0..b1ad256 100644 --- a/bs/string.scm +++ b/bs/string.scm @@ -1,45 +1,45 @@ -(library (bs string (0)) +(library (bs string) (export replace replace-char to-string str capitalize split - strip lstrip rstrip prefix? suffix?) + strip lstrip rstrip prefix? suffix? drop) (import - (rnrs base) - (only (rnrs control) case-lambda) - (only (rnrs io simple) display) - (only (srfi srfi-13) - string-trim string-trim-both string-trim-right - string-prefix? string-suffix? string-upcase string-concatenate - string-drop string-take string-contains substring/shared string-null? string-fold - string-tokenize) - (only (srfi srfi-14) - string->char-set char-set-complement char-set) - (only (srfi srfi-28) format) - ;; TODO: port ice-9 dependency or replace with (scheme something) - (only (ice-9 ports) with-output-to-string)) + (rnrs base) + (only (rnrs control) case-lambda) + (only (rnrs io simple) display) + (only (srfi srfi-13) + string-trim string-trim-both string-trim-right + string-prefix? string-suffix? string-upcase string-concatenate + string-drop string-take string-contains substring/shared string-null? string-fold + string-tokenize) + (only (srfi srfi-14) + string->char-set char-set-complement char-set) + (only (srfi srfi-28) format) + ;; TODO: port ice-9 dependency or replace with (scheme something) + (only (ice-9 ports) with-output-to-string)) (define (prefix? s pre) - "Is PRE a prefix of S?" + #;"Is PRE a prefix of S?" (string-prefix? pre s)) (define (suffix? s suf) - "Is SUF a suffix of S?" + #;"Is SUF a suffix of S?" (string-suffix? suf s)) (define (split s sep) - "Split S at SEP" + #;"Split S at SEP" ;; this is still wrong. it splits on any of the "sep" characters ;; instead of all of them (string-tokenize s (char-set-complement (apply char-set (string->list sep))))) (define (replace-char s match char) - "Replace MATCH in S with CHAR" + #;"Replace MATCH in S with CHAR" (let ((f (lambda (a b) (let ((next-char (if (eq? a match) char a))) (string-concatenate (list b (string next-char))))))) (string-fold f "" s))) (define (replace s match repl) - "Replace MATCH in S with REPL" + #;"Replace MATCH in S with REPL" ;; based on string-replace-substring By A. Wingo in ;; https://lists.gnu.org/archive/html/guile-devel/2014-03/msg00058.html ;; also in string-replace-substring guix:guix/utils.scm. @@ -79,4 +79,7 @@ (string-trim s char)) (define (rstrip s char) - (string-trim-right s char ))) + (string-trim-right s char)) + + (define (drop s num) + (string-drop s num))) |