added the lang/htdp-langs-save-file-prefix library
to help detect HtDP-lang save files
This commit is contained in:
parent
3f987d76b7
commit
b300bae75c
36
collects/lang/htdp-langs-save-file-prefix.rkt
Normal file
36
collects/lang/htdp-langs-save-file-prefix.rkt
Normal file
|
@ -0,0 +1,36 @@
|
|||
#lang racket/base
|
||||
(require racket/contract
|
||||
racket/port)
|
||||
|
||||
(provide/contract
|
||||
[htdp-save-file-prefix (listof string?)]
|
||||
[htdp-file-prefix? (-> input-port? boolean?)])
|
||||
|
||||
(define htdp-save-file-prefix
|
||||
(list ";; The first three lines of this file were inserted by DrRacket. They record metadata"
|
||||
";; about the language level of this file in a form that our tools can easily process."))
|
||||
|
||||
(define (htdp-file-prefix? port)
|
||||
(define pp (peeking-input-port port))
|
||||
(define ans (htdp-file-prefix/raw? pp))
|
||||
(when ans
|
||||
(htdp-file-prefix/raw? port))
|
||||
ans)
|
||||
|
||||
;; htdp-file-prefix/raw? : input-port? -> boolean
|
||||
;; SIDE EFFECT: consumes input from the port;
|
||||
;; in the case the it returns #t, then it consumes precisely
|
||||
;; the prefix that DrRacket saves
|
||||
;; in the case that it returns #f, it consumes some random amount
|
||||
(define (htdp-file-prefix/raw? port)
|
||||
(let loop ([prefix htdp-save-file-prefix])
|
||||
(cond
|
||||
[(null? prefix)
|
||||
(define l (read-line port 'any))
|
||||
(and (string? l)
|
||||
(regexp-match #rx"^#reader" l))]
|
||||
[else
|
||||
(define l (read-line port 'any))
|
||||
(and (string? l)
|
||||
(equal? l (car prefix))
|
||||
(loop (cdr prefix)))])))
|
|
@ -31,6 +31,8 @@
|
|||
"stepper-language-interface.rkt"
|
||||
"debugger-language-interface.rkt"
|
||||
"run-teaching-program.rkt"
|
||||
"htdp-langs-save-file-prefix.rkt"
|
||||
|
||||
stepper/private/shared
|
||||
|
||||
(only-in test-engine/scheme-gui make-formatter)
|
||||
|
@ -633,8 +635,9 @@
|
|||
(define/override (get-reader-module) reader-module)
|
||||
(define/override (get-metadata modname settings)
|
||||
(string-append
|
||||
";; The first three lines of this file were inserted by DrRacket. They record metadata\n"
|
||||
";; about the language level of this file in a form that our tools can easily process.\n"
|
||||
(apply string-append
|
||||
(map (λ (x) (string-append x "\n"))
|
||||
htdp-save-file-prefix))
|
||||
(format "#reader~s~s\n"
|
||||
reader-module
|
||||
`((modname ,modname)
|
||||
|
@ -1005,7 +1008,9 @@
|
|||
[(exn:srclocs? exn)
|
||||
((exn:srclocs-accessor exn) exn)]
|
||||
[(exn? exn)
|
||||
(let ([cms (continuation-mark-set->list (exn-continuation-marks exn) teaching-languages-continuation-mark-key)])
|
||||
(let ([cms (continuation-mark-set->list
|
||||
(exn-continuation-marks exn)
|
||||
teaching-languages-continuation-mark-key)])
|
||||
(cond
|
||||
((not cms) '())
|
||||
((findf (lambda (mark)
|
||||
|
|
|
@ -804,6 +804,26 @@ Check Syntax is a part of the DrRacket collection, but is implemented via the to
|
|||
The bitmap in the Check Syntax button on the DrRacket frame.
|
||||
}
|
||||
|
||||
@section{Teaching Languages}
|
||||
|
||||
The teaching language are implemented via the tools interface and thus
|
||||
not part of DrRacket proper, but one helper library is documented here.
|
||||
|
||||
@defmodule[lang/htdp-langs-save-file-prefix]
|
||||
|
||||
@defthing[htdp-save-file-prefix (listof string?)]{
|
||||
These strings are used as the prefix in a file saved while using the teaching
|
||||
languages. Each string is on a separate line in the saved file.
|
||||
}
|
||||
@defproc[(htdp-file-prefix? [ip input-port?]) boolean?]{
|
||||
Determines if the contents of @racket[ip] is one of the possible prefixes that
|
||||
DrRacket saves at the beginning of a teaching language file.
|
||||
|
||||
In the case that this function returns @racket[#t], it consumes the entire prefix
|
||||
from @racket[ip] (and discards it). In the case that this function returns
|
||||
@racket[#f], it does not consume anything from @racket[ip].
|
||||
}
|
||||
|
||||
@include-section["get-slash-extend.scrbl"]
|
||||
@include-section["unit.scrbl"]
|
||||
@include-section["language.scrbl"]
|
||||
|
|
Loading…
Reference in New Issue
Block a user