diff options
| author | mryouse | 2022-08-01 02:45:38 +0000 |
|---|---|---|
| committer | mryouse | 2022-08-01 02:45:38 +0000 |
| commit | 7300580eb3aacfe1b67918fb20259e3ec26559c2 (patch) | |
| tree | f8313e71dacf16d7c330991ae02409fe9884dc60 /libs | |
| parent | a5acb6ccc355443a9ab476cbee4c7b2cd44155ee (diff) | |
add (very) basic bracket syntax
Diffstat (limited to 'libs')
| -rw-r--r-- | libs/regex.neb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/libs/regex.neb b/libs/regex.neb index 33e2b55..8de476f 100644 --- a/libs/regex.neb +++ b/libs/regex.neb @@ -23,11 +23,26 @@ (.match-inner pattern (rest text))) (.match-inner (rest (rest pattern)) text))) +(func .read-inner (pattern end) + (.read-inner pattern end "")) + +(func .read-inner (pattern end progress) + (if (eq? end (first pattern)) + (list (rest pattern) progress) + (.read-inner (rest pattern) end (concat progress (first pattern))))) + +(func .match-bracket (pattern text) + (def processed (.read-inner (rest pattern) "]")) + (not (empty? (drop-while (split (last processed)) + (not (.match-inner (concat _item_ (first processed)) text)))))) + (func .match-inner (pattern text) (branch ((eq? "" pattern) #true) ((and (eq? "$" pattern) (eq? "" text)) #true) ((eq? "" text) #false) + ((eq? "[" (first pattern)) + (.match-bracket pattern text)) ((and (>= (length pattern) 2) (eq? "?" (first (rest pattern)))) (.match-? pattern text)) ((and (>= (length pattern) 2) (eq? "*" (first (rest pattern)))) |
