• 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-lit

    Match exactly some particular string literal.

    Signature
    (sin-match-lit lit sin) → (mv match sin)
    Arguments
    lit — The literal string to search for.
        Guard (stringp lit).
    sin — The sin stobj.
    Returns
    match — nil if no text was matched, or the matched text, i.e., lit itself.
        Type (or (stringp match) (not match)).
    sin — The remainder of the input stream after removing the matched text, if applicable.

    Examples:

    (sin-match-lit "apple" [applesauce])
      -->
    ("apple" [sauce])
    
    (sin-match-lit "apple" [candyapple])
      -->
    (nil [candyapple])

    Corner case: when lit is the empty string we always just fail. Matching the empty string would be quite degenerate, and failing in this case we can fit sin-match-lit into the ordinary matching-functions paradigm of progress, etc.

    Definitions and Theorems

    Function: sin-match-lit

    (defun sin-match-lit (lit sin)
           (declare (xargs :stobjs (sin)))
           (declare (xargs :guard (stringp lit)))
           (let ((__function__ 'sin-match-lit))
                (declare (ignorable __function__))
                (b* (((when (or (mbe :logic (not (stringp lit))
                                     :exec nil)
                                (equal lit "")))
                      (mv nil sin))
                     ((unless (sin-matches-p lit sin))
                      (mv nil sin))
                     (sin (sin-nthcdr (length lit) sin)))
                    (mv lit sin))))

    Theorem: return-type-of-sin-match-lit.match

    (defthm return-type-of-sin-match-lit.match
            (b* (((mv ?match ?sin)
                  (sin-match-lit lit sin)))
                (or (stringp match) (not match)))
            :rule-classes :type-prescription)

    Theorem: stringp-of-sin-match-lit.match

    (defthm stringp-of-sin-match-lit.match
            (b* (((mv ?match ?new-sin)
                  (sin-match-lit lit sin)))
                (equal (stringp match)
                       (if match t nil))))

    Theorem: non-empty-of-sin-match-lit.match

    (defthm non-empty-of-sin-match-lit.match
            (b* (((mv ?match ?new-sin)
                  (sin-match-lit lit sin)))
                (equal (equal match "") nil)))

    Theorem: sin-match-lit-progress-weak

    (defthm sin-match-lit-progress-weak
            (b* (((mv ?match ?new-sin)
                  (sin-match-lit lit sin)))
                (<= (len (strin-left new-sin))
                    (len (strin-left sin))))
            :rule-classes ((:rewrite) (:linear)))

    Theorem: sin-match-lit-progress-strong

    (defthm sin-match-lit-progress-strong
            (b* (((mv ?match ?new-sin)
                  (sin-match-lit lit sin)))
                (implies match
                         (< (len (strin-left new-sin))
                            (len (strin-left sin)))))
            :rule-classes ((:rewrite) (:linear)))

    Theorem: sin-match-lit-reconstruction

    (defthm sin-match-lit-reconstruction
            (b* (((mv ?match ?new-sin)
                  (sin-match-lit lit sin)))
                (equal (append (explode match)
                               (strin-left new-sin))
                       (strin-left sin))))

    Theorem: sin-match-lit-graceful-failure

    (defthm sin-match-lit-graceful-failure
            (b* (((mv ?match ?new-sin)
                  (sin-match-lit lit sin)))
                (implies (not match)
                         (equal new-sin sin))))

    Theorem: sin-match-lit.match-when-ok

    (defthm sin-match-lit.match-when-ok
            (b* (((mv ?match ?new-sin)
                  (sin-match-lit lit sin)))
                (implies match (equal match lit))))

    Theorem: equal-of-sin-match-lit-and-lit

    (defthm equal-of-sin-match-lit-and-lit
            (b* (((mv ?match ?new-sin)
                  (sin-match-lit lit sin)))
                (equal (equal match lit)
                       (if match
                           (and (stringp lit)
                                (consp (explode lit)))
                           (not lit)))))