Compatible with seq. Consume and return a token of exactly some particular type, or cause an error if the desired kind of token is not at the start of the input stream.
(vl-match-token type &key (function '__function__) (tokstream 'tokstream)) → (mv errmsg? token new-tokstream)
Function:
(defun vl-match-token-fn (type function tokstream) (declare (xargs :stobjs (tokstream))) (declare (xargs :guard (and (vl-tokentype-p type) (symbolp function)))) (let ((__function__ 'vl-match-token)) (declare (ignorable __function__)) (b* ((tokens (vl-tokstream->tokens)) ((when (atom tokens)) (vl-parse-error "Unexpected EOF." :function function)) (token1 (car tokens)) ((unless (eq type (vl-token->type token1))) (mv (make-vl-warning :type :vl-parse-error :msg "Parse error at ~a0: expected ~s1 but found ~s2." :args (list (vl-token->loc (car tokens)) type (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-token.errmsg? (b* (((mv ?errmsg? ?token ?new-tokstream) (vl-match-token-fn type function tokstream))) (and (iff errmsg? (not (vl-is-token? type))) (iff (vl-warning-p errmsg?) errmsg?))) :rule-classes :rewrite)
Theorem:
(defthm vl-token-p-of-vl-match-token.token (implies (vl-is-token? type) (b* (((mv ?errmsg? ?token ?new-tokstream) (vl-match-token-fn type function tokstream))) (vl-token-p token))) :rule-classes :rewrite)
Theorem:
(defthm vl-match-token-fails-gracefully (implies (not (vl-is-token? type)) (equal (mv-nth 1 (vl-match-token type)) nil)))
Theorem:
(defthm vl-match-token-under-iff (iff (mv-nth 1 (vl-match-token type)) (vl-is-token? type)))
Theorem:
(defthm vl-token->type-of-vl-match-token (implies (vl-is-token? type) (equal (vl-token->type (mv-nth 1 (vl-match-token type))) type)))
Theorem:
(defthm vl-match-token-count-strong-on-value (and (<= (vl-tokstream-measure :tokstream (mv-nth 2 (vl-match-token type))) (vl-tokstream-measure)) (implies (mv-nth 1 (vl-match-token type)) (< (vl-tokstream-measure :tokstream (mv-nth 2 (vl-match-token type))) (vl-tokstream-measure)))) :rule-classes ((:rewrite) (:linear)))
Theorem:
(defthm equal-of-vl-match-token-count (equal (equal (vl-tokstream-measure :tokstream (mv-nth 2 (vl-match-token type))) (vl-tokstream-measure)) (if (mv-nth 0 (vl-match-token type)) t nil)))