Represent a token as a message.
(token-to-msg token) → msg
This is used in parser error messages,
so it does not have to provide a complete description of the token
for all possible tokens.
We only give a complete description of keyword and punctuator tokens,
because those are the kinds that may be a mismatch
(e.g. expecing a
It is convenient to treat uniformly tokens and
Function:
(defun token-to-msg (token) (declare (xargs :guard (token-optionp token))) (let ((__function__ 'token-to-msg)) (declare (ignorable __function__)) (if token (token-case token :keyword (msg "the keyword ~x0" token.unwrap) :ident "an identifier" :const "a constant" :string "a string literal" :punctuator (msg "the punctuator ~x0" token.unwrap)) "end of file")))
Theorem:
(defthm msgp-of-token-to-msg (b* ((msg (token-to-msg token))) (msgp msg)) :rule-classes :rewrite)