Skip to content

Commit b0d921b

Browse files
committed
Fix internal-transition can't be rendered in boxart
- Skip internal-transition on box/asciiart format - Add option mode::blackbox::State in scdlang_smcat
1 parent 6bc6e2e commit b0d921b

File tree

5 files changed

+39
-21
lines changed

5 files changed

+39
-21
lines changed

packages/cli/src/commands/code/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,21 @@ impl<'c> CLI<'c> for Code {
5555

5656
let mut machine: Box<dyn Transpiler> = match target {
5757
"xstate" => Box::new({
58+
use xstate::option::*;
5859
let mut machine = xstate::Machine::new();
5960
let config = machine.configure();
60-
config.set("output", output_format);
61+
config.set(OUTPUT, output_format);
6162
if output_format.one_of(&output::EXPORT_NAME_LIST) {
62-
config.set("export_name", &export_name);
63+
config.set(EXPORT, &export_name);
6364
}
6465
machine
6566
}),
6667
"smcat" | "graph" => {
68+
use smcat::option::*;
6769
let mut machine = Box::new(smcat::Machine::new());
6870
let config = machine.configure();
6971
match output_format {
70-
"ascii" | "boxart" => config.with_err_semantic(true),
72+
"ascii" | "boxart" => config.with_err_semantic(true).set(MODE, mode::blackbox::STATE),
7173
_ => config.with_err_semantic(false),
7274
};
7375
machine

packages/cli/src/commands/eval/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,21 @@ If file => It will be overwriten everytime the REPL produce output, especially i
6060

6161
let mut machine: Box<dyn Transpiler> = match target {
6262
"xstate" => Box::new({
63+
use xstate::option::*;
6364
let mut machine = xstate::Machine::new();
6465
let config = machine.configure();
65-
config.set("output", output_format);
66+
config.set(OUTPUT, output_format);
6667
if output_format.one_of(&output::EXPORT_NAME_LIST) {
67-
config.set("export_name", &export_name);
68+
config.set(EXPORT, &export_name);
6869
}
6970
machine
7071
}),
7172
"smcat" | "graph" => {
73+
use smcat::option::*;
7274
let mut machine = Box::new(smcat::Machine::new());
7375
let config = machine.configure();
7476
match output_format {
75-
"ascii" | "boxart" => config.with_err_semantic(true),
77+
"ascii" | "boxart" => config.with_err_semantic(true).set(MODE, mode::blackbox::STATE),
7678
_ => config.with_err_semantic(false),
7779
};
7880
machine

packages/core/src/core/builder.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,14 @@ impl<'g> Builder<'g> for Scdlang<'g> {
8383
self
8484
}
8585

86-
fn set(&mut self, key: &'static str, value: &'g str) {
86+
fn set(&mut self, key: &'static str, value: &'g str) -> &mut dyn Builder<'g> {
8787
match self.derive_config.as_mut() {
8888
Some(config) => {
8989
config.entry(key).and_modify(|val| *val = value).or_insert(value);
9090
}
9191
None => self.derive_config = Some([(key, value)].iter().cloned().collect()),
92-
}
92+
};
93+
self
9394
}
9495

9596
fn get(&self, key: &'g str) -> Option<&'g str> {

packages/core/src/external.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pub trait Builder<'t> {
135135
fn with_err_line(&mut self, line: usize) -> &mut dyn Builder<'t>;
136136

137137
// Set custom config. Used on derived Parser.
138-
fn set(&mut self, key: &'static str, value: &'t str);
138+
fn set(&mut self, key: &'static str, value: &'t str) -> &mut dyn Builder<'t>;
139139
// Get custom config. Used on derived Parser.
140140
fn get(&self, key: &'t str) -> Option<&'t str>;
141141
}

packages/transpiler/smcat/src/lib.rs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ pub mod prelude {
1515
pub use scdlang::external::*;
1616
}
1717

18+
pub mod option {
19+
pub const MODE: &str = "mode"; // -> normal,blackbox-state
20+
pub mod mode {
21+
pub mod blackbox {
22+
pub const STATE: &str = "blackbox-state";
23+
}
24+
}
25+
}
26+
1827
#[derive(Default, Serialize)]
1928
/** Transpiler Scdlang → State Machine Cat (JSON).
2029
@@ -66,6 +75,7 @@ impl<'a> Parser<'a> for Machine<'a> {
6675
fn try_parse(source: &str, builder: Scdlang<'a>) -> Result<Self, DynError> {
6776
use StateType::*;
6877
let mut schema = Coordinate::default();
78+
let get = |key| builder.get(key);
6979

7080
for kind in builder.iter_from(source)? {
7181
match kind {
@@ -91,19 +101,22 @@ impl<'a> Parser<'a> for Machine<'a> {
91101
current.with_color(color);
92102
next = next.map(|mut s| s.with_color(color).clone())
93103
}
94-
if let Some(next) = next {
95-
vec![current, next] // external transition
96-
} else {
97-
if let (Some(event), Some(action)) = (event.as_ref(), action.as_ref()) {
98-
current.actions = Some(vec![ActionType {
99-
r#type: ActionTypeType::Activity,
100-
body: match cond.as_ref() {
101-
None => format!("{} / {}", event, action),
102-
Some(cond) => format!("{} [{}] / {}", event, cond, action),
103-
},
104-
}]);
104+
use option::mode::*;
105+
match next {
106+
Some(next) => vec![current, next], // external transition
107+
None if get(option::MODE) == Some(blackbox::STATE) => vec![/*WARNING:wasted*/], // ignore anything inside state
108+
None => {
109+
if let (Some(event), Some(action)) = (event.as_ref(), action.as_ref()) {
110+
current.actions = Some(vec![ActionType {
111+
r#type: ActionTypeType::Activity,
112+
body: match cond.as_ref() {
113+
None => format!("{} / {}", event, action),
114+
Some(cond) => format!("{} [{}] / {}", event, cond, action),
115+
},
116+
}]);
117+
}
118+
vec![current] // internal transition
105119
}
106-
vec![current] // internal transition
107120
}
108121
});
109122

0 commit comments

Comments
 (0)