return string if there's an error
This commit is contained in:
parent
8c8356398c
commit
808672d884
2 changed files with 20 additions and 9 deletions
Binary file not shown.
21
src/lib.rs
21
src/lib.rs
|
|
@ -101,7 +101,10 @@ pub struct StateBuddyTrace {
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn eval_boolean(s: &str, js_trace: JsValue) -> JsValue {
|
pub fn eval_boolean(s: &str, js_trace: JsValue) -> JsValue {
|
||||||
let trace: StateBuddyTrace = from_value(js_trace).expect("fuuuuck");
|
let trace: StateBuddyTrace = match from_value(js_trace) {
|
||||||
|
Ok(trace) => trace,
|
||||||
|
Err(e) => return JsValue::from_str("failed to parse JSON"),
|
||||||
|
};
|
||||||
let mut traceMap = HashMap::<&str, Signal<bool>>::new();
|
let mut traceMap = HashMap::<&str, Signal<bool>>::new();
|
||||||
for entry in &trace.entries {
|
for entry in &trace.entries {
|
||||||
let value = traceMap.entry(entry.inputEvent.as_str()).or_insert_with(|| Signal::<bool>::Sampled {
|
let value = traceMap.entry(entry.inputEvent.as_str()).or_insert_with(|| Signal::<bool>::Sampled {
|
||||||
|
|
@ -113,23 +116,31 @@ pub fn eval_boolean(s: &str, js_trace: JsValue) -> JsValue {
|
||||||
time_points.push(Duration::from_millis(entry.simtime as u64));
|
time_points.push(Duration::from_millis(entry.simtime as u64));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
panic!("fuck!!!");
|
return JsValue::from_str("this should never happen");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let parse_result = argus::parse_str(s);
|
let parse_result = argus::parse_str(s);
|
||||||
let expr = parse_result.expect("fuuuckk!!");
|
let expr = match parse_result {
|
||||||
|
Ok(expr) => expr,
|
||||||
|
Err(e) => return JsValue::from_str("failed to parse expression"),
|
||||||
|
};
|
||||||
let eval_result = match expr {
|
let eval_result = match expr {
|
||||||
Expr::Bool(bool_expr) => BooleanSemantics::eval::<interpolation::Constant>(&bool_expr, &TraceMap{events: traceMap}),
|
Expr::Bool(bool_expr) => BooleanSemantics::eval::<interpolation::Constant>(&bool_expr, &TraceMap{events: traceMap}),
|
||||||
_ => panic!("fuuuck"),
|
_ => return JsValue::from_str("expected boolean expression (this should never happen)"),
|
||||||
};
|
};
|
||||||
let mut result = Vec::<StateBuddyEvalResultEntry>::new();
|
let mut result = Vec::<StateBuddyEvalResultEntry>::new();
|
||||||
eval_result.expect("fuuuck").iter().for_each(|(timestamp, satisfied), | {
|
if let Ok(r) = eval_result {
|
||||||
|
r.iter().for_each(|(timestamp, satisfied), | {
|
||||||
result.push(StateBuddyEvalResultEntry{
|
result.push(StateBuddyEvalResultEntry{
|
||||||
timestamp: timestamp.as_millis() as f64,
|
timestamp: timestamp.as_millis() as f64,
|
||||||
satisfied: *satisfied,
|
satisfied: *satisfied,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return JsValue::from_str("failed to evaluate expression");
|
||||||
|
}
|
||||||
to_value(&StateBuddyEvalResult { entries: result }).expect("fuuuck")
|
to_value(&StateBuddyEvalResult { entries: result }).expect("fuuuck")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue