7.7
match-string
source code: https://github.com/AlexKnauth/match-string
(require match-string) | package: match-string |
provides string-append, append, and string as match expanders,
and string-append/c, append/c, and string/c as contract constructers.
syntax
(string-append pat ...)
(string-append expr ...) string-append
pat = match-pattern | pat ooo ooo = ... | ...+ | ..k
a match expander for matching strings.
When it’s not used as a match expander, it behaves like normal rkt:string-append.
Examples:
> (match "abcdef" [(string-append "abc" s) s]) "def"
> (match "ab cdef" [(string-append (or "abc" "ab c") s) s]) "def"
> (match "cadaddadddr" [(string-append "c" (and x (or "a" "d")) ... "r") x]) '("a" "d" "a" "d" "d" "a" "d" "d" "d")
> (match "abababab" [(string-append (and los (or "ab" "abab")) ..3) los]) '("abab" "ab" "ab")
> (match "abababab" [(string-append (string-append (and lol "ab") ...+) ..3) lol]) '(("ab" "ab") ("ab") ("ab"))
a match expander for matching lists.
When it’s not used as a match expander, it behaves like normal rkt:append.
Examples:
> (match (list 1 2 3 4 5 6) [(append (list 1 2 3) p) p]) '(4 5 6)
> (match '(1 2 3 . 4) [(append (list 1 2) p) p]) '(3 . 4)
> (match '(1 2 3 . 4) [(append (list 1 2 3) p) p]) 4
> (match '(0 1 #:kw-1 kw-arg-1 2 #:kw-2 kw-arg-2 3 4) [(append (and lol (or (list (? keyword?) _) (list (not (? keyword?))))) ...) lol]) '((0) (1) (#:kw-1 kw-arg-1) (2) (#:kw-2 kw-arg-2) (3) (4))
> (match '(a b a b a b a b) [(append (append (and lolol '(a b)) ...+) ..3) lolol]) '(((a b) (a b)) ((a b)) ((a b)))
> (match '(1 2 3 . 4) [(append (and l (or '(1) '(2) '(3) 4)) ..4) l]) '((1) (2) (3) 4)
syntax
(string pat ...)
(string expr ...) string
pat = match-pattern | match-pattern ooo ooo = ... | ..k
a match expander for matching string character by character.
Whet it’s used as a match expander, it expands to (app string->list (list pat ...)).
When it’s not used as a match expander, it behaves like normal rkt:string.
procedure
(string-append/c arg ...) → flat-contract?
arg : (or/c flat-contract? '... '...+ ..k?)
procedure
(append/c arg ...) → flat-contract?
arg : (or/c flat-contract? '... '...+ ..k?)
procedure
(string/c arg ...) → flat-contract?
arg : (or/c flat-contract? '... '...+ ..k?)