A functional language interpreter with text processing
npm install funcity-cliA functional language interpreter with text processing, easy embeddable!


---
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:
``funcity`
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.elseif
You can chain additional conditions using .
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:
`funcity`
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:
`funcity`
{{
set printWeather (fun w (cond w.sunny 'nice' 'bad'))
}}
Today is {{printWeather weather}} weather.
- fun defines an anonymous lambda function.set
- performs a mutable binding in the current scope.
Furthermore, you can easily integrate this interpreter into your application:
`typescript
// 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);
// 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!
- 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 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.
Supported escape sequences:
- \n newline\t
- tab\r
- carriage return\v
- vertical tab\f
- form feed\0
- NUL\'
- single quote\"
- double quote
- \` backtick\\
- backslash
---
TODO:
`bash`
npm install -D funcity-cli
Or, global installation:
`bash`
npm install -g funcity-cli
`bash``
npm install funcity
---
For detailed documentation and advanced features, please visit our GitHub repository.
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.
Under MIT.