Filtering...

scan

books/build2/scan
other
(in-package "BUILD2")
other
(include-book "types")
other
(include-book "std/strings/top" :dir :system)
find-charfunction
(defun find-char
  (s c i)
  (declare (xargs :guard (and (stringp s)
        (characterp c)
        (natp i))
      :measure (nfix (- (length s) (nfix i)))))
  (let ((i (nfix i)))
    (cond ((>= i (length s)) nil)
      ((eql (char s i) c) i)
      (t (find-char s c (+ 1 i))))))
other
(defthm find-char-type
  (or (natp (find-char s c i))
    (null (find-char s c i)))
  :rule-classes :type-prescription)
other
(defthm find-char-bound
  (implies (find-char s c i)
    (< (find-char s c i)
      (length s)))
  :rule-classes :linear)
other
(defthm find-char-lower-bound
  (implies (find-char s c i)
    (<= (nfix i)
      (find-char s c i)))
  :rule-classes :linear)
extract-quoted-stringfunction
(defun extract-quoted-string
  (s i)
  (declare (xargs :guard (and (stringp s) (natp i))))
  (let* ((len (length s)) (i (nfix i)))
    (cond ((>= i len) (mv nil i))
      ((not (eql (char s i) #\")) (mv nil i))
      (t (let* ((start (+ 1 i)) (end (find-char s #\" start)))
          (if end
            (mv (subseq s start end)
              (+ 1 end))
            (mv nil i)))))))
parse-include-bookfunction
(defun parse-include-book
  (line)
  (declare (xargs :guard (stringp line)))
  (let* ((trimmed (trim line)) (trimmed-len (length trimmed))
      (localp (and (>= trimmed-len 7)
          (strprefixp "(local" trimmed)))
      (work (if localp
          (trim (subseq trimmed 6 trimmed-len))
          trimmed)))
    (if (not (strprefixp "(include-book" work))
      nil
      (let ((quote-pos (find-char work #\" 0)))
        (if (not quote-pos)
          nil
          (mv-let (name end-pos)
            (extract-quoted-string work
              quote-pos)
            (declare (ignore end-pos))
            (if name
              (make-book-dep :path name
                :localp localp)
              nil)))))))
other
(defthm parse-include-book-type
  (implies (parse-include-book line)
    (book-dep-p (parse-include-book line)))
  :rule-classes (:rewrite :type-prescription))
scan-lines-for-depsfunction
(defun scan-lines-for-deps
  (lines)
  (declare (xargs :guard (string-listp lines)))
  (if (atom lines)
    nil
    (let ((dep (parse-include-book (car lines))) (rest (scan-lines-for-deps (cdr lines))))
      (if dep
        (cons dep rest)
        rest))))
other
(defthm scan-lines-for-deps-type
  (book-dep-list-p (scan-lines-for-deps lines)))