Skip to content

moonbit-community/diago

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Diago

A diagoago diagram language compiler written in MoonBit.

Overview

Diago compiles diagoago diagram source files to SVG. It implements the codiago diago language features including objects, edges, labels, shapes, and styling.

Installation

moon build

Usage

# Compile diagoago to SVG (output to stdout)
moon run cmd/main -- diagram.d2

# Compile diagoago to SVG file
moon run cmd/main -- diagram.d2 output.svg

Example

Create a file example.d2:

server: Web Server
database: Database {
  shape: cylinder
}
cache: Cache {
  shape: oval
}

server -> database: queries
server -> cache: reads
cache -> database: fallback

Compile it:

moon run cmd/main -- example.d2 example.svg

Architecture

The compiler pipeline:

diagoago Source → Lexer → Parser → AST → IR → Graph → Layout → SVG
Module Description
lexer Tokenizes diagoago source into tokens
parser Parses tokens into AST
ast Abstract syntax tree definitions
ir Intermediate representation
graph Graph data structures (objects, edges)
layout Positions objects and routes edges
svg Renders graph to SVG

Supported Features

  • Objects with labels
  • Nested objects (containers)
  • Edges with labels and arrows (->, <-, <->, --)
  • Shapes: rectangle, circle, oval, cylinder, diamond, hexagon
  • Style properties: fill, stroke, stroke-width, border-radius
  • Edge chains: a -> b -> c

Tests

moon test        # Run all tests
moon test -v     # Verbose output

License

MIT

About

A diagram language written in MoonBit.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages