• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
      • Apt
      • Zfc
      • Acre
        • Acre-internals
          • Regex
          • Match-string-at
          • Matchstatelist-measure
          • Parse-primitive
          • Matches-remove-zero-length
          • Parse-repeatop
          • Parse-repeatbase
          • Matchstatelist-in-bounds
          • Parse-range
            • Parse-charset-set
            • Parse-charset-atom
            • Match-regex-locs
            • Parse-octal-charcode
            • Parse-k-backref
            • Parse-g-backref
            • Matchstatelist-all-have-backref
            • Parse-repeatmod
            • Parse-charset-elem
            • Parse-charset-aux
            • Parse-hex-charcode
            • Parse-charset
            • Matchstatelist-indices-lte
            • Matchstatelist-indices-gte
            • Match-exact
            • Matches-add-backref
            • Matchresult
            • Preproc-legible-aux
            • Maybe-backref
            • Match-charset
            • Undup-equiv
            • Find-substr
            • Maybe-backref-extract-substr
            • Matchstatelist-min-index
            • Matchstate-in-bounds
            • Match-add-backref
            • Undup
            • Backref-alist-in-bounds
            • Backref
            • Matchstate
            • Matchresult->matched-substr
            • Matchresult->captured-substr!
            • Matchresult->captured-substr
            • Maybe-backref-in-bounds
            • Matchmode
            • Backref-extract-substr
            • Charset-range
            • Matchstate-measure
            • Backref-in-bounds
            • Rev-keys
            • Parse-regex
            • Undup-exec
            • Get-charset
            • Regex-concat2
            • Preproc-legible
            • Matchresult-in-bounds
            • Regex-disjunct2
            • Backref-alist
            • Named-captures-bindings
            • Captures-bindings
            • Matchstatelist
            • Charset-char-regex
            • Repeatmod-p
          • Parse-and-match-regex
          • Match-regex
          • Parse
          • Matchresult->matchedp
          • Match
        • Milawa
        • Smtlink
        • Abnf
        • Vwsim
        • Isar
        • Wp-gen
        • Dimacs-reader
        • Pfcs
        • Legacy-defrstobj
        • Proof-checker-array
        • Soft
        • C
        • Farray
        • Rp-rewriter
        • Instant-runoff-voting
        • Imp-language
        • Sidekick
        • Leftist-trees
        • Java
        • Taspi
        • Bitcoin
        • Riscv
        • Des
        • Ethereum
        • X86isa
        • Sha-2
        • Yul
        • Zcash
        • Proof-checker-itp13
        • Regex
        • ACL2-programming-language
        • Json
        • Jfkr
        • Equational
        • Cryptography
        • Poseidon
        • Where-do-i-place-my-book
        • Axe
        • Bigmems
        • Builtins
        • Execloader
        • Aleo
        • Solidity
        • Paco
        • Concurrent-programs
        • Bls12-377-curves
      • Debugging
      • Std
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Acre-internals

    Parse-range

    Signature
    (parse-range x index) → (mv err min max new-index)
    Arguments
    x — Guard (stringp x).
    index — Guard (natp index).
    Returns
    err — Type (acl2::maybe-stringp err).
    min — Type (natp min).
    max — Type (maybe-natp max).
    new-index — Type (natp new-index).

    Definitions and Theorems

    Function: parse-range

    (defun parse-range (x index)
     (declare (xargs :guard (and (stringp x) (natp index))))
     (declare (xargs :guard (<= index (strlen x))))
     (let ((__function__ 'parse-range))
      (declare (ignorable __function__))
      (b* ((x (lstrfix x))
           (index (lnfix index))
           ((when (eql index (strlen x)))
            (mv "String ended inside range expression (start)"
                0 0 index))
           ((mv min len1)
            (str::parse-nat-from-string x 0 0 index (strlen x)))
           (index (+ len1 index))
           ((when (eql index (strlen x)))
            (mv "String ended inside range expression (after min index)"
                0 0 index))
           (nextchar (char x index))
           ((when (eql nextchar #\}))
            (mv nil min min (+ 1 index)))
           ((unless (eql nextchar #\,))
            (mv "Malformed range -- expecting comma"
                0 0 index))
           (index (+ 1 index))
           ((when (eql index (strlen x)))
            (mv "String ended inside range expression (after comma)"
                0 0 index))
           ((mv val2 len2)
            (str::parse-nat-from-string x 0 0 index (strlen x)))
           (max (and (not (eql len2 0)) val2))
           (index (+ len2 index))
           ((when (eql index (strlen x)))
            (mv "String ended inside range expression (after max index)"
                0 0 index))
           (nextchar (char x index))
           ((unless (eql nextchar #\}))
            (mv "Malformed range -- expecting close brace"
                0 0 index)))
        (mv nil min max (+ 1 index)))))

    Theorem: maybe-stringp-of-parse-range.err

    (defthm maybe-stringp-of-parse-range.err
      (b* (((mv ?err common-lisp::?min
                common-lisp::?max ?new-index)
            (parse-range x index)))
        (acl2::maybe-stringp err))
      :rule-classes :type-prescription)

    Theorem: natp-of-parse-range.min

    (defthm natp-of-parse-range.min
      (b* (((mv ?err common-lisp::?min
                common-lisp::?max ?new-index)
            (parse-range x index)))
        (natp min))
      :rule-classes :type-prescription)

    Theorem: maybe-natp-of-parse-range.max

    (defthm maybe-natp-of-parse-range.max
      (b* (((mv ?err common-lisp::?min
                common-lisp::?max ?new-index)
            (parse-range x index)))
        (maybe-natp max))
      :rule-classes :type-prescription)

    Theorem: natp-of-parse-range.new-index

    (defthm natp-of-parse-range.new-index
      (b* (((mv ?err common-lisp::?min
                common-lisp::?max ?new-index)
            (parse-range x index)))
        (natp new-index))
      :rule-classes :type-prescription)

    Theorem: new-index-of-parse-range

    (defthm new-index-of-parse-range
      (b* (((mv ?err common-lisp::?min
                common-lisp::?max ?new-index)
            (parse-range x index)))
        (<= (nfix index) new-index))
      :rule-classes :linear)

    Theorem: new-index-of-parse-range-strong

    (defthm new-index-of-parse-range-strong
      (b* (((mv ?err common-lisp::?min
                common-lisp::?max ?new-index)
            (parse-range x index)))
        (implies (not err)
                 (< (nfix index) new-index)))
      :rule-classes :linear)

    Theorem: new-index-of-parse-range-less-than-length

    (defthm new-index-of-parse-range-less-than-length
      (b* (((mv ?err common-lisp::?min
                common-lisp::?max ?new-index)
            (parse-range x index)))
        (implies (<= (nfix index)
                     (len (acl2::explode x)))
                 (<= new-index (len (acl2::explode x)))))
      :rule-classes :linear)

    Theorem: parse-range-of-str-fix-x

    (defthm parse-range-of-str-fix-x
      (equal (parse-range (acl2::str-fix x) index)
             (parse-range x index)))

    Theorem: parse-range-streqv-congruence-on-x

    (defthm parse-range-streqv-congruence-on-x
      (implies (acl2::streqv x x-equiv)
               (equal (parse-range x index)
                      (parse-range x-equiv index)))
      :rule-classes :congruence)

    Theorem: parse-range-of-nfix-index

    (defthm parse-range-of-nfix-index
      (equal (parse-range x (nfix index))
             (parse-range x index)))

    Theorem: parse-range-nat-equiv-congruence-on-index

    (defthm parse-range-nat-equiv-congruence-on-index
      (implies (acl2::nat-equiv index index-equiv)
               (equal (parse-range x index)
                      (parse-range x index-equiv)))
      :rule-classes :congruence)