]> git.mdlowis.com Git - archive/dlang-scm.git/commitdiff
Main now parses the input file given, writes the scheme to a file, and subsequently...
authorMike D. Lowis <mike@mdlowis.com>
Mon, 23 Jul 2012 19:35:10 +0000 (15:35 -0400)
committerMike D. Lowis <mike@mdlowis.com>
Mon, 23 Jul 2012 19:35:10 +0000 (15:35 -0400)
source/main.scm

index 99bd28139fa6be35097ef6710562a87d4cc102e6..799d697e230edf369003d823c297f5f9318fbe80 100644 (file)
@@ -1,12 +1,24 @@
 (declare (uses lexer parser scheme))
 
+; Require the String library extension
+(require-extension srfi-13)
+
+(define (get-output-file-name ifname)
+  (string-append (substring ifname 0 (string-index-right ifname #\.)) ".scm"))
+
 (define (parse-file fname)
-  (define result (dlang/program (dlang/lexer (open-input-file fname))))
-  (set! result (scheme-program result))
-  result)
+  (scheme-program (dlang/program (dlang/lexer (open-input-file fname)))))
+
+(define (interpret-file fname)
+  (define ofname (get-output-file-name fname))
+  (define program (parse-file fname))
+  (with-output-to-file ofname
+    (lambda () (map print program)))
+  (load ofname))
 
 ; If we have a file, then parse it
 (if (= 1 (length (command-line-arguments)))
-  (map print (parse-file (car (command-line-arguments))))
+  (interpret-file (car (command-line-arguments)))
+  ;(map print (parse-file (car (command-line-arguments))))
   (print "No input file provided."))