Compatible with seq. Consume and return a token if it has one of several types. Cause an error if the first token isn't one of the acceptable types.
(vl-match-some-token types &key (function '__function__) (tokstream 'tokstream)) → (mv errmsg? token new-tokstream)
Function:
(defun vl-match-some-token-fn (types function tokstream) (declare (xargs :stobjs (tokstream))) (declare (xargs :guard (and (vl-tokentypelist-p types) (symbolp function)))) (let ((__function__ 'vl-match-some-token)) (declare (ignorable __function__)) (b* ((tokens (vl-tokstream->tokens)) ((when (atom tokens)) (vl-parse-error "Unexpected EOF." :function function)) (token1 (car tokens)) ((unless (member-eq (vl-token->type token1) types)) (mv (make-vl-warning :type :vl-parse-error :msg "Parse error at ~a0: expected one of ~x1, but found ~s2." :args (list (vl-token->loc token1) types (vl-token->type token1)) :fatalp t :fn function) nil tokstream)) (tokstream (vl-tokstream-pop))) (mv nil token1 tokstream))))
Theorem:
(defthm return-type-of-vl-match-some-token.errmsg? (b* (((mv ?errmsg? ?token ?new-tokstream) (vl-match-some-token-fn types function tokstream))) (and (iff errmsg? (not (vl-is-some-token? types))) (iff (vl-warning-p errmsg?) errmsg?))) :rule-classes :rewrite)
Theorem:
(defthm vl-token-p-of-vl-match-some-token.token (implies (vl-is-some-token? types) (b* (((mv ?errmsg? ?token ?new-tokstream) (vl-match-some-token-fn types function tokstream))) (vl-token-p token))) :rule-classes :rewrite)
Theorem:
(defthm vl-match-some-token-fails-gracefully (implies (not (vl-is-some-token? types)) (equal (mv-nth 1 (vl-match-some-token types)) nil)))
Theorem:
(defthm vl-match-some-token-count-strong-on-value (and (<= (vl-tokstream-measure :tokstream (mv-nth 2 (vl-match-some-token types))) (vl-tokstream-measure)) (implies (mv-nth 1 (vl-match-some-token types)) (< (vl-tokstream-measure :tokstream (mv-nth 2 (vl-match-some-token types))) (vl-tokstream-measure)))) :rule-classes ((:rewrite) (:linear)))
Theorem:
(defthm equal-of-vl-match-some-token-count (equal (equal (vl-tokstream-measure :tokstream (mv-nth 2 (vl-match-some-token types))) (vl-tokstream-measure)) (if (mv-nth 0 (vl-match-some-token types)) t nil)))