Match anything that occurs up to, and including, the first occurrence of a particular string literal.
(sin-match-through-lit lit sin) → (mv match sin)
You could use this, for instance, after reading
Examples:
(sin-match-through-lit "apple" [snake]) --> (nil [snake]) (sin-match-through-lit "apple" [snakeapplesauce]) --> ("snakeapple" [sauce])
Corner case: as in sin-match-lit, when
Function:
(defun sin-match-through-lit (lit sin) (declare (xargs :stobjs (sin))) (declare (xargs :guard (stringp lit))) (let ((__function__ 'sin-match-through-lit)) (declare (ignorable __function__)) (b* (((when (or (mbe :logic (not (stringp lit)) :exec nil) (equal lit ""))) (mv nil sin)) (pos (sin-find lit sin)) ((unless pos) (mv nil sin)) (stop (+ pos (length lit))) (match1 (sin-firstn stop sin)) (sin (sin-nthcdr stop sin))) (mv match1 sin))))
Theorem:
(defthm return-type-of-sin-match-through-lit.match (b* (((mv ?match ?sin) (sin-match-through-lit lit sin))) (or (stringp match) (not match))) :rule-classes :type-prescription)
Theorem:
(defthm stringp-of-sin-match-through-lit.match (b* (((mv ?match ?new-sin) (sin-match-through-lit lit sin))) (equal (stringp match) (if match t nil))))
Theorem:
(defthm non-empty-of-sin-match-through-lit.match (b* (((mv ?match ?new-sin) (sin-match-through-lit lit sin))) (equal (equal match "") nil)))
Theorem:
(defthm sin-match-through-lit-progress-weak (b* (((mv ?match ?new-sin) (sin-match-through-lit lit sin))) (<= (len (strin-left new-sin)) (len (strin-left sin)))) :rule-classes ((:rewrite) (:linear)))
Theorem:
(defthm sin-match-through-lit-progress-strong (b* (((mv ?match ?new-sin) (sin-match-through-lit lit sin))) (implies match (< (len (strin-left new-sin)) (len (strin-left sin))))) :rule-classes ((:rewrite) (:linear)))
Theorem:
(defthm sin-match-through-lit-reconstruction (b* (((mv ?match ?new-sin) (sin-match-through-lit lit sin))) (equal (append (explode match) (strin-left new-sin)) (strin-left sin))))
Theorem:
(defthm sin-match-through-lit-graceful-failure (b* (((mv ?match ?new-sin) (sin-match-through-lit lit sin))) (implies (not match) (equal new-sin sin))))