diff options
Diffstat (limited to 'modules/language/python/string.scm')
-rw-r--r-- | modules/language/python/string.scm | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/modules/language/python/string.scm b/modules/language/python/string.scm index d4cb74b..91a78db 100644 --- a/modules/language/python/string.scm +++ b/modules/language/python/string.scm @@ -17,10 +17,17 @@ py-partition py-replace py-strip py-title py-rpartitio py-rindex py-split py-rsplit py-splitlines py-startswith py-swapcase py-translate py-zfill - pystring-listing <py-string> pystring py-string?)) + pystring-listing <py-string> pystring py-string? + scm-str scm-sym py-identifier?)) (define-syntax-rule (aif it p x y) (let ((it p)) (if it x y))) +(define (scm-str x) (slot-ref (pystring x) 'str)) +(define (scm-sym x) + (if (symbol? x) + x + (string->symbol (scm-str x)))) + (define (py-string? x) (or (string? x) (is-a? x <py-string>))) @@ -169,6 +176,24 @@ (mk-is py-isspace isspace char-whitespace?) (mk-is py-isupper isupper char-upper-case?) +(define-py (py-identifier? isidentifier s) + (let lp ((l (string->list s)) (first? #t)) + (if (pair? l) + (let ((x (car l))) + (if first? + (if (or (char-alphabetic? x) + (eq? x #\_)) + (lp (cdr l) #f) + #f) + (if (or (char-alphabetic? x) + (char-numeric? x) + (eq? x #\_)) + (lp (cdr l) #f) + #f))) + (if ((@ (language python module keyword) iskeyword) s) + #f + #t)))) + (define-py (py-istitle istitle s) (let ((n (len s))) (if ((> n 0)) |