Unread a specified number of tokens.
(unread-tokens n parstate) → new-parstate
We move tokens
from the sequence of read tokens
to the sequence of unread tokens
by incrementing the number of unread tokens by
It is an internal error if
Function:
(defun unread-tokens (n parstate) (declare (xargs :stobjs (parstate))) (declare (xargs :guard (and (natp n) (parstatep parstate)))) (let ((__function__ 'unread-tokens)) (declare (ignorable __function__)) (b* ((n (nfix n)) (tokens-read (parstate->tokens-read parstate)) (tokens-unread (parstate->tokens-unread parstate)) (size (parstate->size parstate)) ((unless (<= n tokens-read)) (raise "Internal error: ~ attempting to unread ~x0 tokens ~ from ~x1 read tokens." n tokens-read) (b* ((parstate (update-parstate->tokens-unread (+ tokens-unread n) parstate)) (parstate (update-parstate->size (+ size n) parstate))) parstate)) (new-tokens-read (- tokens-read n)) (new-tokens-unread (+ tokens-unread n)) (new-size (+ size n)) (parstate (update-parstate->tokens-read new-tokens-read parstate)) (parstate (update-parstate->tokens-unread new-tokens-unread parstate)) (parstate (update-parstate->size new-size parstate))) parstate)))
Theorem:
(defthm parstatep-of-unread-tokens (implies (parstatep parstate) (b* ((new-parstate (unread-tokens n parstate))) (parstatep new-parstate))) :rule-classes :rewrite)
Theorem:
(defthm parsize-of-unread-tokens (b* ((?new-parstate (unread-tokens n parstate))) (equal (parsize new-parstate) (+ (parsize parstate) (nfix n)))))