6 releases

0.2.4 Nov 6, 2021
0.2.3 Nov 4, 2021
0.1.0 Nov 2, 2021

#1996 in Parser implementations

28 downloads per month

GPL-3.0 license

19KB
237 lines

positron - parse and execute boolean expressions

Hosted version (Website) here Code: DevHyperCoder/positron-web

Hosted version (API) here Code: DevHyperCoder/positron-api

Installation

Cargo.toml

[dependencies]
positron={version = "x.x.x", features= ["json"]}
  • json feature derives Serialize and Deserialize

Check crates.io for the latest version of positron

LICENSE

positron is licensed under the GNU General Public License 3. Our copy of GPL-3 can be found here


lib.rs:

positron - parse and execute boolean expressions

Examples

Basic Or Gate

use std::collections::HashMap;
use positron::{circuit::Circuit,gate::Gate};

// a + b
let gate =  Gate::Or(vec![Gate::Value("a".to_string()),Gate::Value("b".to_string())]);

let mut data = HashMap::new();
data.insert("a".to_string(),true);
data.insert("b".to_string(),true);

let circuit = Circuit {
    gate,
    data
};

assert_eq!(circuit.execute().unwrap(),true)

Parsing example

use std::{collections::HashMap,str::FromStr};
use positron::{circuit::Circuit,parser::Parsed};

let input = "(a+b).(a.b)";

let parsed = Parsed::from_str(input).unwrap();

assert!(parsed.variables.contains("a"));
assert!(parsed.variables.contains("b"));

let mut data = HashMap::new();
data.insert("a".to_string(),true);
data.insert("b".to_string(),true);

let circuit = Circuit {
    gate:parsed.root_gate,
    data
};

assert_eq!(circuit.execute().unwrap(),true)

Dependencies

~3.5MB
~69K SLoC