Lex a character constant.
(lex-character-constant cprefix? first-pos parstate) → (mv erp lexeme span new-parstate)
This is called when we expect a character constant, after the opening single quote, and the prefix before that if present, have already been read. So we read zero or more characters and escape sequences, and ensure that there is at least one (according to the grammar). In the process of reading those characters and escape sequences, we read up to the closing single quote (see lex-*-c-char), whose position we use as the ending one of the span we return. The starting position of the span is passed to this function as input.
Function:
(defun lex-character-constant (cprefix? first-pos parstate) (declare (xargs :stobjs (parstate))) (declare (xargs :guard (and (cprefix-optionp cprefix?) (positionp first-pos) (parstatep parstate)))) (let ((__function__ 'lex-character-constant)) (declare (ignorable __function__)) (b* (((reterr) (irr-lexeme) (irr-span) parstate) ((erp cchars closing-squote-pos parstate) (lex-*-c-char parstate)) (span (make-span :start first-pos :end closing-squote-pos)) ((unless cchars) (reterr-msg :where (position-to-msg closing-squote-pos) :expected "one or more characters and escape sequences" :found "none"))) (retok (lexeme-token (token-const (const-char (cconst cprefix? cchars)))) span parstate))))
Theorem:
(defthm lexemep-of-lex-character-constant.lexeme (b* (((mv acl2::?erp ?lexeme ?span ?new-parstate) (lex-character-constant cprefix? first-pos parstate))) (lexemep lexeme)) :rule-classes :rewrite)
Theorem:
(defthm spanp-of-lex-character-constant.span (b* (((mv acl2::?erp ?lexeme ?span ?new-parstate) (lex-character-constant cprefix? first-pos parstate))) (spanp span)) :rule-classes :rewrite)
Theorem:
(defthm parstatep-of-lex-character-constant.new-parstate (implies (parstatep parstate) (b* (((mv acl2::?erp ?lexeme ?span ?new-parstate) (lex-character-constant cprefix? first-pos parstate))) (parstatep new-parstate))) :rule-classes :rewrite)
Theorem:
(defthm parsize-of-lex-character-constant-uncond (b* (((mv acl2::?erp ?lexeme ?span ?new-parstate) (lex-character-constant cprefix? first-pos parstate))) (<= (parsize new-parstate) (parsize parstate))) :rule-classes :linear)
Theorem:
(defthm parsize-of-lex-character-constant-cond (b* (((mv acl2::?erp ?lexeme ?span ?new-parstate) (lex-character-constant cprefix? first-pos parstate))) (implies (not erp) (<= (parsize new-parstate) (1- (parsize parstate))))) :rule-classes :linear)