pull/10/head
Matthew Butterick 7 years ago
parent d60ef52e2b
commit 5613323df7

@ -8,15 +8,16 @@
([((b-line NUM STMT ...) ...) #'(LINE ...)] ([((b-line NUM STMT ...) ...) #'(LINE ...)]
[(LINE-FUNC ...) (prefix-id "line-" #'(NUM ...))] [(LINE-FUNC ...) (prefix-id "line-" #'(NUM ...))]
[(VAR-ID ...) (find-property 'b-id #'(LINE ...))] [(VAR-ID ...) (find-property 'b-id #'(LINE ...))]
[(REQ-SPEC ...) (find-property 'b-import-name #'(LINE ...))] [(IMPORT-NAME ...)
(find-property 'b-import-name #'(LINE ...))]
[((SHELL-ID SHELL-VAL) ...) [((SHELL-ID SHELL-VAL) ...)
(for/list ([(val idx) (in-indexed (current-command-line-arguments))]) (for/list ([(val idx) (in-indexed (current-command-line-arguments))])
(list (suffix-id #'arg idx #:context caller-stx) val))]) (list (suffix-id #'arg idx #:context caller-stx) val))])
#'(#%module-begin #'(#%module-begin
(module configure-runtime br (module configure-runtime br
(require basic-demo-3/runtime) (require basic-demo-3/runtime)
(configure-this!)) (configure-this!))
(require REQ-SPEC) ... (require IMPORT-NAME) ...
(define VAR-ID 0) ... (define VAR-ID 0) ...
(provide VAR-ID ...) (provide VAR-ID ...)
(set! SHELL-ID SHELL-VAL) ... (set! SHELL-ID SHELL-VAL) ...
@ -32,6 +33,6 @@
(remove-duplicates (remove-duplicates
(for/list ([stx (in-list (stx-flatten line-stxs))] (for/list ([stx (in-list (stx-flatten line-stxs))]
#:when (syntax-property stx which)) #:when (syntax-property stx which))
stx) stx)
#:key syntax->datum))) #:key syntax->datum)))

@ -31,9 +31,13 @@
(define-macro (b-func FUNC-ID ARG ...) (define-macro (b-func FUNC-ID ARG ...)
#'(if (procedure? FUNC-ID) #'(if (procedure? FUNC-ID)
(let ([result (FUNC-ID ARG ...)]) (let ([result (FUNC-ID ARG ...)])
(if (boolean? result) (cond
(if result 1 0) [(number? result) (b-expr result)]
result)) [(string? result) result]
[(boolean? result) (if result 1 0)]
[else
(raise-line-error
(format "unknown data type: ~v" result))]))
(raise-line-error (raise-line-error
(format "expected ~a to be a function, got ~v" (format "expected ~a to be a function, got ~v"
'FUNC-ID FUNC-ID)))) 'FUNC-ID FUNC-ID))))

@ -22,7 +22,7 @@ b-for : /"for" b-id /"=" b-expr /"to" b-expr [/"step" b-expr]
b-next : /"next" b-id b-next : /"next" b-id
b-def : /"def" b-id /"(" ID [/"," ID]* /")" /"=" b-expr b-def : /"def" b-id /"(" ID [/"," ID]* /")" /"=" b-expr
b-import : /"import" b-import-name b-import : /"import" b-import-name
@b-import-name : (ID | STRING) @b-import-name : ID | STRING
b-expr : b-or-expr b-expr : b-or-expr
b-or-expr : [b-or-expr "or"] b-and-expr b-or-expr : [b-or-expr "or"] b-and-expr
b-and-expr : [b-and-expr "and"] b-not-expr b-and-expr : [b-and-expr "and"] b-not-expr
@ -35,4 +35,4 @@ b-expt : [b-expt ("^")] b-value
@b-value : b-number | b-id | /"(" b-expr /")" | b-func @b-value : b-number | b-id | /"(" b-expr /")" | b-func
b-func : ID /"(" b-expr [/"," b-expr]* /")" b-func : ID /"(" b-expr [/"," b-expr]* /")"
@b-number : INTEGER | DECIMAL @b-number : INTEGER | DECIMAL
b-repl : (b-statement | b-expr) (/":" [b-repl])* b-repl : (b-statement | b-expr) (/":" [b-repl])*

Loading…
Cancel
Save