dot

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

ABOUTME: Consolidated AST types for the unified DOT parser, merging mammoth attractor and dot-editor ASTs. ABOUTME: Defines Graph, Node, Edge, Subgraph, and Diagnostic types with traversal helpers and edge ID assignment.

ABOUTME: Tokenizer/lexer for the DOT DSL that transforms source text into a token stream. ABOUTME: Handles identifiers, keywords, strings with escapes, numbers, booleans, comments, and DOT punctuation.

ABOUTME: Recursive descent parser for the DOT DSL that produces an in-memory Graph model. ABOUTME: Parses digraphs with nodes, edges, attributes, defaults, subgraphs, and chained edge expansion.

ABOUTME: Serializer that converts a Graph AST back to a DOT-formatted source string. ABOUTME: Also provides color-coding for pipeline visualization based on node shape conventions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyColorCoding

func ApplyColorCoding(g *Graph)

ApplyColorCoding adds fillcolor and style attributes to nodes based on their shape, and colors edges based on their label (success/fail conditions).

func Serialize

func Serialize(g *Graph) string

Serialize converts a Graph AST back to a DOT-formatted string with deterministic output. Nodes are sorted by ID, and attributes within each element are sorted by key.

Types

type Diagnostic

type Diagnostic struct {
	Severity string // "error", "warning", "info"
	Message  string
	NodeID   string
	EdgeID   string
	Rule     string
}

Diagnostic represents a validation finding associated with a node or edge.

type Edge

type Edge struct {
	ID    string
	From  string
	To    string
	Attrs map[string]string
}

Edge represents a directed edge from one node to another with an optional ID and attributes.

func (*Edge) StableID

func (e *Edge) StableID() string

StableID returns a deterministic identifier for an edge based on its endpoints. The format is "from->to", which is stable across parses of the same DOT source.

type Graph

type Graph struct {
	Name         string
	Nodes        map[string]*Node
	Edges        []*Edge
	Attrs        map[string]string // graph-level attributes
	NodeDefaults map[string]string // node [...] defaults
	EdgeDefaults map[string]string // edge [...] defaults
	Subgraphs    []*Subgraph
}

Graph represents a parsed DOT digraph with its nodes, edges, attributes, and subgraphs.

func Parse

func Parse(input string) (*Graph, error)

Parse parses the given DOT source string into a Graph. It tokenizes the input, builds the AST, and assigns stable edge IDs before returning.

func (*Graph) AddEdge

func (g *Graph) AddEdge(e *Edge)

AddEdge appends an edge to the graph.

func (*Graph) AddNode

func (g *Graph) AddNode(n *Node)

AddNode adds a node to the graph, initializing the Nodes map if needed.

func (*Graph) AssignEdgeIDs

func (g *Graph) AssignEdgeIDs()

AssignEdgeIDs assigns a unique ID to each edge that does not already have one. Edges that already have a non-empty ID are left unchanged. For edges sharing the same From->To pair, a numeric suffix disambiguates them.

func (*Graph) FindExitNode

func (g *Graph) FindExitNode() *Node

FindExitNode returns the exit/terminal node, or nil if not found. Recognized via shape=Msquare, node_type=exit, or type=exit.

func (*Graph) FindNode

func (g *Graph) FindNode(id string) *Node

FindNode returns the node with the given ID, or nil if not found.

func (*Graph) FindStartNode

func (g *Graph) FindStartNode() *Node

FindStartNode returns the start node, or nil if not found. Recognized via shape=Mdiamond, node_type=start, or type=start.

func (*Graph) IncomingEdges

func (g *Graph) IncomingEdges(nodeID string) []*Edge

IncomingEdges returns all edges terminating at the given node ID.

func (*Graph) NodeIDs

func (g *Graph) NodeIDs() []string

NodeIDs returns all node IDs in sorted order for deterministic output.

func (*Graph) OutgoingEdges

func (g *Graph) OutgoingEdges(nodeID string) []*Edge

OutgoingEdges returns all edges originating from the given node ID.

type Node

type Node struct {
	ID    string
	Attrs map[string]string
}

Node represents a node in the graph with an ID and key-value attributes.

type Subgraph

type Subgraph struct {
	ID           string
	Name         string
	Attrs        map[string]string // subgraph attributes
	NodeIDs      []string          // node IDs in this subgraph
	NodeDefaults map[string]string // scoped node defaults
}

Subgraph represents a subgraph scope containing nodes and scoped defaults.

type Token

type Token struct {
	Type  TokenType
	Value string
	Line  int
	Col   int
}

Token represents a single lexical token with its type, value, and source location.

func Lex

func Lex(input string) ([]Token, error)

Lex tokenizes the given DOT source string into a slice of tokens.

type TokenType

type TokenType int

TokenType represents the type of a lexical token.

const (
	TokenEOF        TokenType = iota
	TokenDigraph              // digraph keyword
	TokenSubgraph             // subgraph keyword
	TokenGraph                // graph keyword
	TokenNode                 // node keyword
	TokenEdge                 // edge keyword
	TokenLBrace               // {
	TokenRBrace               // }
	TokenLBracket             // [
	TokenRBracket             // ]
	TokenArrow                // ->
	TokenEquals               // =
	TokenComma                // ,
	TokenSemicolon            // ;
	TokenIdentifier           // bare identifier
	TokenString               // double-quoted string
	TokenNumber               // integer or float literal
	TokenBoolean              // true or false
	TokenMinus                // - (standalone, not part of -> or number)
)

func (TokenType) String

func (t TokenType) String() string

String returns a human-readable name for the token type.

Directories

Path Synopsis
ABOUTME: Unified lint rules for DOT pipeline graphs, merged from mammoth-dot-editor and attractor/validate.go.
ABOUTME: Unified lint rules for DOT pipeline graphs, merged from mammoth-dot-editor and attractor/validate.go.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL