[honu] read and parse a line at the repl

This commit is contained in:
Jon Rafkind 2011-09-15 16:01:41 -06:00
parent 219516b321
commit 808c2bdf27
2 changed files with 25 additions and 3 deletions

View File

@ -10,6 +10,8 @@
(for-syntax racket/base
syntax/parse))
(require "private/debug.rkt")
(define-tokens honu-tokens (number identifier string))
(define-empty-tokens honu-empty-tokens
@ -152,7 +154,7 @@
(define (read-tokens port)
(let loop ([tokens '()])
(define next (honu-lexer port))
;; (printf "next ~a\n" next)
;; (debug "next token ~a\n" next)
(match next
[(struct* position-token ([token (? token-eof?)] [start-pos start] [end-pos end]))
; (printf "done lexing ~a\n" tokens)

View File

@ -1,7 +1,27 @@
#lang racket/base
(require "read.rkt")
(require "read.rkt"
"private/honu-typed-scheme.rkt"
racket/port)
(define (read-one-line name input)
(define quit? #f)
(define one-line
(with-output-to-string
(lambda ()
(let loop ()
(define next (read-char input))
(when (eof-object? next)
(set! quit? #t))
(when (not (or (eof-object? next)
(char=? next #\newline)))
(display next)
(loop))))))
(if quit?
;; this isn't right, somehow communicate to the system that the repl should close
#'(exit)
(honu-read-syntax name (open-input-string one-line))))
(provide configure)
(define (configure . args)
(current-read-interaction honu-read-syntax))
(current-read-interaction read-one-line))