| 1 |
;;; Ikarus Scheme -- A compiler for R6RS Scheme. |
| 2 |
;;; Copyright (C) 2006,2007,2008 Abdulaziz Ghuloum |
| 3 |
;;; |
| 4 |
;;; This program is free software: you can redistribute it and/or modify |
| 5 |
;;; it under the terms of the GNU General Public License version 3 as |
| 6 |
;;; published by the Free Software Foundation. |
| 7 |
;;; |
| 8 |
;;; This program is distributed in the hope that it will be useful, but |
| 9 |
;;; WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 |
;;; General Public License for more details. |
| 12 |
;;; |
| 13 |
;;; You should have received a copy of the GNU General Public License |
| 14 |
;;; along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
|
| 16 |
|
| 17 |
(library (ikarus.reader.annotated) |
| 18 |
(export read-source-file read-library-source-file read-script-source-file) |
| 19 |
(import |
| 20 |
(except (ikarus) read-annotated read-script-annotated) |
| 21 |
(only (ikarus.reader) read-annotated read-script-annotated) |
| 22 |
(only (ikarus.io) open-string-input-port/id)) |
| 23 |
|
| 24 |
(define (annotated-port file-name) |
| 25 |
(open-string-input-port/id |
| 26 |
(with-input-from-file file-name |
| 27 |
(lambda () |
| 28 |
(let ([x (get-string-all (current-input-port))]) |
| 29 |
(if (eof-object? x) "" x)))) |
| 30 |
file-name)) |
| 31 |
|
| 32 |
(define (read-library-source-file file-name) |
| 33 |
(read-annotated (annotated-port file-name))) |
| 34 |
|
| 35 |
(define (read-source-file file-name) |
| 36 |
(let ([p (annotated-port file-name)]) |
| 37 |
(let f () |
| 38 |
(let ([x (read-annotated p)]) |
| 39 |
(if (eof-object? x) |
| 40 |
'() |
| 41 |
(cons x (f))))))) |
| 42 |
|
| 43 |
(define (read-script-source-file file-name) |
| 44 |
(let ([p (annotated-port file-name)]) |
| 45 |
(let ([x (read-script-annotated p)]) |
| 46 |
(if (eof-object? x) |
| 47 |
(begin (close-input-port p) '()) |
| 48 |
(cons x |
| 49 |
(let f () |
| 50 |
(let ([x (read-annotated p)]) |
| 51 |
(cond |
| 52 |
[(eof-object? x) |
| 53 |
(close-input-port p) |
| 54 |
'()] |
| 55 |
[else (cons x (f))])))))))) |
| 56 |
) |