Parser for options that require a posp argument, e.g.,
(parse-pos name explicit-value args) → (mv err value rest-args)
This is just like parse-nat except that we also cause an error if the argument is zero.
Function:
(defun parse-pos (name explicit-value args) (declare (xargs :guard (and (stringp name) (or (not explicit-value) (stringp explicit-value)) (string-listp args)))) (let ((__function__ 'parse-pos)) (declare (ignorable __function__)) (b* (((mv val args) (if explicit-value (mv explicit-value args) (mv (car args) (cdr args)))) ((unless val) (mv (msg "Option ~s0 needs an argument" name) 1 args)) (ret (str::strval val)) ((unless ret) (mv (msg "Option ~s0 needs a number, but got ~x1" name val) 1 args)) ((when (eql ret 0)) (mv (msg "Option ~s0 can't be zero" name) 1 args))) (mv nil ret args))))
Theorem:
(defthm posp-of-parse-pos.value (b* (((mv ?err acl2::?value ?rest-args) (parse-pos name explicit-value args))) (posp value)) :rule-classes :type-prescription)
Theorem:
(defthm string-listp-of-parse-pos.rest-args (implies (force (string-listp args)) (b* (((mv ?err acl2::?value ?rest-args) (parse-pos name explicit-value args))) (string-listp rest-args))) :rule-classes :rewrite)
Theorem:
(defthm parse-pos-makes-progress (<= (len (mv-nth 2 (parse-pos name explicit-value args))) (len args)) :rule-classes ((:rewrite) (:linear)))