- Scheme 97.6%
- Racket 2.4%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| at-exp | ||
| tests | ||
| .gitignore | ||
| at-exp.ss | ||
| build.ss | ||
| gerbil.pkg | ||
| LICENSE | ||
| LICENSE-MIT.txt | ||
| README.md | ||
Gerbil @-expressions
#lang :at-exp adds Racket-style @ expressions to Gerbil.
Example
#lang :at-exp
(export main)
(def (greet name)
@string-append{Hello, @|name|!})
(def (main)
(displayln (greet "Gerbil")))
Reader API
Use the reader independently of #lang:
(import (prefix-in :at-exp/reader at-))
(at-read (open-input-string "@list[1]{hello}")) ; => (list 1 "hello")
(at-read-inside (open-input-string "Hello @|name|!")) ; => ("Hello " name "!")
| Export | Behavior |
|---|---|
read |
Optional input port; returns one datum or end-of-file. |
read-syntax |
Optional source name, then input port; returns Gerbil runtime syntax (AST) or end-of-file. A false source name uses the port's source. |
read-inside |
Optional input port; reads the entire port as text and returns a list of strings and expressions. |
read-syntax-inside |
Optional source name, then input port; returns a syntax-wrapped text list. Also accepts command-char:. |
make-at-readtable |
Returns a native readtable without changing the current table or any port. |
make-at-reader |
Returns a reader procedure. Accepts the options below plus syntax?: (default #t) and inside?: (default #f); uses the read-syntax calling convention when syntax?: is true, otherwise read. |
use-at-readtable |
Accepts the readtable options below and installs the result as both the current readtable and the current input port's table. Other existing ports retain their tables. |
Omitted ports default to current-input-port; omitted source names default to #f. Inside readers consume through end-of-file, returning an empty list (syntax-wrapped when requested) for empty input.
Customization
Both factories accept these keywords:
readtable:— base table, defaulting tocurrent-readtable;#fselects Gambit's standard table.command-char:— character introducing at-expressions; defaults to#\@.command-readtable:— defaults to the base table. Accepts a table,#ffor Gambit's standard table, or'dynamicfor the current table when reading a command. Applies to the initial command read; nested host expressions use the ambient table. Expression escapes use the command table throughout.datum-readtable:— table for bracketed arguments. Accepts a table,#tfor the constructed at-table (default),#ffor Gambit's standard table, a function transforming the constructed table, or'dynamic. The closing]remains a delimiter regardless of its supplied handler.syntax-post-processor:— procedure receiving and returning Gerbil runtime syntax after each at-form is assembled, before punctuation prefixes are applied. Runs even for datum readers, but not for ordinary host datums or text chunks. Defaults tovalues.
The convenience read, read-syntax, and read-inside use dynamic command and datum tables. read-syntax-inside uses the factory defaults.
Development
gerbil build
gerbil test -v 0 ./tests/reader-test.ss ./tests/api-test.ss
Tested with Gerbil v0.19-dev-38-g98e339be and Gambit v4.9.7-6-g64f4d369.
Attribution and license
The grammar is adapted from Racket's scribble/reader.rkt, by eli and mflatt. Reader test cases come from the Scribble reader tests.
This port uses the upstream MIT license option; the Gerbil implementation and tests are also MIT-licensed. See LICENSE and LICENSE-MIT.txt.