funcity-cli
v1.3.0
Published
A functional language interpreter with text processing
Maintainers
Readme
funcity
A functional language interpreter with text processing, easy embeddable!

What is this?
This is a lightweight functional language processor implemented in TypeScript, featuring syntax extensions for text processing. It includes a CLI application and a library package containing only the core engine.
funcity can be considered a type of text template processor. For example, entering code like this:
Today is {{if weather.sunny}}nice{{else}}bad{{end}} weather.Evaluates the value of the weather variable manually bound to the core engine beforehand and generates different text outputs:
Today is bad weather.The if ... elseif ... else ... end statements in the text indicate that the script is being executed.
You can chain additional conditions using elseif.
So, you might ask, what makes this a "Functional language"?
Or how is it different from existing text processors?
Let me show you another equivalent example:
Today is {{cond weather.sunny 'nice' 'bad'}} weather.This is an example of function application,
inserting the result of applying three arguments to the cond function.
The first argument is a conditional expression.
The following code may further interest you:
{{
set printWeather (fun w (cond w.sunny 'nice' 'bad'))
}}
Today is {{printWeather weather}} weather.fundefines an anonymous lambda function.setperforms a mutable binding in the current scope.
Furthermore, you can easily integrate this interpreter into your application:
// Input script
const script = "Today is {{cond weather.sunny ‘nice’ 'bad'}} weather.";
// Run the interpreter
const variables = buildCandidateVariables();
const logs: FunCityLogEntry[] = [];
const text = await runScriptOnceToText(script, {
variables,
logs,
sourceId: 'hello.fc',
});
// Display the result text
console.log(text);In other words, funcity is a processing system that brings the power of functional programming to text template processors, enabling seamless integration into applications!
Features
- A lightweight functional language processor for handling untyped lambda calculus. Adopted the simplest possible syntax. Additionally, selected the syntax extensions that should be prioritized for text processing.
- All function objects are treated as asynchronous functions. You do not need to be aware that they are asynchronous functions when applying them.
- There is also a CLI using the core engine. The CLI has both REPL mode and text processing mode.
- The core engine includes a tokenizer, parser, and reducer (interpreter).
- The core engine library is highly independent, requiring no dependencies on other libraries or packages. It can be easily integrated into your application.
- Parsers and interpreters support both interpreting pure expressions and interpreting full text-processing syntax. This means that even when an interpreter for a purely functional language is required, it is possible to completely ignore the (somewhat incongruous) syntax of text processing.
- Allows pre-binding of useful standard function implementations.
String literals
String literals can be wrapped in single quotes ', double quotes ", or backticks `.
The opening and closing quote must match. Other quote characters can be used inside a string without escaping.
To use the same quote as the opener (or \) inside a string, escape it with a backslash.
You can also embed template blocks with {{...}} inside a quoted string.
Use \{ and \} to output literal braces.
Supported escape sequences:
\nnewline\ttab\rcarriage return\vvertical tab\fform feed\0NUL\'single quote\"double quote- ````` backtick
\{left brace\}right brace\\backslash
Installation (CLI)
TODO:
npm install -D funcity-cliOr, global installation:
npm install -g funcity-cliInstallation (Library)
npm install funcityDocumentation
For detailed documentation and advanced features, please visit our GitHub repository.
Note
funcity was separated from the document site generator mark-the-ripper during its design phase, as it seemed better suited to function as an independent scripting engine.
Therefore, mark-the-ripper can leverage the power of funcity's functional language.
License
Under MIT.
