preserves-tool
This commit is contained in:
parent
f09067d719
commit
a817fed40d
|
@ -0,0 +1,3 @@
|
|||
#lang setup/infotab
|
||||
(define racket-launcher-names '("preserves-tool"))
|
||||
(define racket-launcher-libraries '("tool.rkt"))
|
|
@ -0,0 +1,38 @@
|
|||
#lang racket/base
|
||||
|
||||
(require "main.rkt")
|
||||
(require racket/match)
|
||||
(require racket/port)
|
||||
|
||||
(module+ main
|
||||
(require racket/cmdline)
|
||||
(define input-format 'text)
|
||||
(define output-format 'binary)
|
||||
(define indent? #t)
|
||||
(define annotations? #t)
|
||||
(command-line #:once-each
|
||||
[("--ib" "--input-binary") "Set binary input mode"
|
||||
(set! input-format 'binary)]
|
||||
[("--it" "--input-text") "Set text input mode"
|
||||
(set! input-format 'text)]
|
||||
[("--ob" "--output-binary") "Set binary output mode"
|
||||
(set! output-format 'binary)]
|
||||
[("--ot" "--output-text") "Set text output mode"
|
||||
(set! output-format 'text)]
|
||||
["--indent" "Enable indent for text output"
|
||||
(set! indent? #t)]
|
||||
["--no-indent" "Disable indent for text output"
|
||||
(set! indent? #f)]
|
||||
["--annotations" "Output annotations"
|
||||
(set! annotations? #t)]
|
||||
["--no-annotations" "Strip annotations"
|
||||
(set! annotations? #f)])
|
||||
|
||||
(define v ((if annotations? values strip-annotations)
|
||||
(match input-format
|
||||
['text (read-preserve-syntax #:source "<stdin>")]
|
||||
['binary (decode-syntax (port->bytes))])))
|
||||
(void (match output-format
|
||||
['text (write-preserve v #:indent indent?)]
|
||||
['binary (write-bytes (encode v))]))
|
||||
(flush-output))
|
Loading…
Reference in New Issue