Parse any natural number.
(parse-any input) → (mv error? nat rest-input)
This is the most basic parsing function: it parses any natural number (i.e. ABNF terminal). It is a building block of all the other parsing functions.
The parsed natural number is returned as the second result, so that the caller can examine it (e.g. to see that it is the expected one, or one of the expected ones). The only case in which this may fail is when the input list of natural number is empty; in this case, 0 is returned as second result, but it is irrelevant.
Function:
(defun parse-any (input) (declare (xargs :guard (nat-listp input))) (if (consp input) (mv nil (lnfix (car input)) (nat-list-fix (cdr input))) (mv "Failed to parse any natural number: end of input reached." 0 (nat-list-fix input))))
Theorem:
(defthm maybe-msgp-of-parse-any.error? (b* (((mv ?error? acl2::?nat ?rest-input) (parse-any input))) (maybe-msgp error?)) :rule-classes :rewrite)
Theorem:
(defthm natp-of-parse-any.nat (b* (((mv ?error? acl2::?nat ?rest-input) (parse-any input))) (natp nat)) :rule-classes (:rewrite :type-prescription))
Theorem:
(defthm nat-listp-of-parse-any.rest-input (b* (((mv ?error? acl2::?nat ?rest-input) (parse-any input))) (nat-listp rest-input)) :rule-classes :rewrite)
Theorem:
(defthm len-of-parse-any-linear-<= (b* (((mv ?error? acl2::?nat ?rest-input) (parse-any input))) (<= (len rest-input) (len input))) :rule-classes :linear)
Theorem:
(defthm len-of-parse-any-linear-< (b* (((mv ?error? acl2::?nat ?rest-input) (parse-any input))) (implies (not error?) (< (len rest-input) (len input)))) :rule-classes :linear)
Theorem:
(defthm parse-any-of-nat-list-fix-input (equal (parse-any (nat-list-fix input)) (parse-any input)))
Theorem:
(defthm parse-any-nat-list-equiv-congruence-on-input (implies (acl2::nat-list-equiv input input-equiv) (equal (parse-any input) (parse-any input-equiv))) :rule-classes :congruence)