Lex a
(lex-token input) → (mv tree rest-input)
More precisely, lex a
If the next input is an at sign,
the token may only be an annotation.
If the next input is a double quote,
the token may only be a string literal.
If the next input is a decimal digit,
the token may only be a numeric literal or a bare numeral.
Otherwise, we try to lex something that starts with a letter
(identifier, or keyword, or boolean, or address).
Note that we need to wrap string, boolean and address literals
with
Function:
(defun lex-token (input) (declare (xargs :guard (nat-listp input))) (let ((__function__ 'lex-token)) (declare (ignorable __function__)) (b* (((when (endp input)) (mv (reserrf :end-of-input) nil)) (next (lnfix (car input))) ((when (= next (char-code #\@))) (b* (((mv tree input) (lex-annotation input)) ((when (reserrp tree)) (mv (reserrf-push tree) input))) (mv (abnf-tree-wrap tree "token") input))) ((when (= next (char-code #\"))) (b* (((mv tree input) (lex-string-literal input)) ((when (reserrp tree)) (mv (reserrf-push tree) input))) (mv (abnf-tree-wrap (abnf-tree-wrap tree "atomic-literal") "token") input))) ((when (or (and (<= (char-code #\0) next) (<= next (char-code #\9))))) (b* (((mv tree input1) (lex-numeric-literal input)) ((when (not (reserrp tree))) (mv (abnf-tree-wrap (abnf-tree-wrap tree "atomic-literal") "token") input1)) ((mv tree input2) (lex-numeral input)) ((when (not (reserrp tree))) (mv (abnf-tree-wrap tree "token") input2))) (mv (reserrf-push tree) (nat-list-fix input)))) ((mv tree input) (lex-identifier/keyword/boolean/address input)) ((when (not (reserrp tree))) (mv (abnf-tree-wrap (cond ((abnf-tree-with-root-p tree "boolean-literal") (abnf-tree-wrap tree "atomic-literal")) ((abnf-tree-with-root-p tree "address-literal") (abnf-tree-wrap tree "atomic-literal")) (t tree)) "token") input)) ((mv tree input) (lex-symbol input)) ((when (not (reserrp tree))) (mv (abnf-tree-wrap tree "token") input))) (mv (reserrf :no-token) input))))
Theorem:
(defthm tree-resultp-of-lex-token.tree (b* (((mv ?tree ?rest-input) (lex-token input))) (abnf::tree-resultp tree)) :rule-classes :rewrite)
Theorem:
(defthm nat-listp-of-lex-token.rest-input (b* (((mv ?tree ?rest-input) (lex-token input))) (nat-listp rest-input)) :rule-classes :rewrite)
Theorem:
(defthm len-of-lex-token-<= (b* (((mv ?tree ?rest-input) (lex-token input))) (<= (len rest-input) (len input))) :rule-classes :linear)
Theorem:
(defthm len-of-lex-token-< (b* (((mv ?tree ?rest-input) (lex-token input))) (implies (not (reserrp tree)) (< (len rest-input) (len input)))) :rule-classes :linear)
Theorem:
(defthm lex-token-of-nat-list-fix-input (equal (lex-token (nat-list-fix input)) (lex-token input)))
Theorem:
(defthm lex-token-nat-list-equiv-congruence-on-input (implies (acl2::nat-list-equiv input input-equiv) (equal (lex-token input) (lex-token input-equiv))) :rule-classes :congruence)