• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Community
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
      • Gl
      • Esim
      • Vl2014
      • Sv
      • Fgl
      • Vwsim
      • Vl
        • Syntax
        • Loader
          • Preprocessor
            • Vl-iframe
            • Preprocessor-ifdef-minutia
            • Vl-preprocess
            • Vl-preprocess-loop
            • Vl-includeskips
            • Vl-read-until-end-of-define
            • Vl-define-formallist->defaults
            • Vl-define
            • Vl-expand-define
            • Vl-read-include
            • Vl-substitute-into-macro-text
            • Vl-process-ifdef
            • Ppst
            • Vl-read-define-default-text
            • Vl-process-define
            • Preprocessor-include-minutia
            • Vl-trim-for-preproc
            • Vl-line-up-define-formals-and-actuals
            • Vl-process-undef
            • Vl-split-define-text
            • Vl-def-context
            • Vl-process-endif
            • Scan-backward-for-non-whitespace
              • Vl-ifdef-context
              • Scan-backward-for-whitespace
              • Vl-atvl-atts-text
              • Scan-for-non-whitespace
              • Vl-check-remaining-formals-all-have-defaults
              • Vl-process-else
              • Vl-is-compiler-directive-p
              • Vl-includeskips-controller-lookup
              • Vl-ifdef-use-map
              • Vl-defines
              • Vl-def-use-map
              • Vl-nice-bytes
              • Vl-safe-previous-n
              • Vl-safe-next-n
              • Vl-ppst-pad
              • Vl-filename-to-string-literal
              • Vl-maybe-update-filemap
              • *vl-preprocess-clock*
              • Vl-ppst->warnings
              • Vl-ppst->iskips
              • Vl-ppst->ifdefmap
              • Vl-ppst->idcache
              • Vl-istack
              • Vl-ppst->istack
              • Vl-ppst->includes
              • Vl-ppst->filemap
              • Vl-ppst->defmap
              • Vl-ppst->defines
              • Vl-ppst->config
              • Vl-ppst->bytes
              • Vl-ppst->activep
              • Vl-ppst->acc
              • Vl-ppst-record-ifdef-use
              • Vl-ppst-record-def-use
              • Vl-ifdef-context-list
              • Vl-def-context-list
              • Vl-ppst-update-warnings
              • Vl-ppst-update-istack
              • Vl-ppst-update-iskips
              • Vl-ppst-update-includes
              • Vl-ppst-update-ifdefmap
              • Vl-ppst-update-idcache
              • Vl-ppst-update-filemap
              • Vl-ppst-update-defmap
              • Vl-ppst-update-defines
              • Vl-ppst-update-config
              • Vl-ppst-update-activep
              • Vl-ppst-update-bytes
              • Vl-ppst-update-acc
              • Vl-ppst-unsound-nreverse-acc
            • Vl-loadconfig
            • Vl-loadstate
            • Lexer
            • Parser
            • Vl-load-merge-descriptions
            • Vl-find-basename/extension
            • Vl-load-file
            • Vl-loadresult
            • Scope-of-defines
            • Vl-find-file
            • Vl-flush-out-descriptions
            • Vl-description
            • Vl-read-file
            • Vl-includeskips-report-gather
            • Vl-load-main
            • Extended-characters
            • Vl-load
            • Vl-load-description
            • Vl-descriptions-left-to-load
            • Inject-warnings
            • Vl-preprocess-debug
            • Vl-write-preprocessor-debug-file
            • Vl-read-file-report-gather
            • Vl-load-descriptions
            • Vl-load-files
            • Translate-off
            • Vl-load-read-file-hook
            • Vl-read-file-report
            • Vl-loadstate-pad
            • Vl-load-summary
            • Vl-collect-modules-from-descriptions
            • Vl-loadstate->warnings
            • Vl-iskips-report
            • Vl-descriptionlist
          • Warnings
          • Getting-started
          • Utilities
          • Printer
          • Kit
          • Mlib
          • Transforms
        • X86isa
        • Svl
        • Rtl
      • Software-verification
      • Math
      • Testing-utilities
    • Preprocessor

    Scan-backward-for-non-whitespace

    Signature
    (scan-backward-for-non-whitespace idx x) → result-idx
    Arguments
    idx — Guard (natp idx).
    x — Guard (stringp x).
    Returns
    result-idx — Type (natp result-idx).

    Definitions and Theorems

    Function: scan-backward-for-non-whitespace

    (defun scan-backward-for-non-whitespace (idx x)
      (declare (xargs :guard (and (natp idx) (stringp x))))
      (declare (xargs :guard (<= idx (length x))))
      (let ((__function__ 'scan-backward-for-non-whitespace))
        (declare (ignorable __function__))
        (b* (((when (zp idx)) (length x))
             ((unless (mbt (< 0 (length x)))) 0)
             (idx (mbe :logic (1- (min idx (length x)))
                       :exec (1- idx)))
             ((when (not (vl-whitespace-p (char x idx))))
              (lnfix idx)))
          (scan-backward-for-non-whitespace idx x))))

    Theorem: natp-of-scan-backward-for-non-whitespace

    (defthm natp-of-scan-backward-for-non-whitespace
      (b* ((result-idx (scan-backward-for-non-whitespace idx x)))
        (natp result-idx))
      :rule-classes :type-prescription)

    Theorem: scan-backward-for-non-whitespace-upper-bound

    (defthm scan-backward-for-non-whitespace-upper-bound
      (b* ((?result-idx (scan-backward-for-non-whitespace idx x)))
        (<= result-idx (length x)))
      :rule-classes :linear)

    Theorem: scan-backward-for-non-whitespace-finds-non-whitespace

    (defthm scan-backward-for-non-whitespace-finds-non-whitespace
      (b* ((?result-idx (scan-backward-for-non-whitespace idx x)))
        (implies (not (equal result-idx (length x)))
                 (not (vl-whitespace-p (char x result-idx))))))

    Theorem: scan-backward-for-non-whitespace-bound-when-non-whitespace-exists

    (defthm
      scan-backward-for-non-whitespace-bound-when-non-whitespace-exists
      (b* ((?result-idx (scan-backward-for-non-whitespace idx x)))
        (implies (and (< (nfix nw-idx) (length x))
                      (not (vl-whitespace-p (char x nw-idx)))
                      (< (nfix nw-idx) (nfix idx)))
                 (and (<= (nfix nw-idx) result-idx)
                      (< result-idx (length x))))))

    Theorem: scan-backward-for-non-whitespace-gte-than-scan-for-non-whitespace

    (defthm
      scan-backward-for-non-whitespace-gte-than-scan-for-non-whitespace
      (<= (scan-for-non-whitespace 0 x)
          (scan-backward-for-non-whitespace (length x)
                                            x))
      :rule-classes :linear)