-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dev-symbolic-domains
- Loading branch information
Showing
10 changed files
with
1,258 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"editor.formatOnSave": true, | ||
"files.associations": { | ||
"*.sbml": "xml" | ||
}, | ||
"[xml]": { | ||
"editor.defaultFormatter": "redhat.vscode-xml", | ||
"editor.formatOnSave": true | ||
}, | ||
"[rust]": { | ||
"editor.defaultFormatter": "rust-lang.rust-analyzer", | ||
"editor.formatOnSave": true | ||
}, | ||
"rust-analyzer.checkOnSave": true, | ||
"rust-analyzer.check.overrideCommand": [ | ||
"cargo", | ||
"clippy", | ||
"--workspace", | ||
"--message-format", | ||
"json" | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
use std::io::BufRead; | ||
use xml::reader::EventReader; | ||
|
||
use super::sbml_xml_rs::Proposition; | ||
|
||
pub enum Expression { | ||
Terminal(Proposition), | ||
// Internal(Box<Expression>), | ||
Not(Box<Expression>), | ||
And(Box<Expression>, Box<Expression>), | ||
Or(Box<Expression>, Box<Expression>), | ||
Xor(Box<Expression>, Box<Expression>), | ||
Implies(Box<Expression>, Box<Expression>), | ||
} | ||
|
||
impl Expression { | ||
pub fn dflt() -> Self { | ||
unimplemented!("default expression") | ||
} | ||
|
||
// todo consider iterative approach instead of recursive? | ||
pub fn try_from_xml<T: BufRead>( | ||
xml: &mut EventReader<T>, | ||
) -> Result<Self, Box<dyn std::error::Error>> { | ||
loop { | ||
match xml.next() { | ||
Ok(xml::reader::XmlEvent::StartElement { name, .. }) => { | ||
match name.local_name.as_str() { | ||
"not" => unimplemented!(), | ||
"and" => unimplemented!(), | ||
"or" => unimplemented!(), | ||
"xor" => unimplemented!(), | ||
"implies" => unimplemented!(), | ||
must_be_cmp_op => { | ||
// todo oh fck already consumed the operator; need to pass it to parse_apply_element | ||
let proposition = super::parse_apply_element(xml)?; // pass the op somehow | ||
drain(xml, "apply")?; // clean the xml iterator; will be used | ||
return Ok(Expression::Terminal(proposition)); | ||
} | ||
} | ||
} | ||
Ok(xml::reader::XmlEvent::EndElement { name, .. }) => { | ||
if name.local_name == "apply" { | ||
return Ok(Expression::dflt()); // todo not default ofc; build | ||
} | ||
} | ||
Ok(xml::reader::XmlEvent::EndDocument) => { | ||
return Err("unexpected end of document".into()) | ||
} | ||
Err(e) => panic!("Error: {}", e), | ||
_ => (), | ||
} | ||
} | ||
} | ||
} | ||
|
||
/// consume the resut of the xml iterator, until the appropriate closing tag is found | ||
fn drain<T: BufRead>( | ||
xml: &mut EventReader<T>, | ||
stop: &str, | ||
) -> Result<(), Box<dyn std::error::Error>> { | ||
loop { | ||
match xml.next() { | ||
Ok(xml::reader::XmlEvent::StartElement { name, .. }) => { | ||
return Err(format!("unexpected start element: {}", name.local_name).into()); | ||
} | ||
Ok(xml::reader::XmlEvent::EndElement { name, .. }) => { | ||
if name.local_name == stop { | ||
return Ok(()); | ||
} | ||
} | ||
Ok(xml::reader::XmlEvent::EndDocument) => { | ||
return Err("unexpected end of document".into()); | ||
} | ||
Err(e) => { | ||
return Err(e.into()); | ||
} | ||
_ => (), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
mod tutorial; | ||
pub use tutorial::*; | ||
|
||
mod sol; | ||
pub use sol::*; | ||
|
||
mod sbml_model; | ||
pub use sbml_model::*; | ||
|
||
mod sbml_xml_rs; | ||
pub use sbml_xml_rs::*; | ||
|
||
mod expression; | ||
pub use expression::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use serde_xml_rs::{from_str, to_string}; // todo likely want to read from stream or smth | ||
|
||
struct Apply {} | ||
|
||
// this is kinda scuffed but i need to preserve the order of the elements while allowing | ||
// different permutations of the elements | ||
// since serde_xml_rs does not work well with different orderings of the children, this | ||
// will have to do; the correct number & type of children will have to be checked manually elsewhere | ||
#[derive(Debug, Deserialize, Serialize)] | ||
struct Proposition { | ||
events: Vec<PropositionEvent>, | ||
} | ||
|
||
#[derive(Debug, Deserialize, Serialize)] | ||
enum PropositionEvent { | ||
CmpOp(CmpOp), | ||
Ci(Ci), | ||
Cn(Cn), | ||
} | ||
|
||
/// represents variable name in apply terminal | ||
#[derive(Debug, Deserialize, Serialize)] | ||
struct Ci { | ||
#[serde(rename = "$value")] | ||
// renaming so that it is wrapped in the tag instead of being tags attribute | ||
value: String, | ||
} | ||
|
||
#[derive(Debug, Deserialize, Serialize)] | ||
struct Cn { | ||
value: f64, // todo | ||
} | ||
|
||
#[derive(Debug, Deserialize, Serialize)] | ||
#[serde(rename_all = "lowercase")] | ||
enum CmpOp { | ||
Eq, | ||
Neq, | ||
Lt, | ||
Leq, | ||
Gt, | ||
Geq, | ||
} | ||
|
||
pub fn trying() { | ||
let lol = Proposition { | ||
events: vec![ | ||
PropositionEvent::CmpOp(CmpOp::Eq), | ||
PropositionEvent::Ci(Ci { | ||
value: "x".to_string(), | ||
}), | ||
PropositionEvent::Cn(Cn { value: 5.0 }), | ||
], | ||
}; | ||
|
||
let xml = to_string(&lol).unwrap(); | ||
println!("{}", xml); | ||
} |
Oops, something went wrong.