Mastersign.Expressions 0.6.0

A parser and compiler for a small EXCEL like expression language inside your .NET applications.

Install-Package Mastersign.Expressions -Version 0.6.0
dotnet add package Mastersign.Expressions --version 0.6.0
<PackageReference Include="Mastersign.Expressions" Version="0.6.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Mastersign.Expressions --version 0.6.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Mastersign.Expressions, 0.6.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Mastersign.Expressions as a Cake Addin
#addin nuget:?package=Mastersign.Expressions&version=0.6.0

// Install Mastersign.Expressions as a Cake Tool
#tool nuget:?package=Mastersign.Expressions&version=0.6.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Mastersign.Expressions

A parser and compiler for a small EXCEL like expression language inside your .NET applications.

Mastersign.Expression is a small DSL (domain specific language) – a little like the MS EXCEL formular language. Its purpose is to provide a simple expression language with a set of predefined functions for math and string manipulation. Expressions are parsed via a parser, based on the Sprache parser framework, and compiled via System.Linq.Expressions into a lambda delegate, and can therefore, used repeatedly with acceptable performance.

Features

Mastersign.Expression supports numeric, boolean and string literals, operators for numeric operations, string concatenation, logical combination and comparison. Grouping is done with parantheses. Function calls have a C-style-syntax. Functions, variables, constants, and parameters are provided via an evaluation context, which can be easily extended by the developer.

It comes with a set of predefined functions for math, string manipulation and regular expressions.

The evaluation context can be configured to ignore the case of operator keywords, literal keywords, variables, parameters, and function names. The quote style for strings can be configured too.

Expression Examples

  • 1 + 2
  • pi * (100f + 32.0/a)
  • "\tName: " & name
  • "result = " & (sin(pi * 2.0 + x) / 10)

Simple Usage Scenario

using System;
using Mastersign.Expressions;

static class Program
{
    static void Main()
    {
        // create the evaluation context for the expression
        var context = new EvaluationContext();
        // load the default packages with functions and constants (math, string, ...)
        context.LoadAllPackages();
        // add a custom variable
        context.SetVariable("x", 4);
        // add a custom function
        context.AddFunction("neg", (Func<double, double>)(v => -v));
        // set parameter list
        context.SetParameters(new ParameterInfo("a", typeof(int)));
        // compile the expression into a lamda delegate
        var fun = context.CompileExpression<int, double>("sin(pi * neg(10 + x)) + a");
        // call the delegate and write the result to the console
        Console.WriteLine(fun(50));
    }
}

License

This project is published under the MIT license.

Copyright © by Tobias Kiertscher dev@mastersign.de

Mastersign.Expressions

A parser and compiler for a small EXCEL like expression language inside your .NET applications.

Mastersign.Expression is a small DSL (domain specific language) – a little like the MS EXCEL formular language. Its purpose is to provide a simple expression language with a set of predefined functions for math and string manipulation. Expressions are parsed via a parser, based on the Sprache parser framework, and compiled via System.Linq.Expressions into a lambda delegate, and can therefore, used repeatedly with acceptable performance.

Features

Mastersign.Expression supports numeric, boolean and string literals, operators for numeric operations, string concatenation, logical combination and comparison. Grouping is done with parantheses. Function calls have a C-style-syntax. Functions, variables, constants, and parameters are provided via an evaluation context, which can be easily extended by the developer.

It comes with a set of predefined functions for math, string manipulation and regular expressions.

The evaluation context can be configured to ignore the case of operator keywords, literal keywords, variables, parameters, and function names. The quote style for strings can be configured too.

Expression Examples

  • 1 + 2
  • pi * (100f + 32.0/a)
  • "\tName: " & name
  • "result = " & (sin(pi * 2.0 + x) / 10)

Simple Usage Scenario

using System;
using Mastersign.Expressions;

static class Program
{
    static void Main()
    {
        // create the evaluation context for the expression
        var context = new EvaluationContext();
        // load the default packages with functions and constants (math, string, ...)
        context.LoadAllPackages();
        // add a custom variable
        context.SetVariable("x", 4);
        // add a custom function
        context.AddFunction("neg", (Func<double, double>)(v => -v));
        // set parameter list
        context.SetParameters(new ParameterInfo("a", typeof(int)));
        // compile the expression into a lamda delegate
        var fun = context.CompileExpression<int, double>("sin(pi * neg(10 + x)) + a");
        // call the delegate and write the result to the console
        Console.WriteLine(fun(50));
    }
}

License

This project is published under the MIT license.

Copyright © by Tobias Kiertscher dev@mastersign.de

  • .NETFramework 4.6.1

  • .NETStandard 2.0

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
0.6.0 39 6/10/2021
0.5.2 85 5/31/2021
0.5.1 73 5/25/2021
0.5.0 90 5/23/2021
0.4.3 945 12/10/2014