• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Community
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
        • Crypto-hdwallet
        • Apt
        • Error-checking
        • Fty-extensions
        • Isar
        • Kestrel-utilities
        • Set
        • C
          • Syntax-for-tools
            • Formalized-subset
            • Mapping-to-language-definition
            • Input-files
            • Compilation-database
            • Printer
            • Output-files
            • Abstract-syntax-operations
            • Implementation-environments
            • Abstract-syntax
            • Concrete-syntax
            • Disambiguation
            • Validation
            • Gcc-builtins
            • Preprocessing
              • Preprocessor
                • Preprocessor-states
                • Preprocessor-printer
                • Pread-token/newline
                • Pread-token
                • Preprocessor-lexer
                  • Plex-lexeme
                  • Plex-block-comment
                  • Plex-pp-number
                  • Plex-line-comment
                  • Plex-identifier
                  • Plex-escape-sequence
                  • Plex-spaces
                    • Plex-*-hexadecimal-digit
                    • Plex-*-s-char
                    • Plex-*-c-char
                    • Plex-header-name
                    • Plex-*-q-char
                    • Plex-*-h-char
                    • Plex-character-constant
                    • Plex-hexadecimal-digit
                    • Plex-string-literal
                    • Plex-hex-quad
                  • Pproc-files
                  • Pproc-file
                  • Filepath-plexeme-list-alist-to-filepath-filedata-map
                  • Filepath-plexeme-list-alist
                  • Preprocessor-reader
                  • Preprocessor-messages
                • External-preprocessing
              • Parsing
            • Atc
            • Transformation-tools
            • Language
            • Representation
            • Insertion-sort
            • Pack
          • Soft
          • Bv
          • Imp-language
          • Ethereum
          • Event-macros
          • Java
          • Riscv
          • Bitcoin
          • Zcash
          • Yul
          • ACL2-programming-language
          • Prime-fields
          • Json
          • Syntheto
          • File-io-light
          • Cryptography
          • Number-theory
          • Axe
          • Lists-light
          • Builtins
          • Solidity
          • Helpers
          • Htclient
          • Typed-lists-light
          • Arithmetic-light
        • X86isa
        • Axe
        • Execloader
      • Math
      • Testing-utilities
    • Preprocessor-lexer

    Plex-spaces

    Lex consecutive spaces during preprocessing.

    Signature
    (plex-spaces first-pos ppstate) 
      → 
    (mv erp lexeme span new-ppstate)
    Arguments
    first-pos — Guard (positionp first-pos).
    ppstate — Guard (ppstatep ppstate).
    Returns
    lexeme — Type (plexemep lexeme).
    span — Type (spanp span).
    new-ppstate — Type (ppstatep new-ppstate), given (ppstatep ppstate).

    This is called just after a space character (code 32) has been read; the position of that space character is passed as input here.

    We read zero or more additional spaces, and we return a lexeme for spaces, with the count incremented by one to account for the first space.

    Definitions and Theorems

    Function: plex-spaces-loop

    (defun plex-spaces-loop (prev-pos ppstate)
      (declare (xargs :stobjs (ppstate)))
      (declare (xargs :guard (and (positionp prev-pos)
                                  (ppstatep ppstate))))
      (b* (((reterr) 0 (irr-position) ppstate)
           ((erp char pos ppstate)
            (pread-char ppstate)))
        (cond ((not char)
               (retok 0 (position-fix prev-pos)
                      ppstate))
              ((utf8-= char 32)
               (b* (((erp nspaces last-pos ppstate)
                     (plex-spaces-loop pos ppstate)))
                 (retok (1+ nspaces) last-pos ppstate)))
              (t (b* ((ppstate (punread-char ppstate)))
                   (retok 0 (position-fix prev-pos)
                          ppstate))))))

    Theorem: natp-of-plex-spaces-loop.nspaces

    (defthm natp-of-plex-spaces-loop.nspaces
      (b* (((mv acl2::?erp
                ?nspaces ?last-pos ?new-ppstate)
            (plex-spaces-loop prev-pos ppstate)))
        (natp nspaces))
      :rule-classes (:rewrite :type-prescription))

    Theorem: positionp-of-plex-spaces-loop.last-pos

    (defthm positionp-of-plex-spaces-loop.last-pos
      (b* (((mv acl2::?erp
                ?nspaces ?last-pos ?new-ppstate)
            (plex-spaces-loop prev-pos ppstate)))
        (positionp last-pos))
      :rule-classes :rewrite)

    Theorem: ppstatep-of-plex-spaces-loop.new-ppstate

    (defthm ppstatep-of-plex-spaces-loop.new-ppstate
      (implies (ppstatep ppstate)
               (b* (((mv acl2::?erp
                         ?nspaces ?last-pos ?new-ppstate)
                     (plex-spaces-loop prev-pos ppstate)))
                 (ppstatep new-ppstate)))
      :rule-classes :rewrite)

    Theorem: ppstate->size-of-plex-spaces-loop-uncond

    (defthm ppstate->size-of-plex-spaces-loop-uncond
      (b* (((mv acl2::?erp
                ?nspaces ?last-pos ?new-ppstate)
            (plex-spaces-loop prev-pos ppstate)))
        (<= (ppstate->size new-ppstate)
            (ppstate->size ppstate)))
      :rule-classes :linear)

    Function: plex-spaces

    (defun plex-spaces (first-pos ppstate)
      (declare (xargs :stobjs (ppstate)))
      (declare (xargs :guard (and (positionp first-pos)
                                  (ppstatep ppstate))))
      (b* (((reterr)
            (irr-plexeme)
            (irr-span)
            ppstate)
           ((erp nspaces last-pos ppstate)
            (plex-spaces-loop first-pos ppstate)))
        (retok (plexeme-spaces (1+ nspaces))
               (make-span :start first-pos
                          :end last-pos)
               ppstate)))

    Theorem: plexemep-of-plex-spaces.lexeme

    (defthm plexemep-of-plex-spaces.lexeme
      (b* (((mv acl2::?erp ?lexeme ?span ?new-ppstate)
            (plex-spaces first-pos ppstate)))
        (plexemep lexeme))
      :rule-classes :rewrite)

    Theorem: spanp-of-plex-spaces.span

    (defthm spanp-of-plex-spaces.span
      (b* (((mv acl2::?erp ?lexeme ?span ?new-ppstate)
            (plex-spaces first-pos ppstate)))
        (spanp span))
      :rule-classes :rewrite)

    Theorem: ppstatep-of-plex-spaces.new-ppstate

    (defthm ppstatep-of-plex-spaces.new-ppstate
      (implies (ppstatep ppstate)
               (b* (((mv acl2::?erp ?lexeme ?span ?new-ppstate)
                     (plex-spaces first-pos ppstate)))
                 (ppstatep new-ppstate)))
      :rule-classes :rewrite)

    Theorem: ppstate->size-of-plex-spaces-uncond

    (defthm ppstate->size-of-plex-spaces-uncond
      (b* (((mv acl2::?erp ?lexeme ?span ?new-ppstate)
            (plex-spaces first-pos ppstate)))
        (<= (ppstate->size new-ppstate)
            (ppstate->size ppstate)))
      :rule-classes :linear)