Parse an
(parse-operator-among operators token input) → (mv tree next-token rest-input)
This is used to check the presence of an expected operator.
We return it as a leaf tree as the first result,
because this is how an operator occurs
in the CSTs of the syntactic grammar.
In other words, the
This is consistent with the fact that
the rule
Function:
(defun parse-operator-among-aux (nats strings) (declare (xargs :guard (and (nat-listp nats) (string-listp strings)))) (let ((__function__ 'parse-operator-among-aux)) (declare (ignorable __function__)) (and (consp strings) (or (equal (string=>nats (str-fix (car strings))) (nat-list-fix nats)) (parse-operator-among-aux nats (cdr strings))))))
Theorem:
(defthm booleanp-of-parse-operator-among-aux (b* ((yes/no (parse-operator-among-aux nats strings))) (booleanp yes/no)) :rule-classes :rewrite)
Theorem:
(defthm parse-operator-among-aux-of-nat-list-fix-nats (equal (parse-operator-among-aux (nat-list-fix nats) strings) (parse-operator-among-aux nats strings)))
Theorem:
(defthm parse-operator-among-aux-nat-list-equiv-congruence-on-nats (implies (acl2::nat-list-equiv nats nats-equiv) (equal (parse-operator-among-aux nats strings) (parse-operator-among-aux nats-equiv strings))) :rule-classes :congruence)
Theorem:
(defthm parse-operator-among-aux-of-string-list-fix-strings (equal (parse-operator-among-aux nats (string-list-fix strings)) (parse-operator-among-aux nats strings)))
Theorem:
(defthm parse-operator-among-aux-string-list-equiv-congruence-on-strings (implies (str::string-list-equiv strings strings-equiv) (equal (parse-operator-among-aux nats strings) (parse-operator-among-aux nats strings-equiv))) :rule-classes :congruence)
Function:
(defun parse-operator-among (operators token input) (declare (xargs :guard (and (string-listp operators) (abnf::tree-optionp token) (abnf::tree-listp input)))) (declare (xargs :guard (subsetp-equal operators *operators*))) (let ((__function__ 'parse-operator-among)) (declare (ignorable __function__)) (b* ((tree (check-token-root "operator" token)) ((when (reserrp tree)) (perr (reserrf-push tree))) (fringe (abnf::tree->string tree)) ((unless (nat-listp fringe)) (perr :impossible)) ((unless (parse-operator-among-aux fringe operators)) (perr (list :required :one-of (string-list-fix operators) :found tree))) (tree (abnf::tree-leafterm fringe)) ((mv token input) (parse-token input))) (mv tree token input))))
Theorem:
(defthm tree-resultp-of-parse-operator-among.tree (b* (((mv ?tree ?next-token ?rest-input) (parse-operator-among operators token input))) (abnf::tree-resultp tree)) :rule-classes :rewrite)
Theorem:
(defthm tree-optionp-of-parse-operator-among.next-token (b* (((mv ?tree ?next-token ?rest-input) (parse-operator-among operators token input))) (abnf::tree-optionp next-token)) :rule-classes :rewrite)
Theorem:
(defthm tree-listp-of-parse-operator-among.rest-input (b* (((mv ?tree ?next-token ?rest-input) (parse-operator-among operators token input))) (abnf::tree-listp rest-input)) :rule-classes :rewrite)
Theorem:
(defthm parsize-of-parse-operator-among-<= (b* (((mv ?tree ?next-token ?rest-input) (parse-operator-among operators token input))) (<= (parsize next-token rest-input) (parsize token input))) :rule-classes :linear)
Theorem:
(defthm parsize-of-parse-operator-among-< (b* (((mv ?tree ?next-token ?rest-input) (parse-operator-among operators token input))) (implies (not (reserrp tree)) (< (parsize next-token rest-input) (parsize token input)))) :rule-classes :linear)
Theorem:
(defthm len-of-parse-operator-among-<= (b* (((mv ?tree ?next-token ?rest-input) (parse-operator-among operators token input))) (<= (len rest-input) (len input))) :rule-classes :linear)
Theorem:
(defthm len-of-parse-operator-among-< (b* (((mv ?tree ?next-token ?rest-input) (parse-operator-among operators token input))) (implies (and (not (reserrp tree)) next-token) (< (len rest-input) (len input)))) :rule-classes :linear)
Theorem:
(defthm parse-operator-among-of-string-list-fix-operators (equal (parse-operator-among (string-list-fix operators) token input) (parse-operator-among operators token input)))
Theorem:
(defthm parse-operator-among-string-list-equiv-congruence-on-operators (implies (str::string-list-equiv operators operators-equiv) (equal (parse-operator-among operators token input) (parse-operator-among operators-equiv token input))) :rule-classes :congruence)
Theorem:
(defthm parse-operator-among-of-tree-option-fix-token (equal (parse-operator-among operators (abnf::tree-option-fix token) input) (parse-operator-among operators token input)))
Theorem:
(defthm parse-operator-among-tree-option-equiv-congruence-on-token (implies (abnf::tree-option-equiv token token-equiv) (equal (parse-operator-among operators token input) (parse-operator-among operators token-equiv input))) :rule-classes :congruence)
Theorem:
(defthm parse-operator-among-of-tree-list-fix-input (equal (parse-operator-among operators token (abnf::tree-list-fix input)) (parse-operator-among operators token input)))
Theorem:
(defthm parse-operator-among-tree-list-equiv-congruence-on-input (implies (abnf::tree-list-equiv input input-equiv) (equal (parse-operator-among operators token input) (parse-operator-among operators token input-equiv))) :rule-classes :congruence)