Like Legos for building domain-specific languages (DSLs).
For example, suppose we want an HTML DSL. We can implement one that uses CoffeeScript and VDOM like this:
import loaderfallbackbufferincludefilterssandboxengine from "biscotti"import HTML from "panda-vdom"render = do ->globals = Objectassign requireHTMLenginesandbox: sandbox globalsloadercoffeescript:index: trueextensions: ".vhtml"do fallbackinclude isBuffered: falsebufferfiltersstringexport render as default
You could then call the resulting
# will load ./html/index.vhtmlrender path: "./vhtml"
You probably don't want to use this directly. Instead, check out the various engines we've written that use Biscotti:
engine function takes an array containing an initial definition of the engine and a list of mixins that will add capabilities to it. Typically, that initial definition defines the
sandbox property, whose value must be a sandbox, which is a V8 VM. It returns a render function that takes an options object with either a
path (and option
encoding) or a
loader- A dictionary of file types and descriptions for loading a file given a path. The
indexproperty determines whether to try adding
indexto the path. The
extensionsproperty is a list of extensions to try.
fallback- Defines the assumptions to make if no path is given. The default is to assume a CoffeeScript file. You can pass an options object with a
languageproperty to provide a different fallback.
include— Adds an
includemethod to the sandbox's globals. This allows a given file to include another file using a relative path. Effectively allows for the equivalent of partials, or partial templates.
buffer— Adds functions to the sandbox's globals allowing included files to add values to a buffer. This way you can return values from the files your engine processes. The
getfunction returns the buffer, in case you want to manipulate it from within a file. The
appendfunction adds to it. The
$$function is equivalent to
$modifies another function so that it's return value is appended to the buffer.
filters— Includes various post-processing functions for transforming the buffer into a usable return value.
filters.stringconverts each element into a string and appends it to single return string.
embedded— Allows you to process arbitrary text, embedding code between delimiters. You must provide an options object with the delimiters as
close(which will default to
run method. See the code for the
embedded mixins for examples.