Skip to content

Commit

Permalink
feat: add layered for guarding
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Oct 9, 2022
1 parent 72b4bc8 commit 59d3cf4
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 1 deletion.
26 changes: 25 additions & 1 deletion fkl_parser/src/parser/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ pub enum FklDeclaration {
Struct(StructDecl),
// Domain(DomainDecl),
Binding(BindingDecl),
Component(ComponentDecl)
Component(ComponentDecl),
Layered(LayeredDecl),
}

// todo: add Loc support
Expand Down Expand Up @@ -303,6 +304,29 @@ pub struct BindingExtraConfig {
pub package: Option<String>,
}

// Layered Block

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct LayeredDecl {
pub name: String,
pub inline_doc: String,
pub dependencies: Vec<LayerRelation>,
pub layers: Vec<LayerDecl>,
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct LayerRelation {
pub from: String,
pub to: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct LayerDecl {
pub name: String,
pub inline_doc: String,
pub package: String,
}

// Architecture Binding Block

#[derive(Debug, Clone, PartialEq, Eq)]
Expand Down
21 changes: 21 additions & 0 deletions fkl_parser/src/parser/fkl.pest
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ declaration = {
| entity_decl
| value_object_decl
| struct_decl
// ddd
| component_decl
| implementation_decl
| layered_decl
}

context_map_decl = {
Expand Down Expand Up @@ -116,6 +118,25 @@ via_message_decl = {
"via" ~ object_name ~ "send" ~ pass_object ~ "to" ~ topic_name ~ ";"?
}

layered_decl = {
"layered" ~ identifier ~ "{" ~ (inline_doc | dependency | layer_decl)* ~ "}"
}

layer_decl = {
"layer" ~ identifier ~ "{" ~ (inline_doc | (package_def)*)? ~ "}"
}

package_def = {
"package" ~ ":" ~ string ~ ";"?
}

dependency = {
"dependency" ~ "{" ~ (source ~ rs_left_to_right ~ target)* ~ "}"
}

source = { identifier | string }
target = { identifier | string }

object_name = { identifier }
method_name = { identifier }
receive_object = { name_type_def }
Expand Down
77 changes: 77 additions & 0 deletions fkl_parser/src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1190,5 +1190,82 @@ imple CinemaCreatedEvent {
}),
}));
}

#[test]
fn layered_architecture() {
let decls = parse(r#"layered DDD {
dependency {
"interface" -> "application"
"interface" -> "domain"
"domain" -> "application"
"application" -> "infrastructure"
"interface" -> "infrastructure"
}
layer interface {
package: "com.example.book"
}
layer domain {
package: "com.example.domain"
}
layer application {
package: "com.example.application"
}
layer infrastructure {
package: "com.example.infrastructure"
}
}"#).or_else(|e| {
println!("{}", e);
Err(e)
}).unwrap();

// assert_eq!(decls[0], FklDeclaration::Layered(LayeredDecl {
// name: "DDD".to_string(),
// inline_doc: "".to_string(),
// dependencies: vec![
// LayerRelation {
// from: "interface".to_string(),
// to: "application".to_string(),
// },
// LayerRelation {
// from: "interface".to_string(),
// to: "domain".to_string(),
// },
// LayerRelation {
// from: "domain".to_string(),
// to: "application".to_string(),
// },
// LayerRelation {
// from: "application".to_string(),
// to: "infrastructure".to_string(),
// },
// LayerRelation {
// from: "interface".to_string(),
// to: "infrastructure".to_string(),
// },
// ],
// layers: vec![
// LayerDecl {
// name: "interface".to_string(),
// inline_doc: "".to_string(),
// package: "com.example.book".to_string(),
// },
// LayerDecl {
// name: "domain".to_string(),
// inline_doc: "".to_string(),
// package: "com.example.domain".to_string(),
// },
// LayerDecl {
// name: "application".to_string(),
// inline_doc: "".to_string(),
// package: "com.example.application".to_string(),
// },
// LayerDecl {
// name: "infrastructure".to_string(),
// inline_doc: "".to_string(),
// package: "com.example.infrastructure".to_string(),
// },
// ],
// }));
}
}

1 change: 1 addition & 0 deletions fkl_parser/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ impl MirTransform {
}
FklDeclaration::Struct(_) => {}
FklDeclaration::Binding(_) => {}
FklDeclaration::Layered(_) => {}
}
});
}
Expand Down

0 comments on commit 59d3cf4

Please sign in to comment.