lang/include-book.ss
#lang scheme

(require (lib "include.ss")
         "../private/require-below.ss"
         "../private/planet.ss")

(require (for-syntax (lib "moddep.ss" "syntax")
                     (prefix-in acl2- "acl2-reader.ss")
                     "acl2-module-v.ss"
                     (cce text)))

(provide include-book)

(define-syntax (include-book stx)

  (when (eq? (syntax-local-context) 'expression)
    (raise-syntax-error
     #f "not valid as an expression" stx))

  (syntax-case* stx (:dir :system :teachpacks) text=?

    [(_ name-stx :dir :teachpacks)

     (string? (syntax-e #'name-stx))

     (let ([name.ss (string-append (syntax-e #'name-stx) ".ss")])
       (with-syntax ([teachpack-spec
                      (datum->syntax
                       stx
                       (make-teachpack-require-syntax name.ss))])
         (syntax/loc stx
           (require-below teachpack-spec))))]

    [(_ name-stx :dir :system)
     (quasisyntax/loc stx (begin))]

    [(_ name-stx)
     (with-syntax ([name (string-append (syntax-e #'name-stx) ".lisp")])
       (quasisyntax/loc stx
         (include-at/relative-to/reader
          name-stx name-stx name acl2-read-syntax)))]))