summaryrefslogtreecommitdiff
path: root/module/system/base/syntax.scm
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2008-11-11 22:52:24 +0100
committerAndy Wingo <wingo@pobox.com>2008-11-11 22:52:24 +0100
commitf38624b349c29e3e5b3e6518959f33803af45558 (patch)
tree3c7cc7f464ed1696964ebdb07d6d613399ff31a2 /module/system/base/syntax.scm
parentf698d111b4e6cc763c01e157c291358152a18ec3 (diff)
downloadguile-f38624b349c29e3e5b3e6518959f33803af45558.tar.gz
add parsers and unparser for ghil; ,language ghil works now
* module/system/repl/common.scm (repl-print): Slightly refine the meaning of "language-printer": a language printer prints an expression of a language, not the result of evaluation. `write' prints values. * module/language/ghil/spec.scm (ghil): Define a language printer, and a translator for turning s-expressions (not scheme, mind you) into GHIL. * module/language/scheme/translate.scm (quote, quasiquote): Add some #:keyword action, so that we can (quote #:keywords). * module/system/base/language.scm (<language>): * module/system/base/compile.scm (read-file-in): Don't require that a language have a read-file; instead error when read-file is called. (compile-passes, compile-in): Refactor to call a helper method to turn the language + set of options into a set of compiler passes. * module/system/base/syntax.scm (define-type): Allow the type to be a list, with the car being the name and the cdr being keyword options. Interpret #:printer as a printer, and pass it down to... (define-record): Here. * module/system/il/ghil.scm (print-ghil, <ghil>): New printer for GHIL, yay! (parse-ghil, unparse-ghil): New lovely functions. Will document them in the manual.
Diffstat (limited to 'module/system/base/syntax.scm')
-rw-r--r--module/system/base/syntax.scm12
1 files changed, 9 insertions, 3 deletions
diff --git a/module/system/base/syntax.scm b/module/system/base/syntax.scm
index 8b0ba5969..0e02ba06a 100644
--- a/module/system/base/syntax.scm
+++ b/module/system/base/syntax.scm
@@ -29,7 +29,12 @@
;;;
(define-macro (define-type name . rest)
- `(begin ,@(map (lambda (def) `(define-record ,def)) rest)))
+ (let ((name (if (pair? name) (car name) name))
+ (opts (if (pair? name) (cdr name) '())))
+ (let ((printer (kw-arg-ref opts #:printer)))
+ `(begin ,@(map (lambda (def) `(define-record ,def
+ ,@(if printer (list printer) '())))
+ rest)))))
;;;
@@ -39,13 +44,14 @@
(define (symbol-trim-both sym pred)
(string->symbol (string-trim-both (symbol->string sym) pred)))
-(define-macro (define-record def)
+(define-macro (define-record def . printer)
(let* ((name (car def)) (slots (cdr def))
(slot-names (map (lambda (slot) (if (pair? slot) (car slot) slot))
slots))
(stem (symbol-trim-both name (list->char-set '(#\< #\>)))))
`(begin
- (define ,name (make-record-type ,(symbol->string name) ',slot-names))
+ (define ,name (make-record-type ,(symbol->string name) ',slot-names
+ ,@printer))
(define ,(symbol-append 'make- stem)
(let ((slots (list ,@(map (lambda (slot)
(if (pair? slot)