• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Community
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
      • Io
      • Defttag
      • Sys-call
      • Save-exec
      • Quicklisp
      • Std/io
      • Oslib
      • 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
            • Def-match-thms
            • Sin-match-everything
          • Def-sin-progress
        • Tshell
        • Unsound-eval
        • Hacker
        • ACL2s-interface
        • Startup-banner
        • Command-line
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Matching-functions

    Sin-match-through-lit

    Match anything that occurs up to, and including, the first occurrence of a particular string literal.

    Signature
    (sin-match-through-lit lit sin) → (mv match sin)
    Arguments
    lit — The literal to search for.
        Guard (stringp lit).
    sin — The sin stobj.
    Returns
    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.

    You could use this, for instance, after reading /*, to match everything until and through */.

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

    Definitions and Theorems

    Function: sin-match-through-lit

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

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

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

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

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

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

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

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