6 releases
0.2.4 | Nov 6, 2021 |
---|---|
0.2.3 | Nov 4, 2021 |
0.1.0 | Nov 2, 2021 |
#26 in #gate
28 downloads per month
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 derivesSerialize
andDeserialize
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
~2.5–3.5MB
~66K SLoC