Attempting to fix the interaction reader in the REPL
This commit is contained in:
parent
c53891eb13
commit
aa5284534a
|
@ -1,29 +1,10 @@
|
||||||
#lang racket
|
#lang racket
|
||||||
|
|
||||||
(provide get-language-info get-info)
|
(provide get-language-info)
|
||||||
|
|
||||||
(define (get-language-info data)
|
(define (get-language-info data)
|
||||||
(lambda (key default)
|
(lambda (key default)
|
||||||
(displayln (list 'bracket-info/get-language-info key default))
|
|
||||||
(case key
|
(case key
|
||||||
[(configure-runtime)
|
[(configure-runtime)
|
||||||
'(#(bracket/runtime-config configure #f))]
|
'(#(bracket/runtime-config configure #f))]
|
||||||
[(color-lexer)
|
|
||||||
(dynamic-require 'syntax-color/default-lexer
|
|
||||||
'default-lexer)
|
|
||||||
(displayln "HErE")
|
|
||||||
(dynamic-require "parser.rkt"
|
|
||||||
'color-expression-lexer)]
|
|
||||||
[else default])))
|
|
||||||
|
|
||||||
(require racket/runtime-path)
|
|
||||||
(define-runtime-path color-lexer-path "parser.rkt")
|
|
||||||
|
|
||||||
(define (get-info in mod line col pos)
|
|
||||||
(displayln (list 'bracket-info/get-info in mod line col pos))
|
|
||||||
(lambda (key default)
|
|
||||||
(displayln (list 'reader/get-info key default))
|
|
||||||
(case key
|
|
||||||
[(color-lexer)
|
|
||||||
(dynamic-require color-lexer-path 'color-expression-lexer)]
|
|
||||||
[else default])))
|
[else default])))
|
||||||
|
|
|
@ -1185,14 +1185,22 @@
|
||||||
|
|
||||||
(define (Plot f range [options '(List)])
|
(define (Plot f range [options '(List)])
|
||||||
; TODO: Implement options
|
; TODO: Implement options
|
||||||
(displayln (list f range))
|
;(displayln (list f range))
|
||||||
(define y-min -5)
|
(define y-min -5)
|
||||||
(define y-max +5)
|
(define y-max +5)
|
||||||
(define excluded? #f)
|
(define excluded? #f)
|
||||||
|
; TODO: plot2d needs to be extended to multiple functions
|
||||||
|
#;(define fs
|
||||||
|
(match functions
|
||||||
|
[(List: f ...) f]
|
||||||
|
[f (list f)]
|
||||||
|
[else (error 'Plot "TODO")]))
|
||||||
|
(define fs (list f))
|
||||||
(match range
|
(match range
|
||||||
[(List: var x-min x-max)
|
[(List: var x-min x-max)
|
||||||
|
; TODO: Declare var as a local variable ?
|
||||||
(plot2d (if (procedure? f)
|
(plot2d (if (procedure? f)
|
||||||
(λ (x) (displayln x) (f x))
|
(λ (x) (f x))
|
||||||
(λ (x) (N (Substitute f (Equal var x)))))
|
(λ (x) (N (Substitute f (Equal var x)))))
|
||||||
x-min x-max y-min y-max excluded?)]
|
x-min x-max y-min y-max excluded?)]
|
||||||
[else (error)]))
|
[else (error)]))
|
||||||
|
|
|
@ -71,7 +71,8 @@
|
||||||
[string (:: #\" (:* (:~ #\")) #\")]
|
[string (:: #\" (:* (:~ #\")) #\")]
|
||||||
[identifier (:: letter (:* (:or letter digit #\_ #\?)))]
|
[identifier (:: letter (:* (:or letter digit #\_ #\?)))]
|
||||||
[identifier:= (:: letter (:* (:or letter digit #\_ #\?)) ":=")]
|
[identifier:= (:: letter (:* (:or letter digit #\_ #\?)) ":=")]
|
||||||
[identifierOP (:: letter (:* (:or letter digit #\_ #\?)) "(")])
|
[identifierOP (:: letter (:* (:or letter digit #\_ #\?)) "(")]
|
||||||
|
[comment (:: "%" (complement (:: any-string #\newline any-string)) #\newline)])
|
||||||
|
|
||||||
(define (string-drop-right n s)
|
(define (string-drop-right n s)
|
||||||
(substring s 0 (- (string-length s) n)))
|
(substring s 0 (- (string-length s) n)))
|
||||||
|
@ -105,6 +106,8 @@
|
||||||
["<>" 'NOT-EQUAL]
|
["<>" 'NOT-EQUAL]
|
||||||
["≠" 'NOT-EQUAL]
|
["≠" 'NOT-EQUAL]
|
||||||
["define" 'DEFINE]
|
["define" 'DEFINE]
|
||||||
|
[comment
|
||||||
|
(return-without-pos (expression-lexer input-port))]
|
||||||
[string
|
[string
|
||||||
(token-STRING (substring lexeme 1 (- (string-length lexeme) 1)))]
|
(token-STRING (substring lexeme 1 (- (string-length lexeme) 1)))]
|
||||||
; The parser can only look ahead 1 token, so we have 3
|
; The parser can only look ahead 1 token, so we have 3
|
||||||
|
@ -154,6 +157,8 @@
|
||||||
(syn-val lexeme 'no-color #f start-pos end-pos)]
|
(syn-val lexeme 'no-color #f start-pos end-pos)]
|
||||||
["define"
|
["define"
|
||||||
(syn-val lexeme 'constant #f start-pos end-pos)]
|
(syn-val lexeme 'constant #f start-pos end-pos)]
|
||||||
|
[comment
|
||||||
|
(syn-val lexeme 'comment #f start-pos end-pos)]
|
||||||
[string
|
[string
|
||||||
(syn-val lexeme 'string #f start-pos end-pos)]
|
(syn-val lexeme 'string #f start-pos end-pos)]
|
||||||
; The parser can only look ahead 1 token, so we have 3
|
; The parser can only look ahead 1 token, so we have 3
|
||||||
|
@ -165,7 +170,10 @@
|
||||||
[(:+ digit)
|
[(:+ digit)
|
||||||
(syn-val lexeme 'constant #f start-pos end-pos)]
|
(syn-val lexeme 'constant #f start-pos end-pos)]
|
||||||
[(:: (:+ digit) #\. (:* digit))
|
[(:: (:+ digit) #\. (:* digit))
|
||||||
(syn-val lexeme 'constant #f start-pos end-pos)]))
|
(syn-val lexeme 'constant #f start-pos end-pos)]
|
||||||
|
; catch anything else
|
||||||
|
[any-char
|
||||||
|
(syn-val lexeme 'error #f start-pos end-pos)]))
|
||||||
|
|
||||||
|
|
||||||
;; A macro to build the syntax object
|
;; A macro to build the syntax object
|
||||||
|
@ -362,6 +370,7 @@
|
||||||
|
|
||||||
(define (parse-expression src stx ip)
|
(define (parse-expression src stx ip)
|
||||||
(port-count-lines! ip)
|
(port-count-lines! ip)
|
||||||
|
(define out
|
||||||
((expression-parser
|
((expression-parser
|
||||||
(if src src (object-name ip))
|
(if src src (object-name ip))
|
||||||
; If you change any of these values, then
|
; If you change any of these values, then
|
||||||
|
@ -395,3 +404,5 @@
|
||||||
(eq? (position-token-token peek1) 'EOF))
|
(eq? (position-token-token peek1) 'EOF))
|
||||||
(begin0 peek1 (next))
|
(begin0 peek1 (next))
|
||||||
(begin0 peek (next)))))))
|
(begin0 peek (next)))))))
|
||||||
|
(displayln out)
|
||||||
|
out)
|
||||||
|
|
|
@ -57,6 +57,10 @@
|
||||||
(define list-ref List-ref)
|
(define list-ref List-ref)
|
||||||
(define-syntax (define stx)
|
(define-syntax (define stx)
|
||||||
(syntax-case stx () [(_ . more) #'(Define . more)]))
|
(syntax-case stx () [(_ . more) #'(Define . more)]))
|
||||||
|
(require bracket/lang/parser)
|
||||||
|
(current-read-interaction
|
||||||
|
(λ (_ in)
|
||||||
|
(parse-expression 'repl #'repl (open-input-string "1+2"))))
|
||||||
body))
|
body))
|
||||||
'module-language
|
'module-language
|
||||||
'#(bracket/bracket-info get-language-info #f)))))
|
'#(bracket/bracket-info get-language-info #f)))))
|
||||||
|
|
|
@ -16,4 +16,5 @@
|
||||||
[(_ sym ...)
|
[(_ sym ...)
|
||||||
#'(begin (define sym 'sym) ...)]))
|
#'(begin (define sym 'sym) ...)]))
|
||||||
|
|
||||||
|
(require bracket/lang/parser)
|
||||||
|
(provide (all-from-out bracket/lang/parser))
|
||||||
|
|
|
@ -8,5 +8,49 @@
|
||||||
(display v)))
|
(display v)))
|
||||||
|
|
||||||
(define (configure data)
|
(define (configure data)
|
||||||
(show-enabled #t))
|
(show-enabled #t)
|
||||||
|
(current-read-interaction read0))
|
||||||
|
|
||||||
|
(require bracket/lang/reader)
|
||||||
|
|
||||||
|
(define (without-lang-read src in)
|
||||||
|
(parameterize ([read-accept-reader #f]
|
||||||
|
[read-accept-lang #f])
|
||||||
|
(read-one-line src in)))
|
||||||
|
|
||||||
|
; XXX This is almost certainly wrong.
|
||||||
|
(define (read0 src ip)
|
||||||
|
(displayln (list 'read0 src ip))
|
||||||
|
(begin0
|
||||||
|
(without-lang-read src ip)
|
||||||
|
(current-read-interaction read1)))
|
||||||
|
|
||||||
|
(define (read1 src ip)
|
||||||
|
(displayln (list 'read1 src ip))
|
||||||
|
(current-read-interaction read0)
|
||||||
|
eof)
|
||||||
|
|
||||||
|
(define (read2 src ip)
|
||||||
|
(displayln (list 'read2 src ip))
|
||||||
|
(current-read-interaction read0)
|
||||||
|
eof)
|
||||||
|
|
||||||
|
;; at the repl, honu will only read a single line at a time regardless
|
||||||
|
;; of how many expressions it contains
|
||||||
|
(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?
|
||||||
|
eof
|
||||||
|
(read-syntax name (open-input-string one-line))))
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
;;; http://scicomp.stackexchange.com/questions/2377/algorithms-for-adaptive-function-plotting
|
;;; http://scicomp.stackexchange.com/questions/2377/algorithms-for-adaptive-function-plotting
|
||||||
;;; for discussion on adaptive plotting.
|
;;; for discussion on adaptive plotting.
|
||||||
|
|
||||||
(define *debug* #t)
|
(define *debug* #f)
|
||||||
|
|
||||||
; These count functions are used to measure the
|
; These count functions are used to measure the
|
||||||
; number of evaluations of the function to be drawn.
|
; number of evaluations of the function to be drawn.
|
||||||
|
@ -262,4 +262,3 @@
|
||||||
(list
|
(list
|
||||||
(list 'angle: angle)))))
|
(list 'angle: angle)))))
|
||||||
angle]))
|
angle]))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user