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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
//! An SCXML statechart interpreter core, a conformant sibling of the Elixir
//! reference `statifier`, checked against the conformance corpus the
//! reference publishes.
//!
//! [`compile`] reads an SCXML document into a [`Machine`]: an immutable
//! value, cheap to clone and safe to share between threads, that holds every
//! state interned in document order and every expression compiled through
//! the predicator crate. A document it cannot compile is answered with the
//! [`Refusal`]s of the first stage that refused it.
//!
//! [`Machine::start`] starts a chart in execution: a [`State`], an
//! immutable value that [`State::step`] (an external event) and
//! [`State::advance`] (the virtual clock) move, each answering the new
//! state and the [`Effect`]s the call produced. The driver takes no
//! runtime, thread, clock or I/O of its own: a send of a type the host
//! registered ([`Options::send_types`]) is answered as an effect for the
//! host to deliver, and the crate never calls host code.
//!
//! ```
//! use statifier::{Options, Value};
//!
//! let machine = statifier::compile(
//! r#"<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" initial="a">
//! <state id="a"><transition event="e.go" target="b"/></state>
//! <final id="b"/>
//! </scxml>"#,
//! )
//! .map_err(|refusals| format!("{refusals:?}"))?;
//! let started = machine.start(Options::new("s-1"))?;
//! assert_eq!(started.state.configuration(), ["a"]);
//!
//! let moved = started.state.step("e.go", Value::Undefined)?;
//! assert_eq!(moved.state.done().map(|done| done.configuration.clone()), Some(vec!["b".to_owned()]));
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! [`State::export_position`] writes a chart's position in the string-id
//! vocabulary, and [`Machine::import_position`] reads one back onto the same
//! chart or another that holds every state it names. A position carries the
//! interpreter's state only: the virtual clock, a pending timer and a queued
//! external event are the host's to reschedule.
//!
//! # Refusals are values
//!
//! No function panics on a document or a position a host passes: every
//! refusal is a value ([`Refusal`], [`Error`], [`ExportError`],
//! [`ImportError`]), every public enum is `#[non_exhaustive]`, and nothing
//! is configured globally.
//!
//! # Features and compatibility
//!
//! The optional `basichttp` feature, off by default, adds the `basichttp`
//! module: the Basic HTTP Event I/O Processor a host registers, delivers a
//! send through and decodes a received request with, and the `Transport`
//! trait it implements, with the request, response and error values it
//! exchanges. It adds no dependency and the crate ships no transport.
//!
//! The `serde` feature, off by default, implements `Serialize` and
//! `Deserialize` for a [`Position`], an [`Effect`] and a [`Done`], with the
//! types they reach, and turns on the predicator crate's own for a
//! [`Value`]. The crate has one runtime dependency, the predicator crate,
//! forbids `unsafe` code, needs `std`, and builds for
//! `wasm32-unknown-unknown`. The README holds the full compatibility and
//! conformance statements.
// The README's Rust examples, run as doctests with the `basichttp` feature
// on (the gate's `cargo test --all-features` run), since one of them uses
// the `basichttp` module.
;
// Proof that the default build does not compile the `basichttp` module. With
// the feature off the block below is `compile_fail`, so the gate's
// `cargo test --no-default-features` run passes only when the path does not
// resolve; with the feature on the same source is a normal block, so a typo
// in the path breaks that run and the `compile_fail` cannot pass for the
// wrong reason.
;
pub use AcceptsCheck;
pub use ;
pub use ;
pub use Machine;
/// The value type of a chart's datamodel: the predicator crate's own
/// value, re-exported rather than mirrored, so a value a host passes in and
/// a value an expression answers are one type.
pub use Value;
/// The map type of a chart's datamodel and of a map value: the predicator
/// crate's own, re-exported beside [`Value`], with its key type.
pub use ;
pub use ;
/// Compiles the SCXML document `source` into its machine.
///
/// Reading a chart is four stages, each a port of the reference's: the
/// reader (the XML), lowering (the SCXML elements), the validator (the
/// specification's rules) and the compiler (the expressions, through the
/// predicator crate). The first stage that refuses the document answers
/// every refusal it found, sorted by where each starts, and no later stage
/// runs. A document that compiles carries the validator's warnings on the
/// machine ([`Machine::warnings`]).
///
/// ```
/// let machine = statifier::compile(
/// r#"<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" initial="a">
/// <state id="a"><transition event="e.go" cond="x > 1" target="b"/></state>
/// <final id="b"/>
/// </scxml>"#,
/// )?;
/// assert!(machine.warnings().is_empty());
///
/// let refusals = statifier::compile(
/// r#"<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0">
/// <state id="a"><transition cond="x >" target="a"/></state>
/// </scxml>"#,
/// )
/// .unwrap_err();
/// assert!(matches!(
/// refusals[0].reason(),
/// statifier::Reason::Compile(statifier::CompileReason::ExpressionCompileError { .. })
/// ));
/// # Ok::<(), Vec<statifier::Refusal>>(())
/// ```
/// Compiles an invocation's inline `<content>` markup as the reference's
/// `Statifier.Invoke.Source` compiles it, a root with no namespace accepted;
/// `None` when any stage refuses it.
pub