diff --git a/beautiful-racket-demo/basic-demo-3/misc.rkt b/beautiful-racket-demo/basic-demo-3/misc.rkt index 3712bf4..b05275d 100644 --- a/beautiful-racket-demo/basic-demo-3/misc.rkt +++ b/beautiful-racket-demo/basic-demo-3/misc.rkt @@ -18,9 +18,12 @@ (define-macro (b-export NAME) #'(void)) -(define-macro (b-repl . ARGS) - (with-pattern ([STMTS (pattern-case-filter #'ARGS - [(b-expr . EXPR-ARGS) - #'(b-print (b-expr . EXPR-ARGS))] - [OTHER-STMT #'OTHER-STMT])]) - #'(begin . STMTS))) \ No newline at end of file +(define-macro (b-repl . REPL-INPUTS) + (with-pattern ([INPUTS (pattern-case-filter #'REPL-INPUTS + [(b-expr . EXPR-ARGS) + #'(b-print (b-expr . EXPR-ARGS))] + [(b-print . PRINT-ARGS) + #'(b-print . PRINT-ARGS)] + [OTHER + #'(error 'invalid-repl-input)])]) + #'(begin . INPUTS))) \ No newline at end of file diff --git a/beautiful-racket-demo/basic-demo-3/parser.rkt b/beautiful-racket-demo/basic-demo-3/parser.rkt index 990ee9f..4ae34ba 100644 --- a/beautiful-racket-demo/basic-demo-3/parser.rkt +++ b/beautiful-racket-demo/basic-demo-3/parser.rkt @@ -37,4 +37,4 @@ b-expt : [b-expt ("^")] b-value @b-value : b-number | b-id | /"(" b-expr /")" | b-func b-func : (ID | RACKET-ID) /"(" b-expr [/"," b-expr]* /")" @b-number : INTEGER | DECIMAL -b-repl : (b-statement | b-expr) (/":" [b-repl])* +b-repl : (b-statement | b-expr) (/":" [@b-repl])* diff --git a/beautiful-racket-demo/basic-demo-3/setup.rkt b/beautiful-racket-demo/basic-demo-3/setup.rkt index 8907934..65427fa 100644 --- a/beautiful-racket-demo/basic-demo-3/setup.rkt +++ b/beautiful-racket-demo/basic-demo-3/setup.rkt @@ -5,17 +5,15 @@ (define basic-output-port (make-parameter (open-output-nowhere))) -(define (do-setup! [where #f]) - (basic-output-port (current-output-port)) - #;(current-read-interaction read-one-line)) - -(define repl-parser (make-rule-parser b-repl)) +(define repl-parse (make-rule-parser b-repl)) -(define (read-one-line path port) +(define (read-one-line origin port) (define one-line (read-line port)) (if (eof-object? one-line) eof - (repl-parser + (repl-parse (make-tokenizer (open-input-string one-line))))) - +(define (do-setup! [where #f]) + (basic-output-port (current-output-port)) + (current-read-interaction read-one-line)) \ No newline at end of file