9 WXME Decoding
procedure
(is-wxme-stream? in) → boolean?
in : input-port?
procedure
(wxme-port->text-port in [close?]) → input-port?
in : input-port? close? : any/c = #t
Unlike wxme-port->port, this function may take liberties with the snips in a way that would render a valid program invalid. For example, if the wxme stream in contains a bitmap image, then there may not be a reasonable text-only version of it and thus wxme-port->port might turn what would have been a valid Racket program into text that is a syntax error, Nevertheless, the result may still be useful for human readers or approximate program-processing tools that run only in a GUI-less context.
If close? is true, then closing the result port closes the original port.
See Snip Class Mapping for information about the kinds of non-text content that can be read.
procedure
(wxme-port->port in [close? snip-filter]) → input-port?
in : input-port? close? : any/c = #t snip-filter : (any/c . -> . any/c) = (lambda (x) x)
These special values produced by the new input port are different than the ones produced by reading a file into an editor<%> object. Instead of instances of the snip%, the special values are typically simple extensions of object%. See Snip Class Mapping for information about the kinds of non-text content that can be read.
If close? is true, then closing the result port close the original port.
The snip-filter procedure is applied to any special value generated for the stream, and its result is used as an alternate special value.
If a special value (possibly produced by the filter procedure) is an object implementing the readable<%> interface, then the object’s read-special method is called to produce the special value.
procedure
(extract-used-classes in) →
(listof string?) (listof string?) in : input-port?
procedure
(register-lib-mapping! str mod-path) → void?
str : string? mod-path : (cons/c 'lib (listof string?))
procedure
(string->lib-path str gui?)
→
(or/c (cons/c 'lib (listof string?)) #f) str : string? gui? : any/c
parameter
(unknown-extensions-skip-enabled skip?) → void? skip? : any/c
parameter
(broken-wxme-big-endian? big?) → void? big? : any/c
procedure
in : input-port?
If racket/gui/base is available (as determined by gui-available?), then open-input-text-editor is used. Otherwise, wxme-port->port is used.
procedure
(wxme-read-syntax source-v in) → (or/c syntax? eof-object?)
source-v : any/c in : input-port?
If racket/gui/base is available (as determined by gui-available?), then open-input-text-editor is used. Otherwise, wxme-port->port is used.
|
method
(send a-snip-reader read-header version stream) → any version : exact-nonnegative-integer? stream : (is-a?/c stream<%>) Called at most once per WXME stream to initialize the data type’s stream-specific information. This method usually does nothing.
method
(send a-snip-reader read-snip text-only? version stream) →
(if text-only? bytes? any/c) text-only? : boolean? version : exact-nonnegative-integer? stream : (is-a?/c stream<%>) Called when an instance of the data type is encountered in the stream. This method reads the data and returns either bytes to be returned as part of the decoded stream or any other kind of value to be returned as a “special” value from the decoded stream. The result value can optionally be an object that implements readable<%>.The text-only? argument is #f when wxme-port->text-port was called and #t when wxme-port->port was called.
|
method
(send a-readable read-special source line column position) → any/c source : any/c line : (or/c exact-nonnegative-integer? #f) column : (or/c exact-nonnegative-integer? #f) position : (or/c exact-nonnegative-integer? #f) Like read-special, but for non-graphical mode. When a value implements this interface, its read-special method is called with source-location information to obtain the “special” result from the WXME-decoding port.
|
method
(send a-stream read-integer what)
→
(or/c (integer-in (- (expt 2 31)) (expt 2 31)) (and/c real? inexact?)) what : any/c Like get-exact, returns either an exact integer or an inexact real.The what field describes what is being read, for error-message purposes, in case the stream does not continue with an integer.
method
(send a-stream read-fixed-integer what) → exact-integer?
what : any/c Reads an exact integer that has a fixed size in the stream, analogous to get-fixed.The what argument is as for read-integer.
Reads an inexact real number, analogous to get-inexact.The what argument is as for read-integer.
method
(send a-stream read-raw-bytes what) → bytes?
what : any/c Reads raw bytes, analogous to get-unterminated-bytes.The what argument is as for read-integer.
method
(send a-stream read-bytes what) → bytes?
what : any/c Reads raw bytes, analogous to get-bytes.The what argument is as for read-integer.
method
(send a-stream read-editor what) → input-port?
what : any/c Reads a nested editor, producing a new input port to extract the editor’s content.The what argument is as for read-integer.
procedure
(read-snip-from-port name who stream) → bytes?
name : string? who : any/c stream : (is-a?/c stream<%>)
9.1 Snip Class Mapping
When graphical data is marshaled to the WXME format, it is associated with a snip-class name to be matched with an implementation at load time. See also Snip Classes.
Ideally, the snip-class name is generated as
(format "~s" (list '(lib string ...) '(lib string ...)))
where each element of the formated list is a quoted module path (see module-path?). The strings must contain only alpha-numeric ASCII characters, plus ., _, -, and spaces, and they must not be "." or "..".
In that case, the first quoted module path is used for loading WXME files in graphical mode; the corresponding module must provide snip-class object that implements the snip-class% class. The second quoted module path is used by the wxme library for converting WXME streams without graphical support; the corresponding module must provide a reader object that implements the snip-reader<%> interface. Naturally, the snip-class% instance and snip-reader<%> instance are expected to parse the same format, but generate different results suitable for the different contexts (i.e., graphical or not).
If a snip-class name is generated as
then graphical mode uses the sole module path, and wxme needs a compatibility mapping. Install one with register-lib-mapping!.
If a snip-class name has neither of the above formats, then graphical mode can use the data only if a snip class is registered for the name, or if it the name of one of the built-in classes: "wxtext", "wxtab", "wximage", or "wxmedia" (for nested editors). The wxme library needs a compatibility mapping installed with register-lib-mapping! if it is not one of the built-in classes.
Several compatibility mappings are installed automatically for the wxme library. They correspond to popular graphical elements supported by various versions of DrRacket, including comment boxes, fractions, XML boxes, Racket boxes, text boxes, and images generated by the htdp/image teachpack (or, more generally, from mrlib/cache-image-snip), and test-case boxes.
For a port created by wxme-port->port, nested editors are represented by instances of the editor% class provided by the wxme/editor library. This class provides a single method, get-content-port, which returns a port for the editor’s content. Images are represented as instances of the image% class provided by the wxme/image library.
Comment boxes are represented as instances of a class that extends editor% to implement readable<%>; see wxme/comment. The read form produces a special comment (created by make-special-comment), so that the comment box disappears when read is used to read the stream; the special-comment content is the readable instance. XML, Racket, and text boxes similarly produce instances of editor% and readable<%> that expand in the usual way; see wxme/xml, wxme/scheme, and wxme/text. Images from the htdp/image teachpack are packaged as instances of cache-image% from the wxme/cache-image library. Test-case boxes are packaged as instances of test-case% from the wxme/test-case library.
9.1.1 Nested Editors
(require wxme/editor) | package: wxme-lib |
method
(send an-editor get-content-port) → input-port?
Returns a port (like the one from wxme-port->port) for the editor’s content.
9.1.2 Images
(require wxme/image) | package: wxme-lib |
|
superclass: image-snip% |
Returns bytes for a PNG, XBM,or XPM file for the image.
method
(send an-image get-w) → (or/c exact-nonnegative-integer? -1)
Returns the display width of the image, which may differ from the width of the actual image specified as data or by a filename; -1 means that the image data’s width should be used.
method
(send an-image get-h) → (or/c exact-nonnegative-integer? -1)
Returns the display height of the image, which may differ from the height of the actual image specified as data or by a filename; -1 means that the image data’s height should be used.
method
(send an-image get-dx) → exact-integer?
Returns an offset into the actual image to be used as the left of the display image.
method
(send an-image get-dy) → exact-integer?
Returns an offset into the actual image to be used as the top of the display image.
9.2 DrRacket Comment Boxes
(require wxme/comment) | package: wxme-lib |
value
| ||
superclass: editor% | ||
|
No data is available.
method
(send a-comment-editor read-special source line column position) → any/c source : any/c line : (or/c exact-nonnegative-integer? #f) column : (or/c exact-nonnegative-integer? #f) position : (or/c exact-nonnegative-integer? #f) Generates a special comment using make-special-comment. The special comment contains the comment text.
9.3 DrRacket XML Boxes
(require wxme/xml) | package: wxme-lib |
value
| ||
superclass: editor% | ||
|
Returns #t if whitespace is elimited from the contained XML literal, #f otherwise.
method
(send a-xml-editor read-special source line column position) → any/c source : any/c line : (or/c exact-nonnegative-integer? #f) column : (or/c exact-nonnegative-integer? #f) position : (or/c exact-nonnegative-integer? #f) Generates a quasiquote S-expression that enclosed the XML, with unquote and unquote-splicing escapes for nested Racket boxes.
9.4 DrRacket Racket Boxes
(require wxme/scheme) | package: wxme-lib |
value
| ||
superclass: editor% | ||
|
Returns #t if the box corresponds to a splicing unquote, #f for a non-splicing unquote.
method
(send a-scheme-editor read-special source line column position) → any/c source : any/c line : (or/c exact-nonnegative-integer? #f) column : (or/c exact-nonnegative-integer? #f) position : (or/c exact-nonnegative-integer? #f) Generates an S-expression for the code in the box.
9.5 DrRacket Text Boxes
(require wxme/text) | package: wxme-lib |
value
| ||
superclass: editor% | ||
|
No data is available.
method
(send a-text-editor read-special source line column position) → any/c source : any/c line : (or/c exact-nonnegative-integer? #f) column : (or/c exact-nonnegative-integer? #f) position : (or/c exact-nonnegative-integer? #f) Generates a string containing the text.
9.6 DrRacket Fractions
(require wxme/number) | package: wxme-lib |
value
9.7 DrRacket Teachpack Images
(require wxme/cache-image) | package: wxme-lib |
value
|
superclass: object% |
Returns a vector of bytes representing the content of the image.
method
(send a-cache-image get-width) → exact-nonnegative-integer?
Returns the width of the image.
method
(send a-cache-image get-height) → exact-nonnegative-integer?
Returns the height of the image.
method
(send a-cache-image get-pin-x) → exact-integer?
Returns an offset across into the image for the pinhole.
method
(send a-cache-image get-pin-y) → exact-integer?
Returns an offset down into the image for the pinhole.
9.8 DrRacket Test-Case Boxes
(require wxme/test-case) | package: wxme-lib |
value
|
superclass: object% |
method
(send a-test-case get-comment) → (or/c #f input-port?)
Returns a port for the comment field, if any.
method
(send a-test-case get-test) → input-port?
Returns a port for the “test” field.
method
(send a-test-case get-expected) → input-port?
Returns a port for the “expected” field.
method
(send a-test-case get-should-raise) → (or/c #f input-port?)
Returns a port for the “should raise” field, if any.
method
(send a-test-case get-error-message) → (or/c #f input-port?)
Returns a port for the “error msg” field, if any.
method
(send a-test-case get-enabled?) → boolean?
Returns #t if the test is enabled.
method
(send a-test-case get-collapsed?) → boolean?
Returns #t if the test is collapsed.
method
(send a-test-case get-error-box?) → boolean?
Returns #t if the test is for an exception.