Project homepage: mages.anglevisions.com
MAGES is the official successor to YAMP. It is a very simple, yet powerful, expression parser and interpreter. You can use MAGES to include a sophisticated, easy to customize, and lightweight scripting engine to your application.
Among other applications, MAGES has been used in Microsoft's PowerToys.
2024:
MAGES was just updated (v3.0.0) with object metadata, direct list support, and JSX syntax.
JSX as you know it - stringified via html:
<div class={"hello" + "," + "there"}><h1>Hi</h1><p>World.</p></div> | html
// result: <div class="hello,there"><h1>Hi</h1><p>World.</p></div>
Object metadata reflected via type:
new { a: "foo", b: 42 } | type | json
// {
// "name": "Object",
// "create": "[Function]",
// "keys": {
// "0": "a",
// "1": "b"
// }
// }
((x, y, z) => x + y + z) | type | json
// {
// "name": "Function",
// "create": "[Function]",
// "parameters": {
// "0": "x",
// "1": "y",
// "2": "z"
// }
// }
Placeholders for calling functions / specifying what should be curry'ed:
var f = (x, y, z) => x + 2 * y + 3 * z;
5 | f(1, _, 2)
// 17, by computing 1 + 2 * 5 + 3 * 2
2023:
MAGES was updated (v2.0.0) with support for complex numbers. Also, the build target and runtime has been updated to make use of modern possibilities.
2018:
The first stable version has been released. The current version 1.6.0 contains an improved REPL. The library contains everything to perform lightweight scripting operations in C#. A CodeProject article about the library (also containing some background and performance comparisons) is also available.
MAGES itself does not have any external runtime dependencies. It is available as a standard .NET library targeting .NET Standard 2.1 and can be consumed from .NET applications, Unity, and other compatible platforms.
Install via the .NET CLI:
dotnet add package MagesOr via the NuGet Package Manager:
Install-Package MagesThe NuGet package is available on NuGet.org.
MAGES provides a global CLI compiler and interactive REPL via the Mages.Compiler .NET tool (targeting .NET 10).
Install it globally using:
dotnet tool install --global Mages.CompilerOnce installed, you can launch the interactive REPL or execute script files with the mages command:
# Start interactive REPL
mages
# Run a MAGES script file
mages path/to/script.mages
# Update to the latest version
dotnet tool update --global Mages.CompilerRich editor support for MAGES with Language Server Protocol (LSP), syntax highlighting, diagnostics, hover documentation, signature help, and IntelliSense is available for Visual Studio Code via the vscode-mages extension in src/vscode-mages.
In the most simple case you are creating a new engine to hold a global scope (for variables and functions) and launch the interpretation.
var engine = new Mages.Core.Engine();
var result = engine.Interpret("sin(2) * cos(pi / 4)"); // 0.642970376623918You can also go-ahead and make reusable blocks from snippets.
var expOne = engine.Compile("exp(1)");
var result = expOne(); // 2.71828182845905Or you can interact with elements created by MAGES.
var func = engine.Interpret("(x, y) => x * y + 3 * sqrt(x)") as Mages.Core.Function;
var result = func.Invoke(new Object[] { 4.0, 3.0 }); // 18.0Or even simpler (details are explained in the getting started document):
var func = engine.Interpret("(x, y) => x * y + 3 * sqrt(x)") as Mages.Core.Function;
var result = func.Call(4, 3); // 18.0These are just some of the more basic examples. More information can be found in the documentation.
The documentation is given in form of Markdown documents being placed in the doc folder of this repository. The following links are worth checking out:
If anything is missing, unclear, or wrong then either submit a PR or file an issue. See the following section on contributions for more information.
Contributions in form of feature implementations or bug fixes are highly welcome, but need to be performed in an organized and consistent way. The contribution guidelines should be read before starting any work.
Contributions may also be taken in form of bug reports and feature requests. Long live open-source development!
The rules of semver are our bread and butter. In short this means:
- MAJOR versions at maintainers' discretion following significant changes to the codebase (e.g., breaking API changes)
- MINOR versions for backwards-compatible enhancements (e.g., performance improvements, additional extensions)
- PATCH versions for backwards-compatible bug fixes (e.g., specification compliance bugs, support issues)
Hence: Do not expect any breaking changes within the same major version.
The following companies sponsored part of the development of MAGES.
Thanks for all the support and trust in the project!
This code is released using the MIT license. For more information see the LICENSE file.
