Match anything that occurs up until the first occurrence of a particular string literal.
(sin-match-until-lit lit sin) → (mv foundp match sin)
Note: it is possible for
Examples:
(sin-match-until-lit "apple" [snake]) --> (nil nil [snake]) (sin-match-until-lit "apple" [snakeapple]) --> (t "snake" [apple]) (sin-match-until-lit "apple" [applesnake]) --> (t nil [applesnake])
Corner case: as in sin-match-lit, when
Function:
(defun sin-match-until-lit (lit sin) (declare (xargs :stobjs (sin))) (declare (xargs :guard (stringp lit))) (let ((__function__ 'sin-match-until-lit)) (declare (ignorable __function__)) (b* (((when (or (mbe :logic (not (stringp lit)) :exec nil) (equal lit ""))) (mv nil nil sin)) (pos (sin-find lit sin)) ((unless pos) (mv nil nil sin)) ((when (eql pos 0)) (mv t nil sin)) (match1 (sin-firstn pos sin)) (sin (sin-nthcdr pos sin))) (mv t match1 sin))))
Theorem:
(defthm booleanp-of-sin-match-until-lit.foundp (b* (((mv ?foundp ?match ?sin) (sin-match-until-lit lit sin))) (booleanp foundp)) :rule-classes :type-prescription)
Theorem:
(defthm return-type-of-sin-match-until-lit.match (b* (((mv ?foundp ?match ?sin) (sin-match-until-lit lit sin))) (or (stringp match) (not match))) :rule-classes :type-prescription)
Theorem:
(defthm stringp-of-sin-match-until-lit.match (b* (((mv ?okp ?match ?new-sin) (sin-match-until-lit lit sin))) (equal (stringp match) (if match t nil))))
Theorem:
(defthm non-empty-of-sin-match-until-lit.match (b* (((mv ?okp ?match ?new-sin) (sin-match-until-lit lit sin))) (equal (equal match "") nil)))
Theorem:
(defthm sin-match-until-lit-progress-weak (b* (((mv ?okp ?match ?new-sin) (sin-match-until-lit lit sin))) (<= (len (strin-left new-sin)) (len (strin-left sin)))) :rule-classes ((:rewrite) (:linear)))
Theorem:
(defthm sin-match-until-lit-progress-strong (b* (((mv ?okp ?match ?new-sin) (sin-match-until-lit lit sin))) (implies match (< (len (strin-left new-sin)) (len (strin-left sin))))) :rule-classes ((:rewrite) (:linear)))
Theorem:
(defthm sin-match-until-lit-reconstruction (b* (((mv ?okp ?match ?new-sin) (sin-match-until-lit lit sin))) (equal (append (explode match) (strin-left new-sin)) (strin-left sin))))
Theorem:
(defthm sin-match-until-lit-graceful-failure (b* (((mv ?okp ?match ?new-sin) (sin-match-until-lit lit sin))) (implies (not match) (equal new-sin sin))))
Theorem:
(defthm sin-match-until-lit-match-free-failure (b* (((mv ?okp ?match ?new-sin) (sin-match-until-lit lit sin))) (implies (not okp) (not match))))