LfrlAnvil.Computable.Expressions 0.1.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package LfrlAnvil.Computable.Expressions --version 0.1.1                
NuGet\Install-Package LfrlAnvil.Computable.Expressions -Version 0.1.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LfrlAnvil.Computable.Expressions" Version="0.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LfrlAnvil.Computable.Expressions --version 0.1.1                
#r "nuget: LfrlAnvil.Computable.Expressions, 0.1.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install LfrlAnvil.Computable.Expressions as a Cake Addin
#addin nuget:?package=LfrlAnvil.Computable.Expressions&version=0.1.1

// Install LfrlAnvil.Computable.Expressions as a Cake Tool
#tool nuget:?package=LfrlAnvil.Computable.Expressions&version=0.1.1                

(root) NuGet Badge

LfrlAnvil.Computable.Expressions

This project contains a parser of string expressions that can be compiled to invocable delegates.

Documentation

Technical documentation can be found here.

Examples

Following contains an example of a parser configuration, as well as creation, compilation and invocation of a delegate:

// creates a builder of a minimal parser capable of supporting most arithmetic and logical operators
// and branching functions, like 'if' and 'switch'
// in addition, it will try to parse all constant numbers as 32-bit signed integers
// instead of the default decimal type
var builder = new ParsedExpressionFactoryBuilder()
    .AddGenericArithmeticOperators()
    .AddGenericBitwiseOperators()
    .AddGenericLogicalOperators()
    .AddBooleanLogicalOperators()
    .AddStringArithmeticOperators()
    .AddBranchingVariadicFunctions()
    .SetNumberParserProvider( p => ParsedExpressionNumberParser.CreateDefaultInt32( p.Configuration ) );

// builds an expression parser
var parser = builder.Build();

// string expression to parse, that contains two external arguments: 'a' and 'b'
var input =
    """
    let x = (a + 1).ToString();
    let y = if(x.Length > 1, b * 2, b * 4).ToString();
    y + x + y;
    """;

// creates a parsed expression from the given string input
var expression = parser.Create<int, string>( input );

// compiles the expression to an invocable delegate
var func = expression.Compile();

// invokes the delegate with 'a' = 42 and 'b' = 31,
// which should return '624362'
var result = func.Invoke( 42, 31 );
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.2.1 113 6/16/2024
0.2.0 90 6/16/2024
0.1.1 92 5/29/2024
0.1.0 97 5/26/2024