@@ -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