-
Notifications
You must be signed in to change notification settings - Fork 1
/
parser.go
38 lines (28 loc) · 875 Bytes
/
parser.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package giraffe
import (
"fmt"
"strings"
)
func (g *Graph) ParseToMermaid() string {
var builder strings.Builder
builder.WriteString("graph TD;\n")
for _, vertex := range g.Vertices {
builder.WriteString(fmt.Sprintf(" %d;\n", vertex.Index))
}
for _, edge := range g.Edges {
builder.WriteString(fmt.Sprintf(" %d --> %d;\n", edge.Start.Index, edge.End.Index))
}
return builder.String()
}
func (g *Graph) ParseToGraphvizDot() string {
var builder strings.Builder
builder.WriteString("digraph G {\n")
for _, vertex := range g.Vertices {
builder.WriteString(fmt.Sprintf(" %d;\n", vertex.Index))
}
for _, edge := range g.Edges {
builder.WriteString(fmt.Sprintf(" %d -> %d;\n", edge.Start.Index, edge.End.Index))
}
builder.WriteString("}")
return builder.String()
}