|
| 1 | +<!-- |
| 2 | + Copyright (c) 2026 Contributors to the Eclipse Foundation |
| 3 | +
|
| 4 | + See the NOTICE file(s) distributed with this work for additional |
| 5 | + information regarding copyright ownership. |
| 6 | +
|
| 7 | + This program and the accompanying materials are made available under the |
| 8 | + terms of the Apache License Version 2.0 which is available at |
| 9 | + https://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +
|
| 11 | + SPDX-License-Identifier: Apache-2.0 |
| 12 | +--> |
| 13 | + |
| 14 | +# PlantUML Parser |
| 15 | + |
| 16 | +The PlantUML Parser is a multi-file parser that processes PlantUML diagram files and converts them into structured data for traceability and architectural analysis. It handles preprocessing of include directives, supports multiple diagram types (Class, Sequence, Component), and generates FlatBuffers binary output for further downstream processing. |
| 17 | + |
| 18 | +--- |
| 19 | + |
| 20 | +## What It Does |
| 21 | + |
| 22 | +The parser takes `.puml` source files as input and produces: |
| 23 | + |
| 24 | +- **FlatBuffers binary** (`.fbs.bin`) — primary structured output for downstream consumers |
| 25 | +- **LOBSTER traceability JSON** (`.lobster`) — for component diagrams, enables traceability linking via the LOBSTER toolchain |
| 26 | +- **Debug JSON** — raw and resolved ASTs when `--log-level debug` or higher is set |
| 27 | + |
| 28 | + |
| 29 | +Rust-based parser that produces an AST for the following PlantUML diagram types: |
| 30 | + |
| 31 | +- Class Diagram |
| 32 | +- Sequence Diagram |
| 33 | +- Component Diagram |
| 34 | + |
| 35 | +Outputs are `.fbs.bin` FlatBuffers binaries (diagram AST) and optionally `.lobster` |
| 36 | +traceability files (for component diagrams). |
| 37 | + |
| 38 | +## Usage |
| 39 | + |
| 40 | +### Build: |
| 41 | +``` |
| 42 | +bazel build //tools/plantuml/parser |
| 43 | +``` |
| 44 | + |
| 45 | +### Run: |
| 46 | +``` |
| 47 | +bazel run //tools/plantuml/parser -- [OPTIONS] |
| 48 | +``` |
| 49 | + |
| 50 | +Options: |
| 51 | + |
| 52 | +| Option | Description | Default | |
| 53 | +|--------|-------------|---------| |
| 54 | +| `--file <FILE>...` | One or more PUML files to parse (repeatable) | — | |
| 55 | +| `--folders <DIR>` | Folder containing PUML files | — | |
| 56 | +| `--log-level <error\|warn\|info\|debug\|trace>` | Logging verbosity | `warn` | |
| 57 | +| `--diagram-type <component\|class\|sequence\|none>` | Diagram type hint | `none` | |
| 58 | +| `--fbs-output-dir <DIR>` | Output directory for `.fbs.bin` FlatBuffers files | none (no output) | |
| 59 | +| `--lobster-output-dir <DIR>` | Output directory for `.lobster` traceability files | none (no output) | |
| 60 | + |
| 61 | +At least one of `--file` or `--folders` is required. |
| 62 | + |
| 63 | +Example: |
| 64 | +``` |
| 65 | +bazel run //tools/plantuml/parser -- \ |
| 66 | + --file $PWD/tools/plantuml/parser/integration_test/component_diagram/simple_component.puml \ |
| 67 | + --log-level trace \ |
| 68 | + --diagram-type component \ |
| 69 | + --fbs-output-dir $PWD/tools/plantuml/parser |
| 70 | +``` |
| 71 | +## Architecture |
| 72 | + |
| 73 | +The parser is organized into separate crate modules per diagram type: |
| 74 | + |
| 75 | +``` |
| 76 | +puml_parser/ |
| 77 | +├── src/ |
| 78 | +│ ├── class_diagram/ # Class diagram parser (pest grammar → AST) |
| 79 | +│ ├── component_diagram/ # Component diagram parser |
| 80 | +│ ├── sequence_diagram/ # Sequence diagram parser (two-stage: syntax → logic) |
| 81 | +│ └── ... # Shared utilities (parser_core, puml_utils) |
| 82 | +puml_cli/ # CLI entry point (clap-based) |
| 83 | +``` |
| 84 | + |
| 85 | +Each diagram parser uses [pest](https://pest.rs/) PEG grammars to tokenize PlantUML input, |
| 86 | +then builds a typed AST. The CLI (`puml_cli`) dispatches to the appropriate parser based on |
| 87 | +`--diagram-type` or auto-detection. |
| 88 | + |
| 89 | +For the detailed design and users Guide, see [README](docs/README.md). |
0 commit comments