Wrapper: lex the entire input stream or fail with a good error message.
(lex-main sin) → (mv errmsg tokens sin)
Function:
(defun lex-main (sin) (declare (xargs :stobjs (sin))) (declare (xargs :guard t)) (let ((__function__ 'lex-main)) (declare (ignorable __function__)) (b* (((mv okp tokens sin) (lex* sin)) ((when okp) (mv nil tokens sin)) (errmsg (cat (sin-file sin) ":" (natstr (sin-line sin)) ":" (natstr (sin-col sin)) ": syntax error near: " (sin-firstn (min 20 (sin-len sin)) sin) (newline-string)))) (mv errmsg tokens sin))))
Theorem:
(defthm return-type-of-lex-main.errmsg (b* (((mv ?errmsg ?tokens ?sin) (lex-main sin))) (or (stringp errmsg) (not errmsg))) :rule-classes :type-prescription)
Theorem:
(defthm tokenlist-p-of-lex-main.tokens (b* (((mv ?errmsg ?tokens ?sin) (lex-main sin))) (tokenlist-p tokens)) :rule-classes :rewrite)
Theorem:
(defthm tokenlist-all-text-of-lex-main (b* (((mv errmsg tokens ?new-sin) (lex-main sin))) (implies (not errmsg) (equal (tokenlist-all-text tokens) (implode (strin-left sin))))))