Documentation
¶
Overview ¶
Package d2ir implements a tree data structure to keep track of the resolved value of D2 keys.
Index ¶
- Constants
- Variables
- func ApplySequenceDeletions(ctx context.Context, scopes []*Map, accepts func(*Field) bool) error
- func BoardIDA(n Node) (ida []d2ast.String)
- func DeclarationOrder(n Node) ([]uint64, int)
- func ExpandSubstitution(m, resolved *Map, placeholder *Field)
- func IDA(n Node) (ida []d2ast.String)
- func IsVar(n Node) bool
- func OverlayEdge(be, oe *Edge)deprecated
- func OverlayField(bf, of *Field)deprecated
- func OverlayMap(base, overlay *Map)
- func OverlaySequenceActor(dst *Map, field *Field)
- func ParentShape(n Node) string
- func ParseAnimateInterval(value string) (int64, bool)
- func RelIDA(p, n Node) (ida []d2ast.String)
- func ReserveVariableExpansionAliases(ctx context.Context, m *Map) error
- func ReserveVariableExpansionCopy(ctx context.Context, m *Map) error
- type Array
- func (a *Array) AST() d2ast.Node
- func (a *Array) Copy(newParent Node) Node
- func (a *Array) Equal(n2 Node) bool
- func (n *Array) LastPrimaryKey() *d2ast.Key
- func (n *Array) LastPrimaryRef() Reference
- func (n *Array) LastRef() Reference
- func (n *Array) Map() *Map
- func (n *Array) Parent() Node
- func (n *Array) Primary() *Scalar
- func (n *Array) String() string
- type BoardKind
- type CompileOptions
- type Composite
- type Edge
- func (e *Edge) AST() d2ast.Node
- func (e *Edge) Copy(newParent Node) Node
- func (e *Edge) Equal(n2 Node) bool
- func (e *Edge) IDString() d2ast.String
- func (e *Edge) ImportAST() d2ast.Node
- func (e *Edge) LastPrimaryKey() *d2ast.Key
- func (e *Edge) LastPrimaryRef() Reference
- func (e *Edge) LastRef() Reference
- func (n *Edge) Map() *Map
- func (n *Edge) Parent() Node
- func (n *Edge) Primary() *Scalar
- func (e *Edge) SetImportAST(node d2ast.Node)
- func (n *Edge) String() string
- type EdgeID
- type EdgeReference
- type Field
- func (f *Field) AST() d2ast.Node
- func (f *Field) Copy(newParent Node) Node
- func (f *Field) Equal(n2 Node) bool
- func (f *Field) ImportAST() d2ast.Node
- func (f *Field) LastPrimaryKey() *d2ast.Key
- func (f *Field) LastPrimaryRef() Reference
- func (f *Field) LastRef() Reference
- func (n *Field) Map() *Map
- func (n *Field) Parent() Node
- func (n *Field) Primary() *Scalar
- func (f *Field) Root() bool
- func (f *Field) SequenceEndpointOnly() bool
- func (f *Field) SetImportAST(node d2ast.Node)
- func (f *Field) ShapeOptionsAfterPrimary() *Field
- func (n *Field) String() string
- type FieldReference
- func (fr *FieldReference) AST() d2ast.Node
- func (r *FieldReference) Context() *RefContext
- func (r *FieldReference) DueToGlob() bool
- func (r *FieldReference) DueToLazyGlob() bool
- func (fr *FieldReference) EdgeDest() bool
- func (fr *FieldReference) InEdge() bool
- func (fr *FieldReference) KeyPathIndex() int
- func (fr *FieldReference) Primary() bool
- type Importable
- type Map
- func (m *Map) AST() d2ast.Node
- func (m *Map) BoardAST(ctx context.Context) (*d2ast.Map, error)
- func (m *Map) Copy(newParent Node) Node
- func (m *Map) CopyBase(newParent Node) *Map
- func (m *Map) CreateEdge(eid *EdgeID, refctx *RefContext, c *compiler) ([]*Edge, error)
- func (m *Map) DeleteEdge(eid *EdgeID) *Edge
- func (m *Map) DeleteField(ida ...string) *Field
- func (m *Map) EdgeCountRecursive() int
- func (m *Map) EnsureField(kp *d2ast.KeyPath, refctx *RefContext, create bool, c *compiler) ([]*Field, error)
- func (m *Map) Equal(n2 Node) bool
- func (m *Map) FieldCountRecursive() int
- func (m *Map) FindBoardRoot(path []string) *Map
- func (m *Map) GetClassMap(name string) *Map
- func (m *Map) GetEdges(eid *EdgeID, refctx *RefContext, c *compiler) []*Edge
- func (m *Map) GetField(ida ...d2ast.String) *Field
- func (m *Map) HasClearedField(name string) bool
- func (m *Map) HasSequenceDeletions() bool
- func (m *Map) ImportAST() d2ast.Node
- func (m *Map) InClass(key *d2ast.Key) bool
- func (m *Map) IsClass() bool
- func (n *Map) LastPrimaryKey() *d2ast.Key
- func (n *Map) LastPrimaryRef() Reference
- func (n *Map) LastRef() Reference
- func (n *Map) Map() *Map
- func (n *Map) Parent() Node
- func (n *Map) Primary() *Scalar
- func (m *Map) Query(idStr string) (Node, error)
- func (m *Map) QueryAll(idStr string) (na []Node, _ error)
- func (m *Map) Root() bool
- func (m *Map) SetImportAST(node d2ast.Node)
- func (n *Map) String() string
- type Node
- type RefContext
- type Reference
- type Scalar
- func (s *Scalar) AST() d2ast.Node
- func (s *Scalar) Copy(newParent Node) Node
- func (s *Scalar) Equal(n2 Node) bool
- func (n *Scalar) LastPrimaryKey() *d2ast.Key
- func (n *Scalar) LastPrimaryRef() Reference
- func (n *Scalar) LastRef() Reference
- func (n *Scalar) Map() *Map
- func (n *Scalar) Parent() Node
- func (n *Scalar) Primary() *Scalar
- func (n *Scalar) String() string
- type SequenceShapeCache
- type Value
Constants ¶
const DefaultMaxEdgeExpansion int64 = 1_024
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.
const DefaultMaxEdgeExpansionWork int64 = 65_536
DefaultMaxEdgeExpansionWork is the maximum number of endpoint-pair examinations edge globs may perform, including repeated lazy replays.
const DefaultMaxGlobExpansion int64 = 65_536
DefaultMaxGlobExpansion is the maximum amount of work globs may perform during one compilation. Explicit source fields do not consume this budget.
const DefaultMaxVariableExpansion int64 = 65_536
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 slice element, one forward dependency, one inserted array member, one produced string byte, one Markdown match candidate, or one byte prepared for a Markdown variable lookup pattern.
const MaxImportDepth = 128
MaxImportDepth is the maximum number of imported files permitted in one active import chain. The root source file is not counted.
Variables ¶
var ErrImportsDisabled = errors.New("d2ir: imports are disabled; provide CompileOptions.FS to enable them")
ErrImportsDisabled is returned when D2 source requests an import but the caller did not provide CompileOptions.FS.
Functions ¶
func ApplySequenceDeletions ¶ added in v0.10.1
ApplySequenceDeletions shares null assignments among maps that declare the same participant or timeline item. The maps still have their original edges, which lets removal of an endpoint also remove its earlier messages.
func DeclarationOrder ¶ added in v0.10.1
DeclarationOrder gives the first authored occurrence of an object or connection after expanding imports and spreads, and its index in the reference list. Multiple endpoints of the same key use their literal position as a tiebreaker. Later style overrides do not move them.
func ExpandSubstitution ¶
func OverlayEdge
deprecated
func OverlayEdge(be, oe *Edge)
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.
func OverlayField
deprecated
func OverlayField(bf, of *Field)
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 ¶
func OverlayMap(base, overlay *Map)
func OverlaySequenceActor ¶ added in v0.10.1
OverlaySequenceActor moves an actor out of a v2 message frame. Its attributes may already have declarations in the diagram or another frame. Unlike a normal overlay, traversal order says nothing about which declaration wins.
func ParentShape ¶
ParentShape returns the canonical name of the shape of the nearest field containing n that sets one (see d2target.CanonicalShape).
func ParseAnimateInterval ¶ added in v0.10.0
ParseAnimateInterval returns the source interval in milliseconds. A bare integer uses milliseconds, matching the CLI flag.
func ReserveVariableExpansionAliases ¶ added in v0.10.0
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.
func ReserveVariableExpansionCopy ¶ added in v0.10.0
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.
Types ¶
type Array ¶
type Array struct {
Values []Value `json:"values"`
// contains filtered or unexported fields
}
func (*Array) LastPrimaryKey ¶
func (*Array) LastPrimaryRef ¶
type BoardKind ¶
type BoardKind string
func NodeBoardKind ¶
NodeBoardKind reports whether n represents the root of a board. n should be *Field or *Map
type CompileOptions ¶
type CompileOptions struct {
// ReportGlobWarning receives non-fatal source findings after a successful full compile.
ReportGlobWarning func(code string, r d2ast.Range, message string)
// ReportDeprecation receives deprecation warnings discovered during IR evaluation,
// such as deprecated shape or constraint names in glob filters.
ReportDeprecation func(code string, r d2ast.Range, message string)
// WarnUnmatchedGlob enables diagnostics for source style selectors that never matched.
WarnUnmatchedGlob bool
// Partial returns the IR built so far together with compile errors. It is
// for language tooling. A partial IR may be incomplete and must not be rendered.
Partial bool
// AnimateDuration overrides the root animate-duration, in milliseconds.
AnimateDuration *int64
// AnimateTweens controls sampling of step and scenario transitions. Nil follows
// the root animate-interval. False compiles only the authored endpoints.
AnimateTweens *bool
// Context stops parsing and compilation when canceled. A nil Context is
// treated as context.Background().
Context context.Context
UTF16Pos bool
// FixedPositionEncoding applies UTF16Pos to imports in all supported encodings.
FixedPositionEncoding bool
// MaxVariableExpansion bounds work added by substitutions and automatic
// copies. Zero uses DefaultMaxVariableExpansion.
MaxVariableExpansion int64
// MaxGlobExpansion bounds work performed by glob matching and
// materialization. Zero uses DefaultMaxGlobExpansion. Explicit source fields
// are not counted as materialization work.
MaxGlobExpansion int64
// MaxEdgeExpansion bounds distinct edge-segment and endpoint combinations
// considered by edge globs. Zero uses DefaultMaxEdgeExpansion. Explicit edges
// do not consume this budget.
MaxEdgeExpansion int64
// MaxEdgeExpansionWork bounds all endpoint-pair examinations performed by
// edge globs, including lazy replays. Zero uses DefaultMaxEdgeExpansionWork.
MaxEdgeExpansionWork int64
// FS resolves imports. Nil disables imports. The lib/localfile package
// provides rooted and explicit unrestricted host-filesystem policies. A filesystem
// may implement ResolveImportPath(parent, name string) string to use its own
// path syntax. Other filesystems receive slash-separated io/fs paths.
FS fs.FS
}
type Edge ¶
type Edge struct {
// SequenceKey retains the scoped, indexed source address through sequence actor hoisting.
SequenceKey *d2ast.Key `json:"-"`
ID *EdgeID `json:"edge_id"`
Primary_ *Scalar `json:"primary,omitempty"`
Map_ *Map `json:"map,omitempty"`
References []*EdgeReference `json:"references,omitempty"`
// contains filtered or unexported fields
}
func ParentEdge ¶
func (*Edge) LastPrimaryKey ¶
func (*Edge) LastPrimaryRef ¶
func (*Edge) SetImportAST ¶
type EdgeID ¶
type EdgeID struct {
SrcPath []d2ast.String `json:"src_path"`
SrcArrow bool `json:"src_arrow"`
DstPath []d2ast.String `json:"dst_path"`
DstArrow bool `json:"dst_arrow"`
// If nil, then any EdgeID with equal src/dst/arrows matches.
Index *int `json:"index"`
Glob bool `json:"glob"`
}
func NewEdgeIDs ¶
type EdgeReference ¶
type EdgeReference struct {
Context_ *RefContext `json:"context"`
DueToGlob_ bool `json:"due_to_glob"`
DueToLazyGlob_ bool `json:"due_to_lazy_glob"`
// contains filtered or unexported fields
}
func (*EdgeReference) AST ¶
func (er *EdgeReference) AST() d2ast.Node
func (*EdgeReference) Context ¶
func (r *EdgeReference) Context() *RefContext
func (*EdgeReference) DueToGlob ¶
func (r *EdgeReference) DueToGlob() bool
func (*EdgeReference) DueToLazyGlob ¶
func (r *EdgeReference) DueToLazyGlob() bool
func (*EdgeReference) Primary ¶
func (er *EdgeReference) Primary() bool
Primary returns true if the Value in Context.Key.Value corresponds to the *Edge represented by Context.Edge
type Field ¶
type Field struct {
Name d2ast.String `json:"name"`
// Primary_ to avoid clashing with Primary(). We need to keep it exported for
// encoding/json to marshal it so cannot prefix _ instead.
Primary_ *Scalar `json:"primary,omitempty"`
Composite Composite `json:"composite,omitempty"`
References []*FieldReference `json:"references,omitempty"`
// contains filtered or unexported fields
}
func LatestPrimary ¶ added in v0.10.1
LatestPrimary returns whichever of a and b has the later primary value assignment. If only one has a primary value, that field is returned.
func ParentField ¶
func (*Field) LastPrimaryKey ¶
func (*Field) LastPrimaryRef ¶
func (*Field) SequenceEndpointOnly ¶ added in v0.10.1
SequenceEndpointOnly reports an implicit participant introduced solely by message endpoints. Such a field beside a branch is not a branch declaration.
func (*Field) SetImportAST ¶
func (*Field) ShapeOptionsAfterPrimary ¶ added in v0.10.1
ShapeOptionsAfterPrimary returns a read-only view of f containing only shape options (and map literal opening) written at or after the assignment that established f's current shape type, or nil if no composite options remain after that assignment.
type FieldReference ¶
type FieldReference struct {
String d2ast.String `json:"string"`
KeyPath *d2ast.KeyPath `json:"key_path"`
Context_ *RefContext `json:"context"`
DueToGlob_ bool `json:"due_to_glob"`
DueToLazyGlob_ bool `json:"due_to_lazy_glob"`
// contains filtered or unexported fields
}
func (*FieldReference) AST ¶
func (fr *FieldReference) AST() d2ast.Node
func (*FieldReference) Context ¶
func (r *FieldReference) Context() *RefContext
func (*FieldReference) DueToGlob ¶
func (r *FieldReference) DueToGlob() bool
func (*FieldReference) DueToLazyGlob ¶
func (r *FieldReference) DueToLazyGlob() bool
func (*FieldReference) EdgeDest ¶
func (fr *FieldReference) EdgeDest() bool
func (*FieldReference) InEdge ¶
func (fr *FieldReference) InEdge() bool
func (*FieldReference) KeyPathIndex ¶
func (fr *FieldReference) KeyPathIndex() int
func (*FieldReference) Primary ¶
func (fr *FieldReference) Primary() bool
Primary returns true if the Value in Context.Key.Value corresponds to the Field represented by String.
type Map ¶
type Map struct {
// TweenFrames are fully resolved, read-only samples of this board's incoming
// transition. They are shared across IR copies, outside the authored board tree.
TweenFrames []*Map `json:"-"`
TweenDurationMS int `json:"-"`
Fields []*Field `json:"fields"`
Edges []*Edge `json:"edges"`
// contains filtered or unexported fields
}
func EditGraphScopes ¶ added in v0.10.1
func EditGraphScopes(ctx context.Context, root *Map, scopes map[*Map]bool, owned bool, edit func(*Map) error) (*Map, error)
EditGraphScopes materializes selected submaps for graph normalization. A true entry selects the whole scope; false marks an ancestor on the way to one. Other maps are read-only during graph compilation and can be shared.
func (*Map) BoardAST ¶ added in v0.10.1
BoardAST builds the editor's flattened source for an authored board. A nested board can occur in several ancestors' ASTs, so reserve each logical occurrence before allocating it. AST() shares field names and scalar values and does not copy IR source-reference histories.
func (*Map) CreateEdge ¶
func (m *Map) CreateEdge(eid *EdgeID, refctx *RefContext, c *compiler) ([]*Edge, error)
func (*Map) DeleteEdge ¶
func (*Map) DeleteField ¶
func (*Map) EdgeCountRecursive ¶
func (*Map) EnsureField ¶
func (m *Map) EnsureField(kp *d2ast.KeyPath, refctx *RefContext, create bool, c *compiler) ([]*Field, error)
EnsureField is a bit of a misnomer. It's more of a Query/Ensure combination function at this point.
func (*Map) FieldCountRecursive ¶
func (*Map) FindBoardRoot ¶
func (*Map) GetClassMap ¶
func (*Map) HasClearedField ¶ added in v0.10.1
HasClearedField reports whether the unquoted shape option name was explicitly cleared with null in this map and not subsequently reassigned.
func (*Map) HasSequenceDeletions ¶ added in v0.10.1
HasSequenceDeletions reports whether this occurrence has field deletions to reconcile with declarations from other frames.
func (*Map) LastPrimaryKey ¶
func (*Map) LastPrimaryRef ¶
func (*Map) SetImportAST ¶
type Node ¶
type Node interface {
Copy(newParent Node) Node
Parent() Node
Primary() *Scalar
Map() *Map
Equal(n2 Node) bool
AST() d2ast.Node
fmt.Stringer
LastRef() Reference
LastPrimaryRef() Reference
LastPrimaryKey() *d2ast.Key
// contains filtered or unexported methods
}
Most errors returned by a node should be created with d2parser.Errorf to indicate the offending AST node.
func ParentBoard ¶
type RefContext ¶
type RefContext struct {
Edge *d2ast.Edge `json:"edge"`
Key *d2ast.Key `json:"key"`
Scope *d2ast.Map `json:"-"`
ScopeMap *Map `json:"-"`
ScopeAST *d2ast.Map `json:"-"`
// contains filtered or unexported fields
}
func (*RefContext) Copy ¶
func (rc *RefContext) Copy() *RefContext
func (*RefContext) EdgeIndex ¶
func (rc *RefContext) EdgeIndex() int
func (*RefContext) Equal ¶
func (rc *RefContext) Equal(rc2 *RefContext) bool
type Scalar ¶
type Scalar struct {
Value d2ast.Scalar `json:"value"`
// BoardLinkSource retains the spelling before resolution against a declaration or import.
BoardLinkSource string `json:"-"`
// TweenOffset retains precision lost when formatting a numeric sample for
// text. Continuous paint properties can use it for the unrounded value.
TweenOffset float64 `json:"-"`
// NumericTween identifies interpolated numbers, including samples that land on an integer.
NumericTween bool `json:"-"`
// contains filtered or unexported fields
}
func (*Scalar) LastPrimaryKey ¶
func (*Scalar) LastPrimaryRef ¶
type SequenceShapeCache ¶ added in v0.10.1
type SequenceShapeCache map[*Map]sequenceClassState
SequenceShapeCache resolves the same class-provided shape and branch options for glob matching and for the subsequent graph normalization.
Source Files
¶
- compile.go
- d2ir.go
- edge_expansion.go
- expansion.go
- field_order.go
- glob_expansion.go
- glob_filter_variables.go
- graph_scopes.go
- import.go
- import_cache.go
- markdown.go
- markdown_binding.go
- merge.go
- pattern.go
- query.go
- recursive_edge_selector.go
- sequence_delete.go
- sequence_globs.go
- shape_options.go
- spread_delete.go
- spread_edge_rules.go
- spread_null.go
- spread_reset.go
- tween.go
- tween_paint.go
- tween_style.go
- tween_variables_scenario.go
- warn_globs.go