Chicken » Module (chicken read-syntax)

## Module (chicken read-syntax)

This module provides procedures which can be used to extend the reader with custom read syntax.

### define-reader-ctor

define-reader-ctor SYMBOL PROCprocedure

  Define new read-time constructor for `#,` read syntax. For further information, see the documentation for SRFI-10.

### set-read-syntax!

set-read-syntax! CHAR-OR-SYMBOL PROCprocedure

  When the reader encounters the non-whitespace character `CHAR` while reading an expression from a given port, then the procedure PROC will be called with that port as its argument. The procedure should return a value that will be returned to the reader:

       ; A simple RGB color syntax:

       (set-read-syntax! #\%
         (lambda (port)
           (apply vector
             (map (cut string->number <> 16)
      	    (string-chop (read-string 6 port) 2) ) ) ) )

       (with-input-from-string "(1 2 %f0f0f0 3)" read)
       ; ==> (1 2 #(240 240 240) 3)

  If CHAR-OR-SYMBOL is a symbol, then a so-called read-mark handler is defined. In that case the handler procedure will be called when a character-sequence of the form `#!SYMBOL` is encountered.

  You can undo special handling of read-syntax by passing `#f` as the second argument (if the syntax was previously defined via `set-read-syntax!`).

  As a special case, your handler can return zero values, via `(values)`. This causes the reader to completely ignore whatever input you've read, rather than returning some possibly unspecified value. This can be useful in macro context, reading comments, conditional compilation, and so forth. Available in CHICKEN 4.6.6 and later.

  Note that all of CHICKEN's special non-standard read-syntax is handled directly by the reader. To disable built-in read-syntax, define a handler that triggers an error (for example).

### set-sharp-read-syntax!

set-sharp-read-syntax! CHAR-OR-SYMBOL PROCprocedure

  Similar to `set-read-syntax!`, but allows defining new `#<CHAR> ...` reader syntax. If the first argument is a symbol, then this procedure is equivalent to `set-read-syntax!`.

  PROC may be `#f` to disable previously defined "sharp" read syntax.

### set-parameterized-read-syntax!

set-parameterized-read-syntax! CHAR-OR-SYMBOL PROCprocedure

  Similar to `set-sharp-read-syntax!`, but intended for defining reader syntax of the form `#<NUMBER><CHAR> ...`. The handler procedure PROC will be called with two arguments: the input port and the number preceding the dispatching character. If the first argument is a symbol, then this procedure is equivalent to `set-read-syntax!`.

  PROC may be `#f` to disable previously defined parameterized read syntax.

### copy-read-table

copy-read-table READ-TABLEprocedure

  Returns a copy of the given read-table. You can access the currently active read-table with `(current-read-table)`. This procedure can be useful to restore an old read-table after temporarily introducing new read syntax.

### current-read-table

current-read-tableparameter

  A read-table object that holds read-procedures for special non-standard read-syntax (see `set-read-syntax!` for more information).

Previous: Module (chicken random)

Next: Module (chicken repl)