brandly/elm-dot-lang/1.1.6

NOTE: the latest version is 1.1.8

DotLang

Parse DOT Language in Elm. Take a look at the grammar https://www.graphviz.org/doc/info/lang.html

fromString : String -> Result (List DeadEnd) Dot

Parse a DOT string.

fromString "graph {}" == Ok (Dot Graph Nothing [])
type Dot
= Dot EdgeType (Maybe ID) (List Stmt)

A DOT file. Either a graph or digraph is represented. It might have an ID. Stmts describe the graph's properties, including vertices and edges.

DOT Components

= Graph
| Digraph

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.

type ID
= ID String
| HtmlID Node
| NumeralID Float

The identifier for a vertex.

type Stmt
= NodeStmt NodeId (List Attr)
| EdgeStmtNode NodeId EdgeRHS (List EdgeRHS) (List Attr)
| EdgeStmtSubgraph Subgraph EdgeRHS (List EdgeRHS) (List Attr)
| AttrStmt AttrStmtType (List Attr)
| LooseAttr Attr
| SubgraphStmt Subgraph

This is the core of a graph's definition. DOT holds a list of statements describing the vertices and edges, along with their properties.

Stmt Components

type NodeId
= NodeId ID (Maybe Port)

NodeId describes the ID of a vertex. Potentially, it has a Port which describes where edges can attach to the vertex.

type Attr
= Attr ID ID

An Attr is a key/value pair describing a property of the graph.

= AttrGraph
| AttrNode
| AttrEdge

An AttrStmt might apply to all nodes or edges, or even the graph as a whole. The AttrStmtType indicates which is being described.

type EdgeRHS
= EdgeNode NodeId
| EdgeSubgraph Subgraph

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.

= Subgraph (Maybe ID) (List 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.

type Port
= PortId ID (Maybe CompassPt)
| PortPt CompassPt

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.

= N
| NE
| E
| SE
| S
| SW
| W
| NW
| C
| UND

A CompassPt describes the 8 compass directions, as well as C for "center" and UND for the default, unspecified direction.

toString

toString : Dot -> String

Export Dot into valid DOT Language syntax, using four spaces for indentation.

toString (Dot Graph Nothing []) == "graph {}"
type Config
= OneLine
| Indent Int

Configure toStringWithConfig, either exporting a graph onto OneLine, if you don't care about readability, or with some number of spaces per Indent.

Export Dot into valid DOT Language syntax with a given Config.

Internal

dot : Parser Dot

The core Parser, in case you want to embed it in some other parser.