This repository was archived by the owner on Nov 1, 2018. It is now read-only.
forked from haskell-lisp/yale-haskell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser-driver.scm
48 lines (40 loc) · 1.48 KB
/
parser-driver.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
;;; This is the top level entry to the parse. The input is a list of file
;;; names to be parsed and the output is a list of modules. Interface files
;;; generate modules similar to ordinary files.
(define (parse-files filenames)
(let ((all-mods '()))
(dolist (file filenames)
(let* ((ext (filename-type file))
(mods (cond ((string=? ext ".hs")
(parse-single-file file))
((string=? ext ".lhs")
(parse-single-file/literate file))
((string=? ext ".hi")
(parse-single-file/interface file)))))
(setf all-mods (append all-mods mods))))
all-mods))
(define (parse-single-file filename)
(parse-single-file-1 filename '#f '#f))
(define (parse-single-file/literate filename)
(parse-single-file-1 filename '#t '#f))
(define (parse-single-file/interface filename)
(parse-single-file-1 filename '#f '#t))
(define (parse-single-file-1 filename literate? interface?)
(when (memq 'reading *printers*)
(format '#t "Reading Haskell source file ~s.~%" filename))
(when (not (file-exists? filename))
(signal-file-not-found filename))
(dynamic-let ((*current-file* filename))
(let ((mods '()))
(call-with-input-file filename
(lambda (port)
(let* ((tokens (lex-port port literate?))
(module-asts (if interface?
(parse-tokens/interface tokens)
(parse-tokens tokens))))
(setf mods module-asts))))
(when (memq 'parse *printers*)
(dolist (m mods)
(format '#t "~%")
(print-full-module m)))
mods)))