Parse PlantUML Syntax in JavaScript
The aim of this project is to provide a feature-complete, well tested, and maintainable Parsing Expression Grammar (PEG) for the PlantUML syntax. The parser is designed to be used as JavaScript library or from the Command Line
Important: The parser is not yet feature-complete. But we focus on writing a robust implementation which can parse parts of diagram without knowing the full syntax. This means that the parser probably still parses just about enough to get you started. If not, please contribute ❤️.
$ npm install --global --save plantuml-parser
We keep a set of PlantUML scripts (in.plantuml
) and the corresponding formatted output (out.<formatter>
) in test/fixtures/.
const { parse, parseTrace, formatters } = require('plantuml-parser');
// Example PlantUML
const data = `
@startuml
class A
class B
A --|> B
@enduml
`;
// parse PlantUML
const ast = parse(data);
// Format and print AST
console.log(
formatters.default(ast);
)
Output
[
[
{
"name": "A",
"isAbstract": false,
"members": []
},
{
"name": "B",
"isAbstract": false,
"members": []
},
{
"left": "A",
"right": "B",
"leftType": "Unknown",
"rightType": "Unknown",
"leftArrowHead": "",
"rightArrowHead": "|>",
"leftArrowBody": "-",
"rightArrowBody": "-",
"leftCardinality": "",
"rightCardinality": "",
"label": ""
}
]
]
Parse PlantUML in data
. Returns abstract syntax tree.
data
: data to parseoptions
: see PEG.js parser options..
Parse PlantUML in data
, produces tracing output for debugging. Returns abstract syntax tree.
data
: data to parseoptions
: see PEG.js parser options..
For a detailed description of all the formatters see src/formatters.
Options:
--formatter, -f formatter to use
[choices: "default", "graph"] [default: "default"]
--input, -i input file to read [string] [default: stdin]
--output, -o output file to write [string] [default: stdout]
--color, -c colorful output [boolean] [default: false]
--verbose, -v print verbose output [boolean] [default: false]
--help Show help [boolean]
- Diagram Types:
- Class
- Component
- Use Case
- Sequence
- Activity
- State
- Object
- Deployment
- Timing
- Formatters:
- JSON
- Graph
- Testing, CI/CD:
- Fixtures for all formatters
- Code coverage
- Code formatting
- Code linting
- Dependency audit
$ npm test
This will run:
- unit tests
- code coverage
- eslint
Every contribution counts. Please,
- ... submit unparsable diagrams via new issue.
- ... extend the parser by forking and creating a Pull Request
When contributing code, always also update the fixtures and run tests.
$ npm run fixtures
$ npm test
$ git commit
- PlantUML code generator: Provides a command line utility to generate code in various languages given a plantuml class diagram.