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))) (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)
Theorem:
(defthm token-to-msg-of-token-option-fix-token (equal (token-to-msg (token-option-fix token)) (token-to-msg token)))
Theorem:
(defthm token-to-msg-token-option-equiv-congruence-on-token (implies (token-option-equiv token token-equiv) (equal (token-to-msg token) (token-to-msg token-equiv))) :rule-classes :congruence)