From d6468b246c4319e215062c5b8627286bc27d556e Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Mon, 28 Aug 2023 23:12:18 -0500 Subject: Add README and COPYING --- README.md | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 README.md (limited to 'README.md') diff --git a/README.md b/README.md new file mode 100644 index 0000000..7307850 --- /dev/null +++ b/README.md @@ -0,0 +1,145 @@ +# Schmaltz +## Render embedded scheme in texts + +Schmaltz is a way to embed scheme code in text files using escape characters. This makes it a decent templating language à la PHP or shell here-documents. + +## Rationale + +Schmaltz was inspired by shell here-documents as well as CHICKEN's extension to scheme string literals, which looks like this: + +```scheme +(define some-string #<#end +Here is a multiline string literal with #(display "embedded") scheme code. +1 + 2 = #(+ 1 2), etc. +end +) +``` + +While this works fine enough, there are a number of limitations preventing it from more thorough use: + +- The above notation only works with string literals. +- The `end` tag must be alone on a line and at the beginning of the line. That, plus the fact that this is a non-standard extension, mean that editors (Emacs) indent that end tag, leading to a mis-parse. Fixing it is possible but fiddly. +- The escape notation isn't extensible. + +Here-documents, in shell and other scripts, are similar in form (I assume that CHICKEN's extension was inspired by this syntax): + +```sh +cat <string . args)` *procedure* +Perform `render`, returning a string with the output. Takes the same arguments as `render`. + +#### `(render-string->string . args)` *procedure* +Perform `render-string`, returning a string with the output. Takes the same arguments as `render-string`. + +#### `render-specials` *parameter* +Special characters to trigger expansion. Every expansion begins with `#`, then another character, then a scheme form. `render-specials` is an alist where CARs is a character literal and CDRs are procedures of one parameter, an input port. + +`render-specials` defaults to + +```scheme +`((#\, . ,(lambda (in) + (eval (read in) (render-environment))))) +``` + +This renders `#,(+ 1 2)` to `3`. + +#### `render-unprintables` *parameter* +String results not to include in the rendered output. For example, `define` might return an unspecified or void value, which when displayed could be `#`. `render-unprintables` is an alist where CARs are strings and CDRs are procedures of one parameter, the current character being processed. The default value of `render-unprintable` is an empty list, but see the section on the `schmaltz` executable for a more useful example. + +#### `(unprintable/skip . _)`, `(unprintable/backtrack char)` *procedures* +Helper procedures for definitions in `render-unprintables`. See the example below for usage ideas. + +`unprintable/skip` skips whatever output is given from the rendered scheme code and prints nothing. `unprintable/backtrack` skips the output, but backtracks to output the character triggering the expansion as well as the preceding `#`. + +#### `render-environment` *parameter* +The environment to evaluate rendered forms in. Defaults to `interaction-environment`. + +#### `environment` *procedure* +Re-exported from `(scheme eval)` for ease of building `render-environment`s. + +### Executable: `schmaltz` + +The `schmaltz` executable reads standard input or files from the command line, rendering and concatenating all of them to standard output, like `cat`. Also like `cat`, if `-` is passed as a parameter to `schmaltz`, it will insert the contents of standard input at that position in the output. + +You can call it as a compiled file or as a script as long as you have `csi` installed. + +By default, `schmaltz` extends the definitions of the following library parameters: + +#### `render-specials` + +Adds `@` for expanding to html via `sxml->html`, e.g. +``` +#@(a (@ (href "https://example.com")) "link") +``` +renders to +``` +link +``` + +It wraps the form in an implicit `quasiquote` so you can include (string) variables, e.g. +``` +#,(define title "Schmaltz!") +#@(h1 ,title) +``` + +#### `render-unprintables` + +```scheme +(list (cons "#" unprintable/skip) + (cons "#!eof" unprintable/backtrack)) +``` + +The above skips printing unspecified values altogether, and the end-of-file marker backtracks to print the (non-)escaping `#` at the input's end. + +### License + +Schmaltz, the library and the program, are licensed under the GOD WILLING LICENSE, version 1.0. See [COPYING][] for details. + +[COPYING]: /schmaltz/tree/COPYING + +### Contributing + +Contributions are welcome! Email me at `git at acdw dot net` or get in touch via whatever other channels you know how with questions or comments or whatever. -- cgit 1.4.1-21-gabe81