Lex zero or more characters and escape sequences in a character constant.
(lex-*-c-char pstate) → (mv erp cchars closing-squote-pos new-pstate)
That is, lex a
This is called when we expect a character constant, after reading the opening single quote of a character constant. If successful, this reads up to and including the closing single quote, and returns the position of the latter, along with the sequence of characters and escape sequences.
We read the next character; it is an error if there is none. It is also an error if the character is a new-line. If the character is a single quote, we end the recursion and return. If the character is a backslah, we attempt to read an escape sequence, then we read zero or more additional characters and escape sequences, and we combine them with the escape sequence. In all other cases, we take the character as is, we read zero or more additional characters and escape sequences, and we combine them with the character.
Function:
(defun lex-*-c-char (pstate) (declare (xargs :guard (parstatep pstate))) (let ((__function__ 'lex-*-c-char)) (declare (ignorable __function__)) (b* (((reterr) nil (irr-position) (irr-parstate)) ((erp char pos pstate) (read-char pstate)) ((unless char) (reterr-msg :where (position-to-msg pos) :expected "an escape sequence or ~ any character other than ~ single quote or backslash or new-line" :found (char-to-msg char))) ((when (= char (char-code #\'))) (retok nil pos pstate)) ((when (= char 10)) (reterr-msg :where (position-to-msg pos) :expected "an escape sequence or ~ any character other than ~ single quote or backslash or new-line" :found (char-to-msg char))) ((erp cchar & pstate) (if (= char (char-code #\\)) (b* (((erp escape pos pstate) (lex-escape-sequence pstate)) (cchar (c-char-escape escape))) (retok cchar pos pstate)) (b* ((cchar (c-char-char char))) (retok cchar pos pstate)))) ((erp cchars closing-squote-pos pstate) (lex-*-c-char pstate))) (retok (cons cchar cchars) closing-squote-pos pstate))))
Theorem:
(defthm c-char-listp-of-lex-*-c-char.cchars (b* (((mv acl2::?erp ?cchars ?closing-squote-pos ?new-pstate) (lex-*-c-char pstate))) (c-char-listp cchars)) :rule-classes :rewrite)
Theorem:
(defthm positionp-of-lex-*-c-char.closing-squote-pos (b* (((mv acl2::?erp ?cchars ?closing-squote-pos ?new-pstate) (lex-*-c-char pstate))) (positionp closing-squote-pos)) :rule-classes :rewrite)
Theorem:
(defthm parstatep-of-lex-*-c-char.new-pstate (b* (((mv acl2::?erp ?cchars ?closing-squote-pos ?new-pstate) (lex-*-c-char pstate))) (parstatep new-pstate)) :rule-classes :rewrite)
Theorem:
(defthm parsize-of-lex-*-c-char-uncond (b* (((mv acl2::?erp ?cchars ?closing-squote-pos ?new-pstate) (lex-*-c-char pstate))) (<= (parsize new-pstate) (parsize pstate))) :rule-classes :linear)
Theorem:
(defthm parsize-of-lex-*-c-char-cond (b* (((mv acl2::?erp ?cchars ?closing-squote-pos ?new-pstate) (lex-*-c-char pstate))) (implies (not erp) (<= (parsize new-pstate) (1- (- (parsize pstate) (len cchars)))))) :rule-classes :linear)