Skip to content

Commit

Permalink
post-review fixes for wildcard internal transitions support
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitriy Kumshayev committed Jul 15, 2024
1 parent 2c64922 commit a8a9f7a
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 217 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ statemachine! {
}
```

See also `examples/wildcard_states_and_internal_transitions.rs` or `examples/internal_transitions_with_data.rs` for a usage example.
See also tests: `test_internal_transition_with_data()` or `test_wildcard_states_and_internal_transitions()` for a usage example.

#### Guard expressions

Expand Down
131 changes: 0 additions & 131 deletions examples/internal_transitions_with_data.rs

This file was deleted.

39 changes: 0 additions & 39 deletions examples/wildcard_states_and_internal_transitions.rs

This file was deleted.

24 changes: 10 additions & 14 deletions macros/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,18 @@ fn add_transition(
}

impl ParsedStateMachine {
pub fn new(sm: StateMachine) -> parse::Result<Self> {
pub fn new(mut sm: StateMachine) -> parse::Result<Self> {
// Derive out_state for internal non-wildcard transitions
let sm = {
let mut sm = sm;
for transition in sm.transitions.iter_mut() {
if transition.out_state.internal_transition && !transition.in_state.wildcard {
transition.out_state.ident = transition.in_state.ident.clone();
transition
.out_state
.data_type
.clone_from(&transition.in_state.data_type);
transition.out_state.internal_transition = false;
}
for transition in sm.transitions.iter_mut() {
if transition.out_state.internal_transition && !transition.in_state.wildcard {
transition.out_state.ident = transition.in_state.ident.clone();
transition
.out_state
.data_type
.clone_from(&transition.in_state.data_type);
transition.out_state.internal_transition = false;
}
sm
};
}

// Check the initial state definition
let mut starting_transitions_iter = sm.transitions.iter().filter(|sm| sm.in_state.start);
Expand Down
32 changes: 0 additions & 32 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,35 +82,3 @@
#![no_std]

pub use smlang_macros::statemachine;

pub(crate) mod internal_macros {
#[macro_export]
macro_rules! assert_transition {
($sm:expr, $event:expr, $expected_state:expr, $expected_count:expr) => {{
let prev_state = $sm.state;
$sm.process_event($event).unwrap();
println!("{:?} -> {:?} : {:?}", prev_state, $sm.state, $sm.context());
assert_eq!($expected_state, $sm.state);
assert_eq!($expected_count, $sm.context().count);
}};
}
#[macro_export]
macro_rules! assert_transition_ok {
($sm:expr, $event:expr, $expected_result:expr, $expected_context:expr) => {{
let prev_state = $sm.state;
if let Ok(result_2132) = $sm.process_event($event) {
let result_2132 = result_2132.clone();
println!(
"{:?} -> {:?} : {:?}",
prev_state,
result_2132,
$sm.context()
);
assert_eq!($expected_result, result_2132);
assert_eq!(&$expected_context, $sm.context());
} else {
panic!("assert_transition_ok failed")
}
}};
}
}
Loading

0 comments on commit a8a9f7a

Please sign in to comment.