Lex zero or more characters and escape sequences in a string literal.
(lex-*-s-char parstate) → (mv erp schars closing-dquote-pos new-parstate)
That is, lex a
This is called when we expect a string literal, after reading the opening double quote of a string literal. If successful, this reads up to and including the closing double 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 double 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-*-s-char (parstate) (declare (xargs :stobjs (parstate))) (declare (xargs :guard (parstatep parstate))) (let ((__function__ 'lex-*-s-char)) (declare (ignorable __function__)) (b* (((reterr) nil (irr-position) parstate) ((erp char pos parstate) (read-char parstate)) ((unless char) (reterr-msg :where (position-to-msg pos) :expected "an escape sequence or ~ any character other than ~ double quote or backslash" :found (char-to-msg char))) ((when (= char (char-code #\"))) (retok nil pos parstate)) ((when (= char 10)) (reterr-msg :where (position-to-msg pos) :expected "an escape sequence or ~ any character other than ~ double quote or backslash" :found (char-to-msg char))) ((erp schar & parstate) (if (= char (char-code #\\)) (b* (((erp escape pos parstate) (lex-escape-sequence parstate)) (schar (s-char-escape escape))) (retok schar pos parstate)) (b* ((schar (s-char-char char))) (retok schar pos parstate)))) ((erp schars closing-dquote-pos parstate) (lex-*-s-char parstate))) (retok (cons schar schars) closing-dquote-pos parstate))))
Theorem:
(defthm s-char-listp-of-lex-*-s-char.schars (b* (((mv acl2::?erp ?schars ?closing-dquote-pos ?new-parstate) (lex-*-s-char parstate))) (s-char-listp schars)) :rule-classes :rewrite)
Theorem:
(defthm positionp-of-lex-*-s-char.closing-dquote-pos (b* (((mv acl2::?erp ?schars ?closing-dquote-pos ?new-parstate) (lex-*-s-char parstate))) (positionp closing-dquote-pos)) :rule-classes :rewrite)
Theorem:
(defthm parstatep-of-lex-*-s-char.new-parstate (implies (parstatep parstate) (b* (((mv acl2::?erp ?schars ?closing-dquote-pos ?new-parstate) (lex-*-s-char parstate))) (parstatep new-parstate))) :rule-classes :rewrite)
Theorem:
(defthm parsize-of-lex-*-s-char-uncond (b* (((mv acl2::?erp ?schars ?closing-dquote-pos ?new-parstate) (lex-*-s-char parstate))) (<= (parsize new-parstate) (parsize parstate))) :rule-classes :linear)
Theorem:
(defthm parsize-of-lex-*-s-char-cond (b* (((mv acl2::?erp ?schars ?closing-dquote-pos ?new-parstate) (lex-*-s-char parstate))) (implies (not erp) (<= (parsize new-parstate) (1- (- (parsize parstate) (len schars)))))) :rule-classes :linear)