id101010 / plantuml-parser

Parse PlantUML Syntax in JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

plantuml-parser Build Status Coverage Status

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 ❤️.

#PlantUMLParser

Installation

$ npm install --global --save plantuml-parser

Examples / Fixtures

We keep a set of PlantUML scripts (in.plantuml) and the corresponding formatted output (out.<formatter>) in test/fixtures/.

Usage

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(data, options)

Parse PlantUML in data. Returns abstract syntax tree.

parseTrace(data, options)

Parse PlantUML in data, produces tracing output for debugging. Returns abstract syntax tree.

formatters: A collection of built-in AST formatters.

For a detailed description of all the formatters see src/formatters.

Command Line Interface

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]

Features

  • 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

Test

$ npm test

This will run:

  • unit tests
  • code coverage
  • eslint

Contribute ❤️

Every contribution counts. Please,

When contributing code, always also update the fixtures and run tests.

$ npm run fixtures
$ npm test
$ git commit

Similar Projects

  • PlantUML code generator: Provides a command line utility to generate code in various languages given a plantuml class diagram.

License

About

Parse PlantUML Syntax in JavaScript

License:Apache License 2.0


Languages

Language:JavaScript 100.0%