aboutsummaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authormryouse2022-07-14 01:52:40 +0000
committermryouse2022-07-14 01:52:40 +0000
commit8484dbac7b5bd85e4a25705a9346647ec4d1ab8b (patch)
treea1d6c92c00a001ada7f07ae6eb9b5ef39782586c /libs
parent3701c619a2421f8c587888ad5443382c5a059b4d (diff)
refactor: dot functions
Diffstat (limited to 'libs')
-rw-r--r--libs/regex.neb85
1 files changed, 42 insertions, 43 deletions
diff --git a/libs/regex.neb b/libs/regex.neb
index e6bff34..928f739 100644
--- a/libs/regex.neb
+++ b/libs/regex.neb
@@ -2,51 +2,50 @@
; for doing regex matches
(func match? :bool (pattern :string text :string)
-
- (func match-one :bool (left right)
- (in? left (list "" "." right)))
+ (.search pattern text))
- (func match-? :bool (pattern text)
- (or
- (and
- (match-one (first-char pattern) (first-char text))
- (match-inner (rest-char (rest-char pattern)) (rest-char text)))
- (match-inner (rest-char (rest-char pattern)) text)))
+(func .match-one :bool (left right)
+ (in? left (list "" "." right)))
- (func match-* (pattern text)
- (or
- (and
- (match-one (first-char pattern) (first-char text))
- (match-inner pattern (rest-char text)))
- (match-inner (rest-char (rest-char pattern)) text)))
+(func .match-? :bool (pattern text)
+ (or
+ (and
+ (.match-one (first-char pattern) (first-char text))
+ (.match-inner (rest-char (rest-char pattern)) (rest-char text)))
+ (.match-inner (rest-char (rest-char pattern)) text)))
- (func match-inner (pattern text)
- (branch
- ((eq? "" pattern) #true)
- ((and (eq? "$" pattern) (eq? "" text)) #true)
- ((eq? "" text) #false)
- ((and (>= (length pattern) 2) (eq? "?" (first-char (rest-char pattern))))
- (match-? pattern text))
- ((and (>= (length pattern) 2) (eq? "*" (first-char (rest-char pattern))))
- (match-* pattern text))
- (#true
- (and
- (match-one (first-char pattern) (first-char text))
- (match-inner (rest-char pattern) (rest-char text))))))
+(func .match-* (pattern text)
+ (or
+ (and
+ (.match-one (first-char pattern) (first-char text))
+ (.match-inner pattern (rest-char text)))
+ (.match-inner (rest-char (rest-char pattern)) text)))
- (func search (pattern text)
- (if (eq? "^" (first-char pattern))
- (match-inner (rest-char pattern) text)
- (block
- (def progress text)
- (def out (list))
- (for-count (length text)
- (redef out (append out (match-inner pattern progress)))
- (redef progress (rest-char progress)))
- (or
- (eq? 0 (list-length out))
- (if (eq? 1 (list-length out))
- (first out)
- (apply or out))))))
+(func .match-inner (pattern text)
+ (branch
+ ((eq? "" pattern) #true)
+ ((and (eq? "$" pattern) (eq? "" text)) #true)
+ ((eq? "" text) #false)
+ ((and (>= (length pattern) 2) (eq? "?" (first-char (rest-char pattern))))
+ (.match-? pattern text))
+ ((and (>= (length pattern) 2) (eq? "*" (first-char (rest-char pattern))))
+ (.match-* pattern text))
+ (#true
+ (and
+ (.match-one (first-char pattern) (first-char text))
+ (.match-inner (rest-char pattern) (rest-char text))))))
- (search pattern text))
+(func .search (pattern text)
+ (if (eq? "^" (first-char pattern))
+ (.match-inner (rest-char pattern) text)
+ (block
+ (def progress text)
+ (def out (list))
+ (for-count (length text)
+ (redef out (append out (.match-inner pattern progress)))
+ (redef progress (rest-char progress)))
+ (or
+ (eq? 0 (list-length out))
+ (if (eq? 1 (list-length out))
+ (first out)
+ (apply or out))))))