Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 3.0.0 #131

Merged
merged 49 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
132aa2b
With checksum
FlorianRappl Jan 7, 2024
18f3d8a
Updated version
FlorianRappl Jan 7, 2024
76e3ed4
Changed name to MagesSetup.exe
FlorianRappl Jan 7, 2024
902c855
Implemented wrapper type for future #64
FlorianRappl Mar 4, 2024
f28c992
Improved codebase
FlorianRappl Mar 5, 2024
48c0dfc
Updated logo
FlorianRappl Mar 5, 2024
88b3266
Updated to .NET Standard 2.1
FlorianRappl Mar 5, 2024
38c6991
Optimized 0-args case
FlorianRappl Mar 5, 2024
5b4a876
Draft for JSX syntax
FlorianRappl Mar 6, 2024
3d97e79
Improved jsx expressions
FlorianRappl Mar 6, 2024
fca8b40
Added jsx factory
FlorianRappl Mar 6, 2024
c62ca91
Improved JSX parsing
FlorianRappl Mar 6, 2024
2abf1a4
Normalize JSX identifiers
FlorianRappl Mar 7, 2024
f89163e
Updated changelog
FlorianRappl Mar 7, 2024
1bb2382
Changed to install .NET 6
FlorianRappl Mar 8, 2024
b9d8c33
Multi .NET
FlorianRappl Mar 8, 2024
dbb5abb
Updated constraint def
FlorianRappl Mar 8, 2024
3318cb2
add: added a randi() function for generating a random integer value
GhostVaibhav Jun 28, 2024
ca0e442
del: deleted an unused header
GhostVaibhav Jun 28, 2024
f61bf19
refactor: refactored the documentation to include the new function
GhostVaibhav Jun 28, 2024
084c78a
refactor: added currying and checks for arguments
GhostVaibhav Jun 28, 2024
0381d18
Merge pull request #124 from GhostVaibhav/ghostvaibhav/123
FlorianRappl Jun 28, 2024
6df92f0
Working on build improvements
FlorianRappl Jul 28, 2024
37f1060
Try to update certificates for mono
FlorianRappl Jul 28, 2024
273f36b
Try with a local file
FlorianRappl Jul 28, 2024
ec0a0ce
Disable parallel processing on Linux
FlorianRappl Jul 28, 2024
0a52ffa
Improved engine running in REPL
FlorianRappl Aug 7, 2024
6ecbdc8
Updated changelog
FlorianRappl Aug 7, 2024
2658609
Improved detection of overflow in NumberTokenizer
Sep 5, 2024
411a63d
Extracted helper methods with tests
Sep 5, 2024
9517a0f
Merge branch 'devel' into issues/#125-overflow-2
FlorianRappl Sep 5, 2024
0865ef2
Update NumberTokenizer.cs
FlorianRappl Sep 5, 2024
a055a82
Merge pull request #126 from josefblaha/issues/#125-overflow-2
FlorianRappl Sep 5, 2024
bea4bcd
Fixed hex num representation #128
FlorianRappl Dec 21, 2024
8e84466
Implemented placeholder parameter #129
FlorianRappl Dec 21, 2024
81c5d3c
Implemented meta data #49
FlorianRappl Dec 21, 2024
7a6f4de
added metadata
FlorianRappl Dec 21, 2024
c6d4da3
Updated to use is / is not for null comparisons
FlorianRappl Dec 21, 2024
259ef3c
Improved HTML stringification of JSX
FlorianRappl Dec 24, 2024
d138654
Include .NET 9
FlorianRappl Dec 24, 2024
562b381
Updated readme
FlorianRappl Dec 24, 2024
6c8ae12
Prepare further JSX test
FlorianRappl Dec 24, 2024
598d755
Fixed issue with functions as props
FlorianRappl Dec 24, 2024
5f4e89b
Fixed target framework for Linux
FlorianRappl Dec 24, 2024
d1eef84
Updated readme
FlorianRappl Dec 24, 2024
70d6652
Improved docs
FlorianRappl Dec 24, 2024
7754ffa
Updated functions
FlorianRappl Dec 24, 2024
168ef03
Removed 5.x
FlorianRappl Dec 24, 2024
682b68a
Keep .NET 5 for the Linux build
FlorianRappl Dec 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ jobs:

- uses: actions/setup-dotnet@v3
with:
dotnet-version: '5.0.x'
dotnet-version: |
5.0.x
6.0.x
7.0.x
8.0.x
9.0.x

- name: Build
run: ./build.sh
Expand All @@ -29,7 +34,12 @@ jobs:

- uses: actions/setup-dotnet@v3
with:
dotnet-version: '5.0.x'
dotnet-version: |
5.0.x
6.0.x
7.0.x
8.0.x
9.0.x

- name: Build
run: |
Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# 3.0.0

- Fixed potential misinterpretation of fractions in hex numbers (#128)
- Fixed usage of capital `X` or `B` for hex or binary representations
- Fixed bug in JSON representation using trailing comma
- Fixed arithmetic overflow detection for number edge cases (#125) by @josefblaha
- Improved GC allocations (#81)
- Added wrapping of `Task` in `Future` (#64)
- Added octal representation (e.g., `0o123`) for numbers
- Added insertion points (`_`) to function calls (#129)
- Added JSX syntax (#120)
- Added default `jsx` and `html` function (#120)
- Added events to `Engine` to handle uncaught errors (#121)
- Added object metadata retrievable via `type` (#49)
- Added a `randi` function to generate random integers (#124) by @GhostVaibhav

# 2.0.3

- Include checksum in chocolatey package

# 2.0.2

- Fixed vulnerability using outdated version of `System.Drawing.Common` for plugins
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016-2024 Florian Rappl
Copyright (c) 2016 - 2025 Florian Rappl

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
70 changes: 54 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,76 @@
![MAGES Logo](https://raw.githubusercontent.com/FlorianRappl/Mages/main/logo.png)
![MAGES Logo](./logo.png)

# MAGES

[![GitHub CI](https://github.com/FlorianRappl/Mages/actions/workflows/ci.yml/badge.svg)](https://github.com/FlorianRappl/Mages/actions/workflows/ci.yml)
[![NuGet](https://img.shields.io/nuget/v/MAGES.svg?style=flat-square)](https://www.nuget.org/packages/Mages/)
[![Issues](https://img.shields.io/github/issues/FlorianRappl/MAGES.svg?style=flat-square)](https://github.com/FlorianRappl/Mages/issues)
[![GitHub CI](https://github.com/FlorianRappl/Mages/actions/workflows/ci.yml/badge.svg)](https://github.com/FlorianRappl/Mages/actions/workflows/ci.yml) [![NuGet](https://img.shields.io/nuget/v/MAGES.svg?style=flat-square)](https://www.nuget.org/packages/Mages/) [![Issues](https://img.shields.io/github/issues/FlorianRappl/MAGES.svg?style=flat-square)](https://github.com/FlorianRappl/Mages/issues)

## Mages: Another Generalized Expression Simplifier

MAGES is the official successor to [YAMP](https://github.com/FlorianRappl/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 is used in [Microsoft's PowerToys](https://github.com/microsoft/PowerToys).
Among other applications, MAGES has been used in [Microsoft's PowerToys](https://github.com/microsoft/PowerToys).

### Current Status

MAGES was just updated (v2.0.0) with support for complex numbers. Also, the build target and runtime has been updated to make use of modern possibilities.
**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`:

```plain
<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`:

```plain
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:

```plain
var f = (x, y, z) => x + 2 * y + 3 * z;
5 | f(1, _, 2)
// 17, by computing 1 + 2 * 5 + 3 * 2
```

### Previous Status

**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](http://www.codeproject.com/Articles/1108939/MAGES-Ultimate-Scripting-for-NET) about the library (also containing some background and performance comparisons) is also available.

### Installation

MAGES itself does not have any dependencies, however, the tests are dependent on NUnit and the benchmarks use BenchmarkDotNet. Usually, MAGES should be installed via the NuGet package source. If this does not work for you, then clone the source and build MAGES yourself. Make sure that all unit tests pass.

The whole library was designed to be consumed from .NET 3.5 (or higher) applications. This means it is (amongst others) compatible with Unity / Mono 2.6. The NuGet package is available via [the official package feed](https://www.nuget.org/packages/MAGES).
The whole library was designed to be consumed from .NET Core 3.0 (or higher) / .NET 5.0 (or higher) applications. This means it is (amongst others) compatible with Unity 2021.2 or Mono 6.4. The NuGet package is available via [the official package feed](https://www.nuget.org/packages/MAGES).

### Get Me Started!

Expand Down Expand Up @@ -100,12 +146,4 @@ Thanks for all the support and trust in the project!

## License

The MIT License (MIT)

Copyright (c) 2016-2024 Florian Rappl

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This code is released using the MIT license. For more information see the [LICENSE file](./LICENSE).
Binary file added assets/logo-128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo-256x256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo-460x460.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo-64x64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo-96x96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 12 additions & 13 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ if (isRunningOnGitHubActions)
}
}

var buildDir = Directory("./src/Mages.Core/bin") + Directory(configuration) + Directory("netstandard2.0");
var replDir = Directory("./src/Mages.Repl/bin") + Directory(configuration) + Directory("netcoreapp3.1");
var installerDir = Directory("./src/Mages.Repl.Installer/bin") + Directory(configuration) + Directory("net45");
var buildDir = Directory("./src/Mages.Core/bin") + Directory(configuration) + Directory("netstandard2.1");
var replDir = Directory("./src/Mages.Repl/bin") + Directory(configuration) + Directory("net60");
var installerDir = Directory("./src/Mages.Repl.Installer/bin") + Directory(configuration) + Directory("net50");
var buildResultDir = Directory("./bin") + Directory(version);
var nugetRoot = buildResultDir + Directory("nuget");
var chocolateyRoot = buildResultDir + Directory("chocolatey");
Expand Down Expand Up @@ -71,7 +71,10 @@ Task("Restore-Packages")
.IsDependentOn("Clean")
.Does(() =>
{
NuGetRestore("./src/Mages.sln");
NuGetRestore("./src/Mages.sln", new NuGetRestoreSettings
{
DisableParallelProcessing = isRunningOnUnix && isRunningOnGitHubActions,
});
});

Task("Update-Assembly-Version")
Expand Down Expand Up @@ -123,7 +126,7 @@ Task("Copy-Files")
.IsDependentOn("Build")
.Does(() =>
{
var nugetBin = nugetRoot + Directory("lib") + Directory("netstandard2.0");
var nugetBin = nugetRoot + Directory("lib") + Directory("netstandard2.1");
CreateDirectory(nugetBin);
CreateDirectory(squirrelBin);
CreateDirectory(releaseDir);
Expand Down Expand Up @@ -204,10 +207,11 @@ Task("Create-Squirrel-Package")
});

Task("Create-Chocolatey-Package")
.IsDependentOn("Copy-Files")
.IsDependentOn("Create-Squirrel-Package")
.WithCriteria(() => isRunningOnWindows)
.Does(() => {
var content = String.Format("$packageName = 'Mages'{1}$installerType = 'exe'{1}$url32 = 'https://github.com/FlorianRappl/Mages/releases/download/v{0}/Mages.exe'{1}$silentArgs = ''{1}{1}Install-ChocolateyPackage \"$packageName\" \"$installerType\" \"$silentArgs\" \"$url32\"", version, Environment.NewLine);
var checksum = CalculateFileHash(releaseDir.Path.FullPath + "/MagesSetup.exe", HashAlgorithm.SHA256).ToHex();
var content = String.Format("$packageName = 'Mages'{1}$installerType = 'exe'{1}$url32 = 'https://github.com/FlorianRappl/Mages/releases/download/v{0}/MagesSetup.exe'{1}$silentArgs = ''{1}$checksum32 = '{2}'{1}{1}Install-ChocolateyPackage -PackageName \"$packageName\" -FileType \"$installerType\" -SilentArgs \"$silentArgs\" -Url \"$url32\" -Checksum \"$checksum32\" -ChecksumType \"sha256\"", version, Environment.NewLine, checksum);
var nuspec = chocolateyRoot + File("Mages.nuspec");
var toolsDirectory = chocolateyRoot + Directory("tools");
var scriptFile = toolsDirectory + File("chocolateyInstall.ps1");
Expand Down Expand Up @@ -267,7 +271,7 @@ Task("Publish-GitHub-Release")
TargetCommitish = isPublish ? "main" : "devel"
}).Result;

var target = nugetRoot + Directory("lib") + Directory("netstandard2.0");
var target = nugetRoot + Directory("lib") + Directory("netstandard2.1");
var libPath = target + File("Mages.Core.dll");
var releaseFiles = GetFiles(releaseDir.Path.FullPath + "/*");

Expand All @@ -280,11 +284,6 @@ Task("Publish-GitHub-Release")
{
var name = System.IO.Path.GetFileName(file.FullPath);

if (name.Equals("Setup.exe"))
{
name = "Mages.exe";
}

using (var fileStream = System.IO.File.OpenRead(file.FullPath))
{
newRelease.UploadAsset(release, new ReleaseAssetUpload(name, "application/x-msdownload", fileStream, null)).Wait();
Expand Down
35 changes: 31 additions & 4 deletions doc/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@ Works without any arguments.
x = rand() // any number between 0 and 1
```

### Generate Single Random Integer

Works with one argument.

```
x = randi(5) // any integer between 0 and 5
```

### Generate Random Vector

Works with one argument.
Expand All @@ -284,9 +292,9 @@ M = rand(3, 2) // a 3x2 matrix with numbers between 0 and 1
Works with one argument, which could be anything.

```
x = type(true) // "Boolean"
x = type([1, 2, 3]) // "Matrix"
x = type("foo") // "String"
x = type(true).name // "Boolean"
x = type([1, 2, 3]).name // "Matrix"
x = type("foo").name // "String"
```

### Checking Types
Expand Down Expand Up @@ -397,4 +405,23 @@ Shuffles the arguments of a given function (last argument) by the order of the g
fab = (a, b) => a * b - b;
fba = shuffle("b", "a", fab);
fab(1, 2) - fba(1, 2) // -1
```
```

## Stringification

### JSON

Transforms the value into a valid JSON string. Does not stringify functions.

```
json(new { a: 42, b: "foo" }) // { "a": 42, "b": "foo" }
```

### HTML

Transforms the value into a valid JSON string. Does only stringify valid JSX objects, numbers, and strings. Strings are automatically HTML-encoded.

```
"foo<b>ho</b>" | html // foo&lt;b&gt;ho&lt;/b&gt;
<div class={"foo" + "bar"}>Hi</div> | html // <div class="foobar">Hi</div>
```
2 changes: 1 addition & 1 deletion doc/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ On starting the REPL we see the following:
\/ \/ \/ \/ \/

(c) Florian Rappl, 2024
Version 2.0.2
Version 2.0.3
Running on Microsoft Windows NT 6.2.9200.0

For help type 'help()'.
Expand Down
42 changes: 41 additions & 1 deletion doc/language.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,44 @@ cos(2.5) == cos()()(2.5)

are therefore equal. In the previous example two calls without any arguments result in the function itself, such that the last call is operating on `cos` itself. Auto currying is applied to any standard function, custom created function (lambda expression), and wrapped .NET function.

Auto currying allows to use functions to create functions without much ceremony and plays great together with the pipe operator, which expects functions requiring only a single argument on the right side.
Auto currying allows to use functions to create functions without much ceremony and plays great together with the pipe operator, which expects functions requiring only a single argument on the right side.

### Placeholders

Calling a function with parameters supplied as `_` will result in a new function taking the number of used placeholders as arguments.

Example:

```
var f = (x, y, z) => x + 2 * y + 3 * z
```

Classically, this could be called like `f(x, y, z)` or with auto-currying like `f(x, y)` or even `f(x)`. But what if we would like to have a function `g(y) = f(x, y, z)`? We would need to define this alias quite explicitly:

```
var g = (y) => f(1, y, 3)
```

With the placeholder parameter it can be written such as:

```
var g = f(1, _, 3)
```

The big advantage of this is that we get a simple way to pipe things:

```
4 | f(1, _, 3)
```

## JSX

XML-like syntax is an integrated part of MAGES. Expressions such as

```
<div><p style="font-style:italic">hello</p><p>there<br/>said Obi.</p></div>
```

can just be used and will call the JSX-factory function `jsx`, which (by default, i.e., if not specified otherwise) will result in JSX-objects. These are just ordinary objects, but with a defined set of keys such as `props` and `children`.

You can either use the JSX output to work on the JSX-objects, or you can pass it to a helper function such as `html`. This works well with JSX-objects and transforms it into a valid HTML string - also taking care of things such as HTML escaping.
4 changes: 3 additions & 1 deletion doc/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ A number is the usual suspect:
```
binary_character ::= '0' | '1'
hex_character ::= digit | [a - f] | [A - F]
octal_character ::= [0 - 7]
binary ::= '0' ('b' | 'B') binary_character+
hex ::= '0' ('x' | 'X') hex_character+
octal ::= '0' ('o' | 'O') octal_character+
float ::= digit+ (. digit* (('e' | 'E') sign? digit+)?)?
number ::= float | binary | hex
number ::= float | binary | hex | octal
```

Boolean primitive values are given by keywords:
Expand Down
Binary file modified logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Product>Mages</Product>
<Authors>Florian Rappl</Authors>
<Company>smapiot</Company>
<Version>2.0.2</Version>
<Version>3.0.0</Version>
<Copyright>Copyright (c) 2024, Florian Rappl</Copyright>
<PackageLicenseUrl>https://github.com/FlorianRappl/MAGES/blob/main/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/FlorianRappl/MAGES/</PackageProjectUrl>
Expand Down
3 changes: 2 additions & 1 deletion src/Mages.Chocolatey.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
<authors>Florian Rappl</authors>
<owners>FlorianRappl</owners>
<licenseUrl>https://github.com/FlorianRappl/Mages/blob/main/LICENSE</licenseUrl>
<projectUrl>https://github.com/FlorianRappl/Mages</projectUrl>
<projectUrl>https://github.com/FlorianRappl/Mages/blob/main/README.md</projectUrl>
<iconUrl>https://raw.github.com/FlorianRappl/Mages/main/logo.png</iconUrl>
<releaseNotes>https://github.com/FlorianRappl/Mages/blob/main/CHANGELOG.md</releaseNotes>
<projectSourceUrl>https://github.com/FlorianRappl/Mages</projectSourceUrl>
<packageSourceUrl>https://github.com/FlorianRappl/Mages</packageSourceUrl>
<docsUrl>https://github.com/FlorianRappl/Mages/tree/main/doc</docsUrl>
<bugTrackerUrl>https://github.com/FlorianRappl/Mages/issues</bugTrackerUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
Expand Down
Loading
Loading