package d2ir
Import Path
github.com/pancsta/d2/d2ir (on go.dev)
Dependency Relation
imports 21 packages, and imported by one package
Involved Source Files
compile.go
Package d2ir implements a tree data structure to keep track of the resolved value of D2
keys.
edge_expansion.go
expansion.go
glob_expansion.go
import.go
import_cache.go
merge.go
pattern.go
query.go
Package-Level Type Names (total 16)
Values []Value
(*Array) AST() d2ast.Node
(*Array) Copy(newParent Node) Node
(*Array) Equal(n2 Node) bool
(*Array) LastPrimaryKey() *d2ast.Key
(*Array) LastPrimaryRef() Reference
(*Array) LastRef() Reference
(*Array) Map() *Map
(*Array) Parent() Node
(*Array) Primary() *Scalar
(*Array) String() string
*Array : Composite
*Array : Node
*Array : Value
*Array : expvar.Var
*Array : fmt.Stringer
func NodeBoardKind(n Node) BoardKind
const BoardLayer
const BoardScenario
const BoardStep
Context stops parsing and compilation when canceled. A nil Context is
treated as context.Background().
FS resolves imports. Nil disables imports. The lib/localfile package
provides rooted and explicit unrestricted host-filesystem policies.
MaxEdgeExpansion bounds distinct edge-segment and endpoint combinations
considered by edge globs. Zero uses DefaultMaxEdgeExpansion. Explicit edges
do not consume this budget.
MaxEdgeExpansionWork bounds all endpoint-pair examinations performed by
edge globs, including lazy replays. Zero uses DefaultMaxEdgeExpansionWork.
MaxGlobExpansion bounds work performed by glob matching and
materialization. Zero uses DefaultMaxGlobExpansion. Explicit source fields
are not counted as materialization work.
MaxVariableExpansion bounds work added by substitutions and automatic
copies. Zero uses DefaultMaxVariableExpansion.
UTF16Pos bool
func Compile(ast *d2ast.Map, opts *CompileOptions) (*Map, []string, error)
( Composite) AST() d2ast.Node
( Composite) Copy(newParent Node) Node
( Composite) Equal(n2 Node) bool
( Composite) LastPrimaryKey() *d2ast.Key
( Composite) LastPrimaryRef() Reference
( Composite) LastRef() Reference
( Composite) Map() *Map
( Composite) Parent() Node
( Composite) Primary() *Scalar
( Composite) String() string
*Array
*Map
Composite : Node
Composite : Value
Composite : expvar.Var
Composite : fmt.Stringer
ID *EdgeID
Map_ *Map
Primary_ *Scalar
References []*EdgeReference
(*Edge) AST() d2ast.Node
(*Edge) Copy(newParent Node) Node
(*Edge) Equal(n2 Node) bool
(*Edge) IDString() d2ast.String
(*Edge) ImportAST() d2ast.Node
(*Edge) LastPrimaryKey() *d2ast.Key
(*Edge) LastPrimaryRef() Reference
(*Edge) LastRef() Reference
(*Edge) Map() *Map
(*Edge) Parent() Node
(*Edge) Primary() *Scalar
(*Edge) SetImportAST(node d2ast.Node)
(*Edge) String() string
*Edge : Importable
*Edge : Node
*Edge : expvar.Var
*Edge : fmt.Stringer
func ParentEdge(n Node) *Edge
func (*Map).CreateEdge(eid *EdgeID, refctx *RefContext, c *compiler) ([]*Edge, error)
func (*Map).DeleteEdge(eid *EdgeID) *Edge
func (*Map).GetEdges(eid *EdgeID, refctx *RefContext, c *compiler) []*Edge
func OverlayEdge(be, oe *Edge)
DstArrow bool
DstPath []d2ast.String
Glob bool
If nil, then any EdgeID with equal src/dst/arrows matches.
SrcArrow bool
SrcPath []d2ast.String
(*EdgeID) Copy() *EdgeID
(*EdgeID) Match(eid2 *EdgeID) bool
func NewEdgeIDs(k *d2ast.Key) (eida []*EdgeID)
func (*EdgeID).Copy() *EdgeID
func (*EdgeID).Match(eid2 *EdgeID) bool
func (*Map).CreateEdge(eid *EdgeID, refctx *RefContext, c *compiler) ([]*Edge, error)
func (*Map).DeleteEdge(eid *EdgeID) *Edge
func (*Map).GetEdges(eid *EdgeID, refctx *RefContext, c *compiler) []*Edge
Context_ *RefContext
DueToGlob_ bool
DueToLazyGlob_ bool
(*EdgeReference) AST() d2ast.Node
(*EdgeReference) Context() *RefContext
(*EdgeReference) DueToGlob() bool
(*EdgeReference) DueToLazyGlob() bool
Primary returns true if the Value in Context.Key.Value corresponds to the *Edge
represented by Context.Edge
*EdgeReference : Reference
Composite Composite
Name d2ast.String
Primary_ to avoid clashing with Primary(). We need to keep it exported for
encoding/json to marshal it so cannot prefix _ instead.
References []*FieldReference
(*Field) AST() d2ast.Node
(*Field) Copy(newParent Node) Node
(*Field) Equal(n2 Node) bool
(*Field) ImportAST() d2ast.Node
(*Field) LastPrimaryKey() *d2ast.Key
(*Field) LastPrimaryRef() Reference
(*Field) LastRef() Reference
(*Field) Map() *Map
(*Field) Parent() Node
(*Field) Primary() *Scalar
(*Field) Root() bool
(*Field) SetImportAST(node d2ast.Node)
(*Field) String() string
*Field : Importable
*Field : Node
*Field : expvar.Var
*Field : fmt.Stringer
func ParentField(n Node) *Field
func (*Map).DeleteField(ida ...string) *Field
func (*Map).EnsureField(kp *d2ast.KeyPath, refctx *RefContext, create bool, c *compiler) ([]*Field, error)
func (*Map).GetField(ida ...d2ast.String) *Field
func ExpandSubstitution(m, resolved *Map, placeholder *Field)
func OverlayField(bf, of *Field)
Context_ *RefContext
DueToGlob_ bool
DueToLazyGlob_ bool
KeyPath *d2ast.KeyPath
String d2ast.String
(*FieldReference) AST() d2ast.Node
(*FieldReference) Context() *RefContext
(*FieldReference) DueToGlob() bool
(*FieldReference) DueToLazyGlob() bool
(*FieldReference) EdgeDest() bool
(*FieldReference) InEdge() bool
(*FieldReference) KeyPathIndex() int
Primary returns true if the Value in Context.Key.Value corresponds to the Field
represented by String.
*FieldReference : Reference
Edges []*Edge
Fields []*Field
(*Map) AST() d2ast.Node
(*Map) Copy(newParent Node) Node
CopyBase copies the map m without layers/scenarios/steps.
(*Map) CreateEdge(eid *EdgeID, refctx *RefContext, c *compiler) ([]*Edge, error)
(*Map) DeleteEdge(eid *EdgeID) *Edge
(*Map) DeleteField(ida ...string) *Field
(*Map) EdgeCountRecursive() int
EnsureField is a bit of a misnomer. It's more of a Query/Ensure combination function at this point.
(*Map) Equal(n2 Node) bool
(*Map) FieldCountRecursive() int
(*Map) FindBoardRoot(path []string) *Map
(*Map) GetClassMap(name string) *Map
(*Map) GetEdges(eid *EdgeID, refctx *RefContext, c *compiler) []*Edge
(*Map) GetField(ida ...d2ast.String) *Field
(*Map) ImportAST() d2ast.Node
(*Map) InClass(key *d2ast.Key) bool
(*Map) IsClass() bool
(*Map) LastPrimaryKey() *d2ast.Key
(*Map) LastPrimaryRef() Reference
(*Map) LastRef() Reference
(*Map) Map() *Map
(*Map) Parent() Node
(*Map) Primary() *Scalar
Query is only for tests and debugging.
QueryAll is only for tests and debugging.
Root reports whether the Map is the root of the D2 tree.
(*Map) SetImportAST(node d2ast.Node)
(*Map) String() string
*Map : Composite
*Map : Importable
*Map : Node
*Map : Value
*Map : expvar.Var
*Map : fmt.Stringer
func Compile(ast *d2ast.Map, opts *CompileOptions) (*Map, []string, error)
func ParentMap(n Node) *Map
func RootMap(m *Map) *Map
func (*Array).Map() *Map
func Composite.Map() *Map
func (*Edge).Map() *Map
func (*Field).Map() *Map
func (*Map).CopyBase(newParent Node) *Map
func (*Map).FindBoardRoot(path []string) *Map
func (*Map).GetClassMap(name string) *Map
func (*Map).Map() *Map
func Node.Map() *Map
func (*Scalar).Map() *Map
func Value.Map() *Map
func ExpandSubstitution(m, resolved *Map, placeholder *Field)
func OverlayMap(base, overlay *Map)
func ReserveVariableExpansionAliases(ctx context.Context, m *Map) error
func ReserveVariableExpansionCopy(ctx context.Context, m *Map) error
func RootMap(m *Map) *Map
Most errors returned by a node should be created with d2parser.Errorf
to indicate the offending AST node.
( Node) AST() d2ast.Node
( Node) Copy(newParent Node) Node
( Node) Equal(n2 Node) bool
( Node) LastPrimaryKey() *d2ast.Key
( Node) LastPrimaryRef() Reference
( Node) LastRef() Reference
( Node) Map() *Map
( Node) Parent() Node
( Node) Primary() *Scalar
( Node) String() string
*Array
Composite (interface)
*Edge
*Field
*Map
*Scalar
Value (interface)
Node : expvar.Var
Node : fmt.Stringer
func ParentBoard(n Node) Node
func (*Array).Copy(newParent Node) Node
func (*Array).Parent() Node
func Composite.Copy(newParent Node) Node
func Composite.Parent() Node
func (*Edge).Copy(newParent Node) Node
func (*Edge).Parent() Node
func (*Field).Copy(newParent Node) Node
func (*Field).Parent() Node
func (*Map).Copy(newParent Node) Node
func (*Map).Parent() Node
func (*Map).Query(idStr string) (Node, error)
func (*Map).QueryAll(idStr string) (na []Node, _ error)
func Node.Copy(newParent Node) Node
func Node.Parent() Node
func (*Scalar).Copy(newParent Node) Node
func (*Scalar).Parent() Node
func Value.Copy(newParent Node) Node
func Value.Parent() Node
func BoardIDA(n Node) (ida []d2ast.String)
func IDA(n Node) (ida []d2ast.String)
func IsVar(n Node) bool
func NodeBoardKind(n Node) BoardKind
func ParentBoard(n Node) Node
func ParentEdge(n Node) *Edge
func ParentField(n Node) *Field
func ParentMap(n Node) *Map
func ParentShape(n Node) string
func RelIDA(p, n Node) (ida []d2ast.String)
func (*Array).Copy(newParent Node) Node
func (*Array).Equal(n2 Node) bool
func Composite.Copy(newParent Node) Node
func Composite.Equal(n2 Node) bool
func (*Edge).Copy(newParent Node) Node
func (*Edge).Equal(n2 Node) bool
func (*Field).Copy(newParent Node) Node
func (*Field).Equal(n2 Node) bool
func (*Map).Copy(newParent Node) Node
func (*Map).CopyBase(newParent Node) *Map
func (*Map).Equal(n2 Node) bool
func Node.Copy(newParent Node) Node
func Node.Equal(n2 Node) bool
func (*Scalar).Copy(newParent Node) Node
func (*Scalar).Equal(n2 Node) bool
func Value.Copy(newParent Node) Node
func Value.Equal(n2 Node) bool
Edge *d2ast.Edge
Key *d2ast.Key
Scope *d2ast.Map
ScopeAST *d2ast.Map
ScopeMap *Map
(*RefContext) Copy() *RefContext
(*RefContext) EdgeIndex() int
(*RefContext) Equal(rc2 *RefContext) bool
func (*EdgeReference).Context() *RefContext
func (*FieldReference).Context() *RefContext
func (*RefContext).Copy() *RefContext
func Reference.Context() *RefContext
func (*Map).CreateEdge(eid *EdgeID, refctx *RefContext, c *compiler) ([]*Edge, error)
func (*Map).EnsureField(kp *d2ast.KeyPath, refctx *RefContext, create bool, c *compiler) ([]*Field, error)
func (*Map).GetEdges(eid *EdgeID, refctx *RefContext, c *compiler) []*Edge
func (*RefContext).Equal(rc2 *RefContext) bool
Most specific AST node for the reference.
( Reference) Context() *RefContext
Result of a glob in Context or from above.
( Reference) DueToLazyGlob() bool
( Reference) Primary() bool
*EdgeReference
*FieldReference
func (*Array).LastPrimaryRef() Reference
func (*Array).LastRef() Reference
func Composite.LastPrimaryRef() Reference
func Composite.LastRef() Reference
func (*Edge).LastPrimaryRef() Reference
func (*Edge).LastRef() Reference
func (*Field).LastPrimaryRef() Reference
func (*Field).LastRef() Reference
func (*Map).LastPrimaryRef() Reference
func (*Map).LastRef() Reference
func Node.LastPrimaryRef() Reference
func Node.LastRef() Reference
func (*Scalar).LastPrimaryRef() Reference
func (*Scalar).LastRef() Reference
func Value.LastPrimaryRef() Reference
func Value.LastRef() Reference
Value d2ast.Scalar
(*Scalar) AST() d2ast.Node
(*Scalar) Copy(newParent Node) Node
(*Scalar) Equal(n2 Node) bool
(*Scalar) LastPrimaryKey() *d2ast.Key
(*Scalar) LastPrimaryRef() Reference
(*Scalar) LastRef() Reference
(*Scalar) Map() *Map
(*Scalar) Parent() Node
(*Scalar) Primary() *Scalar
(*Scalar) String() string
*Scalar : Node
*Scalar : Value
*Scalar : expvar.Var
*Scalar : fmt.Stringer
func (*Array).Primary() *Scalar
func Composite.Primary() *Scalar
func (*Edge).Primary() *Scalar
func (*Field).Primary() *Scalar
func (*Map).Primary() *Scalar
func Node.Primary() *Scalar
func (*Scalar).Primary() *Scalar
func Value.Primary() *Scalar
( Value) AST() d2ast.Node
( Value) Copy(newParent Node) Node
( Value) Equal(n2 Node) bool
( Value) LastPrimaryKey() *d2ast.Key
( Value) LastPrimaryRef() Reference
( Value) LastRef() Reference
( Value) Map() *Map
( Value) Parent() Node
( Value) Primary() *Scalar
( Value) String() string
*Array
Composite (interface)
*Map
*Scalar
Value : Node
Value : expvar.Var
Value : fmt.Stringer
Package-Level Functions (total 19)
BoardIDA returns the absolute path to n from the nearest board root.
func ExpandSubstitution(m, resolved *Map, placeholder *Field)
IDA returns the absolute path to n.
func NewEdgeIDs(k *d2ast.Key) (eida []*EdgeID)
NodeBoardKind reports whether n represents the root of a board.
n should be *Field or *Map
OverlayEdge applies one edge overlay directly to another edge.
Deprecated: construct overlays as maps and apply them with OverlayMap.
OverlayEdge is an internal IR mutation detail and will be removed after one
compatibility release.
OverlayField applies one field overlay directly to another field.
Deprecated: construct overlays as maps and apply them with OverlayMap.
OverlayField is an internal IR mutation detail and will be removed after one
compatibility release.
func OverlayMap(base, overlay *Map) func ParentBoard(n Node) Node func ParentEdge(n Node) *Edge func ParentField(n Node) *Field func ParentShape(n Node) string
RelIDA returns the path to n relative to p.
ReserveVariableExpansionAliases accounts for logical IR nodes reached more
than once through composite aliases. It must run before graph materialization,
which turns those shared references into distinct graph objects.
ReserveVariableExpansionCopy accounts for the logical IR nodes an automatic
copy will materialize. It shares the same compilation-wide budget used by
substitutions and alias materialization.
Package-Level Variables (only one)
ErrImportsDisabled is returned when D2 source requests an import but the
caller did not provide CompileOptions.FS.
Package-Level Constants (total 8)
const BoardLayer BoardKind = "layer" const BoardScenario BoardKind = "scenario"
DefaultMaxEdgeExpansion is the maximum number of distinct edge-segment and
endpoint combinations that edge globs may consider during one compilation.
Explicit edges do not consume this budget because their work is proportional
to the input size. The limit is calibrated so a sparse star at the boundary
remains bounded in the built-in Dagre and ELK layouts, while larger wildcard
fanout stops before layout.
DefaultMaxEdgeExpansionWork is the maximum number of endpoint-pair
examinations edge globs may perform, including repeated lazy replays.
DefaultMaxGlobExpansion is the maximum amount of work globs may perform
during one compilation. Explicit source fields do not consume this budget.
DefaultMaxVariableExpansion is the maximum amount of work that variable
substitutions and the copies they induce may add to one compilation. One
work unit is one copied IR node or copied slice element, one inserted array
member, one produced string byte, one Markdown match candidate, or one byte
prepared for a Markdown variable lookup pattern.
MaxImportDepth is the maximum number of imported files permitted in one
active import chain. The root source file is not counted.
![]() |
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |