• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
      • Theories
      • Rule-classes
      • Proof-builder
      • Recursion-and-induction
      • Hons-and-memoization
      • Events
      • Parallelism
      • History
      • Programming
      • Operational-semantics
      • Real
      • Start-here
      • Debugging
      • Miscellaneous
      • Output-controls
      • Macros
      • Interfacing-tools
        • Io
        • Defttag
        • Sys-call
        • Save-exec
        • Quicklisp
        • Std/io
        • Oslib
        • Bridge
        • Clex
          • Example-lexer
            • Token-p
            • Lex-punctuation
            • Lex-id/keyword
            • Lex-string
            • Lex-whitespace
            • Lex-comment
              • Lex1
              • Lex-main
              • Lex*
              • Tokenlist-p
              • Letter-char-p
              • Idtail-char-p
              • Whitespace-char-p
              • Number-char-p
              • Tokentype-p
              • Lex*-exec
              • Newline-string
            • Sin
            • Matching-functions
            • Def-sin-progress
          • Tshell
          • Unsound-eval
          • Hacker
          • ACL2s-interface
          • Startup-banner
          • Command-line
      • Interfacing-tools
        • Io
        • Defttag
        • Sys-call
        • Save-exec
        • Quicklisp
        • Std/io
        • Oslib
        • Bridge
        • Clex
          • Example-lexer
            • Token-p
            • Lex-punctuation
            • Lex-id/keyword
            • Lex-string
            • Lex-whitespace
            • Lex-comment
              • Lex1
              • Lex-main
              • Lex*
              • Tokenlist-p
              • Letter-char-p
              • Idtail-char-p
              • Whitespace-char-p
              • Number-char-p
              • Tokentype-p
              • Lex*-exec
              • Newline-string
            • Sin
            • Matching-functions
            • Def-sin-progress
          • Tshell
          • Unsound-eval
          • Hacker
          • ACL2s-interface
          • Startup-banner
          • Command-line
        • Hardware-verification
        • Software-verification
        • Math
        • Testing-utilities
      • Example-lexer

      Lex-comment

      Match comment characters to create an :comment token.

      Signature
      (lex-comment sin) → (mv tok sin)
      Arguments
      sin — The sin stobj.
      Returns
      tok — A comment token taken from the start of the input stream, or nil if the input stream does not start with a comment.
          Type (equal (token-p tok) (if tok t nil)).
      sin — The remaining input stream, with the leading comment removed.

      Definitions and Theorems

      Function: lex-comment

      (defun lex-comment (sin)
        (declare (xargs :stobjs (sin)))
        (declare (xargs :guard t))
        (let ((__function__ 'lex-comment))
          (declare (ignorable __function__))
          (b* ((comment-p (sin-matches-p "//" sin))
               ((unless comment-p) (mv nil sin))
               ((mv match sin)
                (sin-match-through-lit (newline-string)
                                       sin))
               ((when match)
                (mv (make-token :type :comment :text match)
                    sin))
               ((mv match sin)
                (sin-match-everything sin)))
            (mv (make-token :type :comment :text match)
                sin))))

      Theorem: return-type-of-lex-comment.tok

      (defthm return-type-of-lex-comment.tok
        (b* (((mv ?tok ?sin) (lex-comment sin)))
          (equal (token-p tok) (if tok t nil)))
        :rule-classes :rewrite)

      Theorem: lex-comment-progress-weak

      (defthm lex-comment-progress-weak
        (mv-let (tok new-sin)
                (lex-comment sin)
          (declare (ignorable tok new-sin))
          (<= (len (strin-left new-sin))
              (len (strin-left sin))))
        :rule-classes ((:rewrite) (:linear)))

      Theorem: lex-comment-progress-strong

      (defthm lex-comment-progress-strong
        (mv-let (tok new-sin)
                (lex-comment sin)
          (declare (ignorable tok new-sin))
          (implies tok
                   (< (len (strin-left new-sin))
                      (len (strin-left sin)))))
        :rule-classes ((:rewrite) (:linear)))

      Theorem: lex-comment-reconstruction

      (defthm lex-comment-reconstruction
        (b* (((mv tok new-sin) (lex-comment sin)))
          (implies tok
                   (equal (append (explode (token->text tok))
                                  (strin-left new-sin))
                          (strin-left sin)))))