Parse DOT Language in Elm. Take a look at the grammar https://www.graphviz.org/doc/info/lang.html
fromString : String -> Result (List Parser.DeadEnd) Dot
Parse a DOT string.
fromString "graph {}" == Ok (Dot Graph Nothing [])
A DOT file. Either a graph
or digraph
is represented. It might have
an ID
. Stmt
s describe the graph's properties, including vertices and edges.
A DOT file representing an undirected graph starts with graph
and edges
are described with --
. A directed graph starts with digraph
and uses ->
for its edges.
The identifier for a vertex.
This is the core of a graph's definition. DOT holds a list of statements describing the vertices and edges, along with their properties.
NodeId
describes the ID
of a vertex. Potentially, it has a Port
which
describes where edges can attach to the vertex.
An Attr
is a key/value pair describing a property of the graph.
An AttrStmt
might apply to all nodes or edges, or even the graph as a
whole. The AttrStmtType
indicates which is being described.
The right-hand side of an edge describes what the left-hand side is
connected to. In DOT, you can string together many right-hand sides to describe
large graph structures in a single Stmt
.
A Subgraph
defines a subset of vertices and edges within a graph. You
might use this to visually group a set of vertices together or just as a
shorthand for defining edges between one vertex and a list of other vertices.
A Port
is a point where edges can attach to a vertex. The Port
can have
an ID
, but they're primarily described by the 8 compass directions.
A CompassPt
describes the 8 compass directions, as well as C
for
"center" and UND
for the default, unspecified direction.
toString : Dot -> String
Export Dot
into valid DOT Language syntax, using four spaces for
indentation.
toString (Dot Graph Nothing []) == "graph {}"
Configure toStringWithConfig
, either exporting a graph onto OneLine
,
if you don't care about readability, or with some number of spaces per
Indent
.
toStringWithConfig : Config -> Dot -> String
Export Dot
into valid DOT Language syntax with a given Config
.
dot : Parser Dot
The core Parser
, in case you want to embed it in some other parser.