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 --- COPYING | 11 +++++ README.md | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 COPYING create mode 100644 README.md diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..524116c --- /dev/null +++ b/COPYING @@ -0,0 +1,11 @@ +Copyright (C) Case Duckworth under the terms of the + + = = = = = = = = = = = = = GOD WILLING LICENSE v1.0 = = = = = = = = = = = = = = + +Permission to use, distribute, modify, or otherwise interact with this software +is up to the good Lord, who in Their wisdom makes all things possible. I really +recommend you take it up with Them whether you should use this software for any +reason, including incorporating this software into your project. + +This software comes with no warranties from the copyright holder; I cannot speak +for God. 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