Skip to content

Joho rework plantuml interfaces#189

Open
hoe-jo wants to merge 5 commits intomainfrom
joho_rework_plantuml_interfaces
Open

Joho rework plantuml interfaces#189
hoe-jo wants to merge 5 commits intomainfrom
joho_rework_plantuml_interfaces

Conversation

@hoe-jo
Copy link
Copy Markdown
Contributor

@hoe-jo hoe-jo commented Apr 29, 2026

No description provided.

hoe-jo added 5 commits April 29, 2026 14:11
…quence parsers

[error handling]: component and sequence parsers were silently
dropping statement-level parse failures via `if let Ok` / `if let Some`.
Both parse_file implementations now propagate errors with `?`, matching
the class parser behaviour.

[dispatch style]: introduced typed error enums to replace
Box<dyn Error> (component) and Option (sequence):
- ComponentError: Base(#[from] BaseParseError<Rule>) | InvalidStatement
- SequenceError:  Base(#[from] BaseParseError<Rule>) | InvalidStatement

All sub-parsers in the sequence parser are converted from Option<T> to
Result<T, SequenceError>. Grammar-valid but non-semantic rules (pragma,
skinparam, title) return Ok(None) and are intentionally skipped; only
genuine parse failures propagate as Err.

DiagramParser impls updated to use the new error types. Both error types
are re-exported from their respective crate roots and from puml_parser.

thiserror dependency added to component_diagram and sequence_diagram BUILD
targets. New rust_test unit targets added for inline acceptance tests.
…Error>

All three parsers now follow the same dispatch contract:
- Component: parse_statement -> Result<Vec<Statement>, ComponentError> (already done)
- Sequence: parse_statement -> Result<Vec<Statement>, SequenceError>
  * Replace Result<Option<Statement>> with Result<Vec<Statement>>
  * Ok(Some(x)) -> Ok(vec![x]), Ok(None) -> Ok(vec![])
  * parse_file appends via Vec::append instead of conditional push
- Class: replace visitor closure walker with flat iterator pattern
  * Remove visit_top_level (recursive FnMut closure with visit_result mutation workaround)
  * Add flatten_top_level: pure fn flattening top_level/together_def wrapper nodes
  * Add parse_top_level_element: extracted dispatch fn with direct ? propagation
  * Apply flatten_top_level in parse_namespace and parse_package as well

Eliminates the visit_result workaround needed to propagate errors through
FnMut closures that do not support ? operator.
Move format_parse_tree to parser_core so all parsers share the same helper:
- Add pub fn format_parse_tree to parser_core/src/lib.rs
- Add @crates//:log dep to parser_core, sequence_diagram, and class_diagram BUILD files

Component parser:
- Remove local format_parse_tree method (now in parser_core)
- Update call site and import to use parser_core::format_parse_tree

Sequence parser:
- Replace eprintln! with log::trace! for raw content at Trace level
- Add #[cfg(not(coverage))] parse tree block at Debug | Trace level

Class parser:
- Replace eprintln! with log::trace! for raw content at Trace level
- Add #[cfg(not(coverage))] parse tree block at Debug | Trace level

All three parsers now:
1. Log raw source content at LogLevel::Trace via log::trace!
2. Log the structured parse tree at LogLevel::Debug | Trace via log::debug!
3. Never write directly to eprintln!
4. Preserve the #[cfg(not(coverage))] gate on the parse tree call
…ceResolver

- Rename DiagramResolver::visit_document -> resolve and drop the
  visit_statement default method + type Statement associated type.
  The trait now expresses a single clear contract: resolve a parsed
  document into a logic model.

- ComponentResolver: DiagramResolver impl uses resolve(); visit_statement
  becomes a plain private method in impl ComponentResolver.

- ClassResolver: DiagramResolver impl uses resolve(); type Statement = ()
  removed; DESIGN comment added to explain the single-pass pattern.

- SequenceResolver (new): wraps build_tree() in a DiagramResolver impl.
  SequenceResolverError is an uninhabited enum (build_tree is infallible)
  that satisfies the std::error::Error bound required by the CLI helper.

- CLI: Sequence(SequenceTree) variant added to ResolvedDiagram;
  resolve_parsed_diagram routes sequence diagrams through SequenceResolver
  instead of hard-coding Err("Sequence diagrams not implemented").

- Tests: arrow detection tests added to logic_parser.rs; sequence
  resolver unit tests in sequence_resolver.rs; end-to-end pipeline
  test in puml_cli; puml_resolver_sequence_unit_test BUILD target added.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant