Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions plantuml/parser/puml_cli/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ rust_binary(
"//plantuml/parser/puml_parser",
"//plantuml/parser/puml_resolver",
"//plantuml/parser/puml_utils",
"//tools/metamodel/activity:activity_diagram",
"//tools/metamodel/class:class_diagram",
"//tools/metamodel/component:component_diagram",
"//tools/metamodel/sequence:sequence_diagram",
"//tools/serialization/flatbuffers/activity:activity_serializer",
"//tools/serialization/flatbuffers/class:class_serializer",
"//tools/serialization/flatbuffers/component:component_serializer",
"//tools/serialization/flatbuffers/sequence:sequence_serializer",
Expand All @@ -44,9 +46,11 @@ rust_test(
"//plantuml/parser/puml_parser",
"//plantuml/parser/puml_resolver",
"//plantuml/parser/puml_utils",
"//tools/metamodel/activity:activity_diagram",
"//tools/metamodel/class:class_diagram",
"//tools/metamodel/component:component_diagram",
"//tools/metamodel/sequence:sequence_diagram",
"//tools/serialization/flatbuffers/activity:activity_serializer",
"//tools/serialization/flatbuffers/class:class_serializer",
"//tools/serialization/flatbuffers/component:component_serializer",
"//tools/serialization/flatbuffers/sequence:sequence_serializer",
Expand Down
37 changes: 34 additions & 3 deletions plantuml/parser/puml_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@ use std::fs;
use std::path::{Path, PathBuf};
use std::rc::Rc;

use activity_diagram::ActivityDiagram;
use activity_serializer::ActivitySerializer;
use class_serializer::ClassSerializer;
use component_serializer::ComponentSerializer;
use sequence_serializer::SequenceSerializer;

use puml_lobster::{write_lobster_to_file, LobsterModel};
use puml_parser::{
DiagramParser, ErrorLocation, Preprocessor, PumlClassParser, PumlComponentParser,
PumlSequenceParser,
DiagramParser, ErrorLocation, Preprocessor, PumlActivityParser, PumlClassParser,
PumlComponentParser, PumlSequenceParser,
};
use puml_resolver::{
ActivityResolver, ClassResolver, ComponentResolver, DiagramResolver, SequenceResolver,
};
use puml_resolver::{ClassResolver, ComponentResolver, DiagramResolver, SequenceResolver};
use puml_utils::{write_fbs_to_file, write_json_to_file, LogLevel};

/// CLI wrapper for LogLevel that implements ValueEnum
Expand Down Expand Up @@ -99,6 +103,7 @@ struct Args {
#[derive(Copy, Clone, ValueEnum, Debug)]
enum DiagramType {
None,
Activity,
Component,
Deployment,
Class,
Expand All @@ -108,6 +113,7 @@ enum DiagramType {
#[allow(dead_code)] // Class and Sequence variants are WIP
#[derive(Debug, Serialize)]
enum ParsedDiagram {
Activity(puml_parser::RawActivityDiagram),
Component(puml_parser::CompPumlDocument),
Class(puml_parser::ClassUmlFile),
Sequence(puml_parser::SeqPumlDocument),
Expand Down Expand Up @@ -191,6 +197,7 @@ fn run() -> Result<(), Box<dyn std::error::Error>> {
let lobster_model = match &logic_result {
ResolvedDiagram::Component(model) => LobsterModel::Component(model),
ResolvedDiagram::Class(model) => LobsterModel::Class(model),
ResolvedDiagram::Activity(_) => LobsterModel::Empty,
ResolvedDiagram::Sequence(_) => LobsterModel::Empty,
};
write_lobster_to_file(lobster_model, path, ldir)?;
Expand All @@ -208,6 +215,9 @@ fn run() -> Result<(), Box<dyn std::error::Error>> {

fn serialize_resolved_diagram(resolved_content: &ResolvedDiagram, source_file: &str) -> Vec<u8> {
match resolved_content {
ResolvedDiagram::Activity(resolved_content) => {
ActivitySerializer::serialize(resolved_content, source_file)
}
ResolvedDiagram::Component(resolved_content) => {
ComponentSerializer::serialize(resolved_content, source_file)
}
Expand All @@ -222,6 +232,7 @@ fn serialize_resolved_diagram(resolved_content: &ResolvedDiagram, source_file: &

#[derive(Debug, Serialize)]
pub enum ResolvedDiagram {
Activity(ActivityDiagram),
Component(HashMap<String, component_diagram::LogicComponent>),
Class(class_diagram::ClassDiagram),
Sequence(sequence_logic::SequenceTree),
Expand All @@ -231,6 +242,10 @@ fn resolve_parsed_diagram(
parsed_content: ParsedDiagram,
) -> Result<ResolvedDiagram, Box<dyn std::error::Error>> {
match parsed_content {
ParsedDiagram::Activity(parsed_content) => {
let mut resolver = ActivityResolver::new();
puml_resolver(&mut resolver, &parsed_content).map(ResolvedDiagram::Activity)
}
ParsedDiagram::Component(parsed_content) => {
let mut resolver = ComponentResolver::new();
puml_resolver(&mut resolver, &parsed_content).map(ResolvedDiagram::Component)
Expand Down Expand Up @@ -289,6 +304,10 @@ fn parse_puml_file(
diagram_type: DiagramType,
) -> Result<ParsedDiagram, Box<dyn std::error::Error>> {
match diagram_type {
DiagramType::Activity => {
parse_with_parser(&mut PumlActivityParser, path, content, log_level)
.map(ParsedDiagram::Activity)
}
DiagramType::Component | DiagramType::Deployment => {
parse_with_parser(&mut PumlComponentParser, path, content, log_level)
.map(ParsedDiagram::Component)
Expand Down Expand Up @@ -326,6 +345,18 @@ fn parse_in_order(
}
}

match PumlActivityParser.parse_file(path, content, log_level) {
Ok(doc) => {
debug!("Successfully detected as Activity diagram");
return Ok(ParsedDiagram::Activity(doc));
}
Err(e) => {
let loc = e.error_location();
debug!("Activity parser failed at {:?}: {}", loc, e);
attempts.push(("Activity", Box::new(e), loc));
}
}

match PumlClassParser.parse_file(path, content, log_level) {
Ok(doc) => {
debug!("Successfully detected as Class diagram");
Expand Down
3 changes: 2 additions & 1 deletion plantuml/parser/puml_resolver/src/activity_diagram/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
rust_library(
name = "puml_resolver_activity",
srcs = [
"src/activity_logic.rs",
"src/activity_resolver.rs",
"src/lib.rs",
],
Expand All @@ -25,6 +24,7 @@ rust_library(
deps = [
"//plantuml/parser/puml_parser:activity_diagram",
"//plantuml/parser/puml_resolver:resolver_traits",
"//tools/metamodel/activity:activity_diagram",
"@crates//:serde",
"@crates//:thiserror",
],
Expand All @@ -47,5 +47,6 @@ rust_test(
"//plantuml/parser/puml_parser:parser_core",
"//plantuml/parser/puml_resolver:resolver_traits",
"//plantuml/parser/puml_utils",
"//tools/metamodel/activity:activity_diagram",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// SPDX-License-Identifier: Apache-2.0
// *******************************************************************************

use crate::activity_logic::{
use activity_diagram::{
ActionNode, ActivityDiagram, ActivityStmt, BackwardNode, ControlKind, ControlNode, IfDisplay,
IfNode, LoopDisplay, RepeatWhileNode, TitleNode, WhileNode,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
// SPDX-License-Identifier: Apache-2.0
// *******************************************************************************

mod activity_logic;
mod activity_resolver;

pub use activity_logic::{
pub use activity_diagram::{
ActionNode, ActivityDiagram, ActivityStmt, BackwardNode, ControlKind, ControlNode, IfDisplay,
IfNode, LoopDisplay, RepeatWhileNode, TitleNode, WhileNode,
};
Expand Down
26 changes: 26 additions & 0 deletions tools/metamodel/activity/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# *******************************************************************************
# Copyright (c) 2026 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************
load("@rules_rust//rust:defs.bzl", "rust_library")

package(default_visibility = ["//visibility:public"])

rust_library(
name = "activity_diagram",
srcs = ["activity_logic.rs"],
crate_name = "activity_diagram",
crate_root = "activity_logic.rs",
edition = "2021",
deps = [
"@crates//:serde",
],
)
47 changes: 47 additions & 0 deletions tools/serialization/flatbuffers/activity/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# *******************************************************************************
# Copyright (c) 2026 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************
load("@flatbuffers//:build_defs.bzl", "flatbuffer_library_public")
load("@rules_rust//rust:defs.bzl", "rust_library")

package(default_visibility = ["//visibility:public"])

flatbuffer_library_public(
name = "activity_fbs_codegen",
srcs = ["activity_diagram.fbs"],
outs = ["activity_diagram_generated.rs"],
flatc_args = [],
language_flag = "--rust",
)

rust_library(
name = "activity_fbs",
srcs = [":activity_fbs_codegen"],
# Generated code from flatc - suppress all lints we can't fix
rustc_flags = ["--cap-lints=allow"],
deps = [
"@crates//:flatbuffers",
],
)

rust_library(
name = "activity_serializer",
srcs = ["activity_serializer.rs"],
crate_name = "activity_serializer",
crate_root = "activity_serializer.rs",
edition = "2021",
deps = [
":activity_fbs",
"//tools/metamodel/activity:activity_diagram",
"@crates//:flatbuffers",
],
)
90 changes: 90 additions & 0 deletions tools/serialization/flatbuffers/activity/activity_diagram.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// *******************************************************************************
// Copyright (c) 2026 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available under the
// terms of the Apache License Version 2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: Apache-2.0
// *******************************************************************************

namespace activity;

enum ControlKind:byte {
Stop,
Kill,
Detach,
Break,
Continue
}

table IfDisplay {
then_label:string;
else_label:string;
}

table LoopDisplay {
continue_label:string;
exit_label:string;
}

table TitleNode {
text:string;
}

table ActionNode {
label:string;
}

table BackwardNode {
label:string;
}

table ControlNode {
kind:ControlKind = Stop;
}

table IfNode {
condition:string;
body:[ActivityStmt];
else_branch:[ActivityStmt];
display:IfDisplay;
}

table WhileNode {
condition:string;
body:[ActivityStmt];
backward:BackwardNode;
display:LoopDisplay;
}

table RepeatWhileNode {
body:[ActivityStmt];
condition:string;
backward:BackwardNode;
display:LoopDisplay;
}

union ActivityStmtValue {
TitleNode,
ActionNode,
IfNode,
WhileNode,
RepeatWhileNode,
ControlNode
}

table ActivityStmt {
value:ActivityStmtValue;
}

table ActivityDiagram {
name:string;
statements:[ActivityStmt];
source_file:string;
}

root_type ActivityDiagram;
Loading
Loading