#logical #expressions #condition #list #parser #error #logical-expression

logical-expressions

A library for working with logical expressions

3 releases

new 0.1.2 Mar 2, 2025
0.1.1 Feb 22, 2025
0.1.0 Feb 22, 2025

#413 in Concurrency

Download history 211/week @ 2025-02-19 190/week @ 2025-02-26

401 downloads per month
Used in multilinear-parser

MIT/Apache

13KB
201 lines

Logical Expressions

A library for working with logical expressions in Rust.

Features

  • Representing logical expressions using the LogicalExpression enum (supports And lists, Or lists and single conditions)
  • Support for custom types to represent conditions
  • Parsing logical expressions from strings with proper error handling
  • Expanding logical expressions into a list of lists, where the inner lists represent AND conditions and the outer lists represent OR conditions (DNF)

Quickstart

Here's an example of how to use the library:

use logical_expressions::LogicalExpression;

let expression: LogicalExpression<String> = LogicalExpression::parse("a & (b | c)").unwrap();
let expanded = expression.expand();
println!("{expanded:?}");

This will output:

[["a", "b"], ["a", "c"]]

Documentation

For more detailed information and examples, please refer to the API documentation.


lib.rs:

This crate provides a library for working with logical expressions.

It defines the LogicalExpression enum, which represents a logical expression with conditions combined using AND and OR operators. The library also provides functions for parsing logical expressions from strings and expanding them into a list of lists, where the inner lists represent the AND conditions and the outer lists represent the OR conditions.

Dependencies

~230–670KB
~16K SLoC