PolyglotCSharp 1.0.2

dotnet add package PolyglotCSharp --version 1.0.2
                    
NuGet\Install-Package PolyglotCSharp -Version 1.0.2
                    
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="PolyglotCSharp" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PolyglotCSharp" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="PolyglotCSharp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PolyglotCSharp --version 1.0.2
                    
#r "nuget: PolyglotCSharp, 1.0.2"
                    
#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.
#:package PolyglotCSharp@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PolyglotCSharp&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=PolyglotCSharp&version=1.0.2
                    
Install as a Cake Tool

Polyglot

An cross-platform, cross-language interpreter of simple, parametrizable logical expression in Reversed Polish Notation.

The motivation

Currently, there really isn't a way to share a simple piece of parametrized logic between frontend, and backend code. Let's say, for instance, that you wanted to display data in a list, with actions that the users can perform on a row. The user may, or may not have permissions to perform an action and we want to grey-out the unavailable actions. One way to solve that problem, would be to contaminate the list data, with names of actions that the user can take, for each row, which were evaluated on the backend. But what if generating the definition of that list, is expensive? How do you validate that the user trying to perform an action on a row, has permission to do so?

One way to solve that problem, would be to attach a logical expression, to the action definition, that would determine whether the user had permissions to execute it. If that expression would be executable by both frontend and backend, frontend could use it to grey-out unavailable actions and backend could use it to validate permissions (given that the expression was cryptographically signed). Thats where polyglot comes in.

The package

This package provides a compiled interpreter of a simple language to express logical expressions, that can accept parameters. It is compiled to a native binary, as well as to webassemby, with bindings for several programming languages (currently: Rust, C# and javascript).

Javascript instructions

To use this package in your javascript project, install it with your favorite package manager npm install @maslox303/polyglot_js. You then have to initialize the module, before using the evaluate function. Example:

import init from '@maslox303/polyglot_js'
import {evaulate} from '@maslox303/polyglot_js'

await init();
console.log(evaluate('(= @a 1)', {a: 1}));

Language

The language interpreted by polyglot is essentially constructed from boolean operators and comparison operators written in a Lisp-like Reversed Polish Notation For example: (= @a 1) means 'parameter with name a is equal to 1'. Comparison expressions can be also combined with boolean operators. For example (& (= @a 1) (= @b 'abc')) means 'parameter a is equal to 1 and parameter b is equal to string "abc"'. Boolean operators accepts any number of subexpressions as argumetnts. For example (| (= @a 1) (= @b 'abc') (! @c g)).

Boolean operators:

  • & and
  • | or

Comparison operators

  • = equal
  • ! not equal
  • > first operand greater than second (only numeric values)
  • ] first operand greater or equal than second (only numeric values)
  • < first operand less than second (only numeric values)
  • [ first operand less or equal than second (only numeric values)

Numeric values can be specified in ' or as bare strings: 123 equivalent to '123'.

Parameters can be accessed using @

Interpreter implementation file, contains unit tests with additional expression examples.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

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
1.0.2 143 10/16/2024
1.0.1 204 2/29/2024
1.0.0 93 2/27/2024
0.1.0 101 2/23/2024