Lex zero or more characters and escape sequences in a character constant.
(lex-c-chars pstate) → (mv erp cchars closing-squote-pos new-pstate)
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-chars (pstate) (declare (xargs :guard (parstatep pstate))) (let ((__function__ 'lex-c-chars)) (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-chars pstate))) (retok (cons cchar cchars) closing-squote-pos pstate))))
Theorem:
(defthm c-char-listp-of-lex-c-chars.cchars (b* (((mv acl2::?erp ?cchars ?closing-squote-pos ?new-pstate) (lex-c-chars pstate))) (c-char-listp cchars)) :rule-classes :rewrite)
Theorem:
(defthm positionp-of-lex-c-chars.closing-squote-pos (b* (((mv acl2::?erp ?cchars ?closing-squote-pos ?new-pstate) (lex-c-chars pstate))) (positionp closing-squote-pos)) :rule-classes :rewrite)
Theorem:
(defthm parstatep-of-lex-c-chars.new-pstate (b* (((mv acl2::?erp ?cchars ?closing-squote-pos ?new-pstate) (lex-c-chars pstate))) (parstatep new-pstate)) :rule-classes :rewrite)
Theorem:
(defthm parsize-of-lex-c-chars-uncond (b* (((mv acl2::?erp ?cchars ?closing-squote-pos ?new-pstate) (lex-c-chars pstate))) (<= (parsize new-pstate) (parsize pstate))) :rule-classes :linear)
Theorem:
(defthm parsize-of-lex-c-chars-cond (b* (((mv acl2::?erp ?cchars ?closing-squote-pos ?new-pstate) (lex-c-chars pstate))) (implies (not erp) (<= (parsize new-pstate) (1- (- (parsize pstate) (len cchars)))))) :rule-classes :linear)