A diagoago diagram language compiler written in MoonBit.
Diago compiles diagoago diagram source files to SVG. It implements the codiago diago language features including objects, edges, labels, shapes, and styling.
moon build# 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.svgCreate a file example.d2:
server: Web Server
database: Database {
shape: cylinder
}
cache: Cache {
shape: oval
}
server -> database: queries
server -> cache: reads
cache -> database: fallbackCompile it:
moon run cmd/main -- example.d2 example.svgThe 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 |
- 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
moon test # Run all tests
moon test -v # Verbose outputMIT