Documentation
¶
Overview ¶
Package d2ir implements a tree data structure to keep track of the resolved value of D2 keys.
Index ¶
- func BoardIDA(n Node) (ida []string)
- func IDA(n Node) (ida []string)
- func OverlayEdge(be, oe *Edge)
- func OverlayField(bf, of *Field)
- func OverlayMap(base, overlay *Map)
- type Array
- type BoardKind
- type Composite
- type Edge
- type EdgeID
- type EdgeReference
- type Field
- func (f *Field) Copy(newParent Node) Node
- func (f *Field) Equal(n2 Node) bool
- func (f *Field) LastPrimaryKey() *d2ast.Key
- 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 (n *Field) String() string
- type FieldReference
- type Map
- func (m *Map) Copy(newParent Node) Node
- func (m *Map) CopyBase(newParent Node) *Map
- func (m *Map) CreateEdge(eid *EdgeID, refctx *RefContext) (*Edge, error)
- func (m *Map) DeleteField(ida ...string) *Field
- func (m *Map) EdgeCountRecursive() int
- func (m *Map) EnsureField(kp *d2ast.KeyPath, refctx *RefContext) (*Field, error)
- func (m *Map) Equal(n2 Node) bool
- func (m *Map) FieldCountRecursive() int
- func (m *Map) GetEdges(eid *EdgeID) []*Edge
- func (m *Map) GetField(ida ...string) *Field
- func (n *Map) LastPrimaryKey() *d2ast.Key
- 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 (n *Map) String() string
- type Node
- type RefContext
- type Reference
- type Scalar
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BoardIDA ¶ added in v0.2.4
BoardIDA returns the absolute path to n from the nearest board root.
func OverlayEdge ¶
func OverlayEdge(be, oe *Edge)
func OverlayField ¶
func OverlayField(bf, of *Field)
func OverlayMap ¶
func OverlayMap(base, overlay *Map)
Types ¶
type Array ¶
type Array struct {
Values []Value `json:"values"`
// contains filtered or unexported fields
}
func (*Array) LastPrimaryKey ¶
type BoardKind ¶
type BoardKind string
func NodeBoardKind ¶
NodeBoardKind reports whether n represents the root of a board. n should be *Field or *Map
type Edge ¶
type Edge struct {
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 ¶
type EdgeID ¶
type EdgeID struct {
SrcPath []string `json:"src_path"`
SrcArrow bool `json:"src_arrow"`
DstPath []string `json:"dst_path"`
DstArrow bool `json:"dst_arrow"`
// If nil, then any EdgeID with equal src/dst/arrows matches.
Index *int `json:"index"`
}
func NewEdgeIDs ¶
type EdgeReference ¶
type EdgeReference struct {
Context *RefContext `json:"context"`
}
func (*EdgeReference) AST ¶
func (er *EdgeReference) AST() d2ast.Node
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 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 ParentField ¶
func (*Field) LastPrimaryKey ¶
type FieldReference ¶
type FieldReference struct {
String d2ast.String `json:"string"`
KeyPath *d2ast.KeyPath `json:"key_path"`
Context *RefContext `json:"context"`
}
func (*FieldReference) AST ¶
func (fr *FieldReference) AST() d2ast.Node
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 {
Fields []*Field `json:"fields"`
Edges []*Edge `json:"edges"`
// contains filtered or unexported fields
}
func (*Map) CreateEdge ¶
func (m *Map) CreateEdge(eid *EdgeID, refctx *RefContext) (*Edge, error)
func (*Map) DeleteField ¶
func (*Map) EdgeCountRecursive ¶
func (*Map) EnsureField ¶
func (*Map) FieldCountRecursive ¶
func (*Map) LastPrimaryKey ¶
type Node ¶
type Node interface {
Copy(newParent Node) Node
Parent() Node
Primary() *Scalar
Map() *Map
Equal(n2 Node) bool
fmt.Stringer
LastRef() 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:"-"`
}
func (*RefContext) Copy ¶
func (rc *RefContext) Copy() *RefContext
func (*RefContext) EdgeIndex ¶
func (rc *RefContext) EdgeIndex() int
type Scalar ¶
func (*Scalar) LastPrimaryKey ¶
Click to show internal directories.
Click to hide internal directories.