Skip to content

Commit bd97735

Browse files
authored
Merge pull request #52 from frame-lang/smcat-visitor
Add some configurable style to the smcat output, simplify visitor
2 parents e5ce763 + 1585794 commit bd97735

File tree

5 files changed

+196
-276
lines changed

5 files changed

+196
-276
lines changed

framec/src/frame_c/ast.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,9 @@ impl MachineBlockNode {
351351
pub fn new(states: Vec<Rc<RefCell<StateNode>>>) -> MachineBlockNode {
352352
MachineBlockNode { states }
353353
}
354+
pub fn get_first_state(&self) -> Option<&Rc<RefCell<StateNode>>> {
355+
self.states.get(0)
356+
}
354357
}
355358

356359
impl NodeElement for MachineBlockNode {

framec/src/frame_c/compiler.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,10 @@ impl Exe {
241241
visitor.run(&system_node);
242242
output = visitor.get_code();
243243
} else if output_format == "plantuml" {
244-
// let x = (&semantic_parser).get_arcanum();
245-
// semantic_parser = semantic_parser.into_inner();
246-
// let y = (&semantic_parser).get_system_hierarchy();
247-
let (x, y) = semantic_parser.get_all();
244+
let (arcanum, system_hierarchy) = semantic_parser.get_all();
248245
let mut visitor = PlantUmlVisitor::new(
249-
x,
250-
y,
246+
arcanum,
247+
system_hierarchy,
251248
generate_state_context,
252249
generate_state_stack,
253250
generate_change_state,
@@ -273,8 +270,11 @@ impl Exe {
273270
visitor.run(&system_node);
274271
output = visitor.get_code();
275272
} else if output_format == "smcat" {
276-
let (x, y) = semantic_parser.get_all();
277-
let mut visitor = SmcatVisitor::new(x, y, FRAMEC_VERSION, comments);
273+
let mut visitor = SmcatVisitor::new(
274+
FRAMEC_VERSION,
275+
config,
276+
semantic_parser.get_system_hierarchy(),
277+
);
278278
visitor.run(&system_node);
279279
output = visitor.get_code();
280280
// } else if output_format == "xstate" {

framec/src/frame_c/config.rs

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ impl FrameConfig {
5353
pub struct CodeGenConfig {
5454
pub common: CommonConfig,
5555
pub rust: RustConfig,
56+
pub smcat: SmcatConfig,
5657
}
5758

5859
/// Code generation options shared among all backends.
@@ -168,6 +169,34 @@ pub struct RustCode {
168169
pub state_cell_var_name: String,
169170
}
170171

172+
/// Code generation options specific to the Smcat backend.
173+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
174+
pub struct SmcatConfig {
175+
pub features: SmcatFeatures,
176+
pub code: SmcatCode,
177+
}
178+
179+
/// Code generation features specific to the Smcat backend.
180+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
181+
pub struct SmcatFeatures {}
182+
183+
/// Style options for generated code specific to the Smcat backend.
184+
///
185+
/// See the sections "colors and line width", "classes", and "overriding the
186+
/// type of a state" in the smcat README:
187+
/// <https://github.com/sverweij/state-machine-cat/blob/develop/README.md>
188+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
189+
pub struct SmcatCode {
190+
/// Style settings for nodes that do not have any children.
191+
pub simple_state_node_style: String,
192+
/// Style settings for nodes that have sub-states as children.
193+
pub parent_state_node_style: String,
194+
/// Style settings for "change-state" transitions.
195+
pub change_state_edge_style: String,
196+
/// Style settings for standard transitions.
197+
pub transition_edge_style: String,
198+
}
199+
171200
impl FrameConfig {
172201
/// Generate a configuration from any `Provider`.
173202
pub fn from<T: Provider>(provider: T) -> Result<FrameConfig, Error> {
@@ -288,24 +317,25 @@ impl Provider for SystemNode {
288317
// Defaults
289318

290319
impl Default for FrameConfig {
291-
fn default() -> FrameConfig {
320+
fn default() -> Self {
292321
FrameConfig {
293322
codegen: CodeGenConfig::default(),
294323
}
295324
}
296325
}
297326

298327
impl Default for CodeGenConfig {
299-
fn default() -> CodeGenConfig {
328+
fn default() -> Self {
300329
CodeGenConfig {
301330
common: CommonConfig::default(),
302331
rust: RustConfig::default(),
332+
smcat: SmcatConfig::default(),
303333
}
304334
}
305335
}
306336

307337
impl Default for CommonConfig {
308-
fn default() -> CommonConfig {
338+
fn default() -> Self {
309339
CommonConfig {
310340
features: CommonFeatures::default(),
311341
code: CommonCode::default(),
@@ -314,19 +344,19 @@ impl Default for CommonConfig {
314344
}
315345

316346
impl Default for CommonFeatures {
317-
fn default() -> CommonFeatures {
347+
fn default() -> Self {
318348
CommonFeatures {}
319349
}
320350
}
321351

322352
impl Default for CommonCode {
323-
fn default() -> CommonCode {
353+
fn default() -> Self {
324354
CommonCode {}
325355
}
326356
}
327357

328358
impl Default for RustConfig {
329-
fn default() -> RustConfig {
359+
fn default() -> Self {
330360
RustConfig {
331361
features: RustFeatures::default(),
332362
code: RustCode::default(),
@@ -335,7 +365,7 @@ impl Default for RustConfig {
335365
}
336366

337367
impl Default for RustFeatures {
338-
fn default() -> RustFeatures {
368+
fn default() -> Self {
339369
RustFeatures {
340370
follow_rust_naming: true,
341371
generate_action_impl: true,
@@ -346,7 +376,7 @@ impl Default for RustFeatures {
346376
}
347377

348378
impl Default for RustCode {
349-
fn default() -> RustCode {
379+
fn default() -> Self {
350380
RustCode {
351381
action_prefix: String::from(""),
352382
action_suffix: String::from(""),
@@ -408,3 +438,29 @@ impl Default for RustCode {
408438
}
409439
}
410440
}
441+
442+
impl Default for SmcatConfig {
443+
fn default() -> Self {
444+
SmcatConfig {
445+
features: SmcatFeatures::default(),
446+
code: SmcatCode::default(),
447+
}
448+
}
449+
}
450+
451+
impl Default for SmcatFeatures {
452+
fn default() -> Self {
453+
SmcatFeatures {}
454+
}
455+
}
456+
457+
impl Default for SmcatCode {
458+
fn default() -> Self {
459+
SmcatCode {
460+
simple_state_node_style: String::from("class=\"state simple\""),
461+
parent_state_node_style: String::from("class=\"state parent\""),
462+
change_state_edge_style: String::from("class=\"edge change-state\""),
463+
transition_edge_style: String::from("class=\"edge transition\""),
464+
}
465+
}
466+
}

framec/src/frame_c/parser.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ impl<'a> Parser<'a> {
154154

155155
/* --------------------------------------------------------------------- */
156156

157+
pub fn get_system_hierarchy(self) -> SystemHierarchy {
158+
self.system_hierarchy_opt.unwrap()
159+
}
160+
161+
/* --------------------------------------------------------------------- */
162+
157163
pub fn get_all(self) -> (Arcanum, SystemHierarchy) {
158164
(self.arcanum, self.system_hierarchy_opt.unwrap())
159165
}

0 commit comments

Comments
 (0)