-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathoutput.rs
72 lines (63 loc) · 2.15 KB
/
output.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use crate::artifact::tla_trace::{TlaState, TlaTrace};
use crate::{Error, ModelCheckerOptions};
pub(crate) fn parse(output: String, options: &ModelCheckerOptions) -> Result<Vec<TlaTrace>, Error> {
let mut traces = Vec::new();
let mut lines = output.lines();
while let Some(line) = lines.next() {
// check if found the beginning of the next trace
if line.starts_with("@!@!@ENDMSG 2121 @!@!@") {
if let Some(trace) = parse_trace(&mut lines, options)? {
traces.push(trace);
}
}
}
Ok(traces)
}
fn parse_trace<'a>(
lines: &mut std::str::Lines<'a>,
options: &ModelCheckerOptions,
) -> Result<Option<TlaTrace>, Error> {
let mut state_index = 0;
let mut state = None;
let mut trace = TlaTrace::new();
loop {
let line = lines
.next()
.ok_or_else(|| Error::InvalidTLCOutput(options.log.clone()))?;
// check if found the start of the next state
if line.starts_with("@!@!@STARTMSG 2217:4 @!@!@") {
state_index += 1;
continue;
}
// check if found the end of the current state
if line.starts_with("@!@!@ENDMSG 2217 @!@!@") {
let state = state
.take()
.expect("[modelator] a trace state should have been started");
trace.add(state);
continue;
}
// any other tag means that this trace has ended
if line.starts_with("@!@!@STARTMSG") {
break;
}
// check if the next state is starting
if line.starts_with(&format!("{}: ", state_index)) {
// start next state
assert!(
state.is_none(),
"[modelator] previous trace state has not ended yet"
);
state = Some(TlaState::new());
continue;
}
// save any remaining line
let state = state
.as_mut()
.expect("[modelator] trace state should have been started");
state.push_str(line);
state.push('\n');
}
let trace = if trace.is_empty() { None } else { Some(trace) };
Ok(trace)
}