• Top
    • Documentation
    • Books
    • Recursion-and-induction
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
      • Io
      • Defttag
      • Sys-call
      • Save-exec
      • Quicklisp
      • Oslib
      • Std/io
      • Bridge
      • Clex
        • Example-lexer
        • Sin
        • Matching-functions
          • Sin-match-until-lit
            • Sin-match-lit
            • Sin-match-charset*
            • Sin-match-some-lit
            • Sin-match-through-lit
            • Sin-match-everything
            • Def-match-thms
          • Def-sin-progress
        • Tshell
        • Unsound-eval
        • Hacker
        • Startup-banner
        • Command-line
      • Hardware-verification
      • Software-verification
      • Testing-utilities
      • Math
    • Matching-functions

    Sin-match-until-lit

    Match anything that occurs up until the first occurrence of a particular string literal.

    Signature
    (sin-match-until-lit lit sin) → (mv foundp match sin)
    Arguments
    lit — The literal to search for.
        Guard (stringp lit).
    sin — The sin stobj.
    Returns
    foundp — Was lit found anywhere in the input stream?.
        Type (booleanp foundp).
    match — nil when no text is matched, or a non-empty string containing the matched text.
        Type (or (stringp match) (not match)).
    sin — The remainder of the input stream, with the match removed, if applicable.

    Note: it is possible for match to be nil even when lit is foundp. In particular, this happens if lit occurs immediately at the start of the input stream.

    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 lit is the empty string we always fail.

    Definitions and Theorems

    Function: sin-match-until-lit

    (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: booleanp-of-sin-match-until-lit.foundp

    (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: return-type-of-sin-match-until-lit.match

    (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: stringp-of-sin-match-until-lit.match

    (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: non-empty-of-sin-match-until-lit.match

    (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: sin-match-until-lit-progress-weak

    (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: sin-match-until-lit-progress-strong

    (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: sin-match-until-lit-reconstruction

    (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: sin-match-until-lit-graceful-failure

    (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: sin-match-until-lit-match-free-failure

    (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))))