Parse a natural number in a given range into a tree that matches a range numeric value notation that consists of that range.
(parse-in-range min max input) → (mv error? tree? rest-input)
Function:
(defun parse-in-range (min max input) (declare (xargs :guard (and (natp min) (natp max) (nat-listp input)))) (declare (xargs :guard (<= min max))) (b* ((min (lnfix min)) (max (lnfix max)) ((mv error? nat input) (parse-any input)) ((when error?) (mv error? nil input)) ((unless (and (<= min nat) (<= nat max))) (mv (msg "Failed to parse a number between ~x0 and ~x1; ~ found ~x2 instead." min max nat) nil (cons nat input)))) (mv nil (tree-leafterm (list nat)) input)))
Theorem:
(defthm maybe-msgp-of-parse-in-range.error? (b* (((mv ?error? ?tree? ?rest-input) (parse-in-range min max input))) (maybe-msgp error?)) :rule-classes :rewrite)
Theorem:
(defthm return-type-of-parse-in-range.tree? (b* (((mv ?error? ?tree? ?rest-input) (parse-in-range min max input))) (and (tree-optionp tree?) (implies (not error?) (treep tree?)) (implies error? (not tree?)))) :rule-classes :rewrite)
Theorem:
(defthm nat-listp-of-parse-in-range.rest-input (b* (((mv ?error? ?tree? ?rest-input) (parse-in-range min max input))) (nat-listp rest-input)) :rule-classes :rewrite)
Theorem:
(defthm len-of-parse-in-range-linear-<= (b* (((mv ?error? ?tree? ?rest-input) (parse-in-range min max input))) (<= (len rest-input) (len input))) :rule-classes :linear)
Theorem:
(defthm len-of-parse-in-range-linear-< (b* (((mv ?error? ?tree? ?rest-input) (parse-in-range min max input))) (implies (not error?) (< (len rest-input) (len input)))) :rule-classes :linear)
Theorem:
(defthm parse-in-range-of-nfix-min (equal (parse-in-range (nfix min) max input) (parse-in-range min max input)))
Theorem:
(defthm parse-in-range-nat-equiv-congruence-on-min (implies (acl2::nat-equiv min min-equiv) (equal (parse-in-range min max input) (parse-in-range min-equiv max input))) :rule-classes :congruence)
Theorem:
(defthm parse-in-range-of-nfix-max (equal (parse-in-range min (nfix max) input) (parse-in-range min max input)))
Theorem:
(defthm parse-in-range-nat-equiv-congruence-on-max (implies (acl2::nat-equiv max max-equiv) (equal (parse-in-range min max input) (parse-in-range min max-equiv input))) :rule-classes :congruence)
Theorem:
(defthm parse-in-range-of-nat-list-fix-input (equal (parse-in-range min max (nat-list-fix input)) (parse-in-range min max input)))
Theorem:
(defthm parse-in-range-nat-list-equiv-congruence-on-input (implies (acl2::nat-list-equiv input input-equiv) (equal (parse-in-range min max input) (parse-in-range min max input-equiv))) :rule-classes :congruence)