Next: , Previous: , Up: iklib reader   [Index]


6.13.4 Reader annotations

The Scheme source code reader allows us to annotate source code read from a textual input with informations about the position of an expression in the input. For example:

(import (vicare))

(define port  (open-string-input-port "(list var)"))
(define datum (get-annotated-datum port))
(pretty-print datum)
-| #[reader-annotation
        expression=#<omitted>
        stripped=(list var)
        textual-position=#[record: &source-position
                              port-id="*string-input-port*"
                              byte=0
                              character=0
                              line=1
                              column=1]]

The following bindings are exported by the library (vicare).

Function: get-annotated-datum port

Like get-datum, but rather than returning a datum return a hierarchy of <reader-annotation> objects with the same hierarchy of the datum and embedding the datum itself.

Function: reader-annotation? obj

Return #t if obj is an <reader-annotation> object, else return #f.

Function: reader-annotation-expression ann

Return a list, vector, identifier, what–have–you that may contain further annotations.

Function: reader-annotation-stripped ann

Return the same symbolic expression of the expression field with no annotations.

Function: reader-annotation-textual-position ann

Return a condition object of type &source-position representing the position of the expression in the source code.

Function: reader-annotation-source ann

Return a pair whose car is the port identifier and whose cdr is the offset of the first character of the source expression in the textual input.