Parse a Leo file at a path.
(parse-from-file-at-path+ path state) → (mv tree lexemes state)
This function attempts to parse a Leo source file at a given path.
If parsing is successful, we return an ABNF
Since Leo files are encoded in UTF-8,
we use the Unicode library function
If reading and decoding are successful, we call parse-from-codepoints+, and we inspect its results. If there is an error, we try to provide an indication of where the error occurs in the file. For now we simply return the position in the file by turning the lexemes returned into a list of Unicode code points (not bytes) and counting such code points. While this may not be quite exactly where the error occurs (as the parser has not been optimized for error reporting yet), it should be at least close enough to significantly narrow the search.
Function:
(defun parse-from-file-at-path+ (path state) (declare (xargs :stobjs (state))) (declare (xargs :guard (stringp path))) (let ((__function__ 'parse-from-file-at-path+)) (declare (ignorable __function__)) (b* (((mv unicodes state) (acl2::read-utf8 (str-fix path) state)) ((unless (nat-listp unicodes)) (mv (reserrf unicodes) nil state)) ((mv tree lexemes) (parse-from-codepoints+ unicodes)) ((when (reserrp tree)) (b* ((pos (len (abnf::tree-list->string lexemes)))) (mv (reserrf (list :position pos :error tree)) nil state)))) (mv tree lexemes state))))
Theorem:
(defthm tree-resultp-of-parse-from-file-at-path+.tree (b* (((mv ?tree ?lexemes acl2::?state) (parse-from-file-at-path+ path state))) (abnf::tree-resultp tree)) :rule-classes :rewrite)
Theorem:
(defthm tree-listp-of-parse-from-file-at-path+.lexemes (b* (((mv ?tree ?lexemes acl2::?state) (parse-from-file-at-path+ path state))) (abnf::tree-listp lexemes)) :rule-classes :rewrite)
Theorem:
(defthm parse-from-file-at-path+-of-str-fix-path (equal (parse-from-file-at-path+ (str-fix path) state) (parse-from-file-at-path+ path state)))
Theorem:
(defthm parse-from-file-at-path+-streqv-congruence-on-path (implies (acl2::streqv path path-equiv) (equal (parse-from-file-at-path+ path state) (parse-from-file-at-path+ path-equiv state))) :rule-classes :congruence)