add raco read

This commit is contained in:
Matthew Flatt 2015-06-03 11:53:11 -06:00
parent 00893cbd3f
commit 3da4b863cf
4 changed files with 45 additions and 31 deletions

View File

@ -1,9 +1,14 @@
#lang racket/base #lang racket/base
(require racket/cmdline
(module expand racket/base
(require racket/cmdline
raco/command-name raco/command-name
racket/pretty) racket/pretty)
(define source-files (provide show-program)
(define (show-program expand)
(define source-files
(command-line (command-line
#:program (short-program+command-name) #:program (short-program+command-name)
#:once-each #:once-each
@ -16,7 +21,7 @@
#:args source-file #:args source-file
source-file)) source-file))
(for ([src-file source-files]) (for ([src-file source-files])
(let ([src-file (path->complete-path src-file)]) (let ([src-file (path->complete-path src-file)])
(let-values ([(base name dir?) (split-path src-file)]) (let-values ([(base name dir?) (split-path src-file)])
(parameterize ([current-load-relative-directory base] (parameterize ([current-load-relative-directory base]
@ -30,4 +35,8 @@
(let ([e (read-syntax src-file in)]) (let ([e (read-syntax src-file in)])
(unless (eof-object? e) (unless (eof-object? e)
(pretty-write (syntax->datum (expand e))) (pretty-write (syntax->datum (expand e)))
(loop)))))))))) (loop))))))))))))
(require (submod "." expand))
(show-program expand)

View File

@ -8,6 +8,7 @@
("decompile" compiler/commands/decompile "decompile bytecode" #f) ("decompile" compiler/commands/decompile "decompile bytecode" #f)
("test" compiler/commands/test "run tests associated with files/directories" 15) ("test" compiler/commands/test "run tests associated with files/directories" 15)
("expand" compiler/commands/expand "macro-expand source" #f) ("expand" compiler/commands/expand "macro-expand source" #f)
("read" compiler/commands/read "read and pretty-print source" #f)
("distribute" compiler/commands/exe-dir "prepare executable(s) in a directory for distribution" #f) ("distribute" compiler/commands/exe-dir "prepare executable(s) in a directory for distribution" #f)
("demodularize" compiler/demodularizer/batch "produce a whole program from a single module" #f))) ("demodularize" compiler/demodularizer/batch "produce a whole program from a single module" #f)))

View File

@ -0,0 +1,4 @@
#lang racket/base
(require (submod "expand.rkt" expand))
(show-program (lambda (e) e))

View File

@ -13,4 +13,4 @@
(define pkg-authors '(mflatt)) (define pkg-authors '(mflatt))
(define version "1.2") (define version "1.3")