d2ir

package
v0.0.0-...-e815181 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2023 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package d2ir implements a tree data structure to keep track of the resolved value of D2 keys.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoardIDA

func BoardIDA(n Node) (ida []string)

BoardIDA returns the absolute path to n from the nearest board root.

func IDA

func IDA(n Node) (ida []string)

IDA returns the absolute path to n.

func IsVar

func IsVar(n Node) bool

func OverlayEdge

func OverlayEdge(be, oe *Edge)

func OverlayField

func OverlayField(bf, of *Field)

func OverlayMap

func OverlayMap(base, overlay *Map)

func RelIDA

func RelIDA(p, n Node) (ida []string)

RelIDA returns the path to n relative to p.

Types

type Array

type Array struct {
	Values []Value `json:"values"`
	// contains filtered or unexported fields
}

func (*Array) AST

func (a *Array) AST() d2ast.Node

func (*Array) Copy

func (a *Array) Copy(newParent Node) Node

func (*Array) Equal

func (a *Array) Equal(n2 Node) bool

func (*Array) LastPrimaryKey

func (n *Array) LastPrimaryKey() *d2ast.Key

func (*Array) LastRef

func (n *Array) LastRef() Reference

func (*Array) Map

func (n *Array) Map() *Map

func (*Array) Parent

func (n *Array) Parent() Node

func (*Array) Primary

func (n *Array) Primary() *Scalar

func (*Array) String

func (n *Array) String() string

type BoardKind

type BoardKind string
const (
	BoardLayer    BoardKind = "layer"
	BoardScenario BoardKind = "scenario"
	BoardStep     BoardKind = "step"
)

func NodeBoardKind

func NodeBoardKind(n Node) BoardKind

NodeBoardKind reports whether n represents the root of a board. n should be *Field or *Map

type CompileOptions

type CompileOptions struct {
	UTF16Pos bool
	// Pass nil to disable imports.
	FS fs.FS
}

type Composite

type Composite interface {
	Node
	Value
	// contains filtered or unexported methods
}

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 ParentEdge(n Node) *Edge

func (*Edge) AST

func (e *Edge) AST() d2ast.Node

func (*Edge) Copy

func (e *Edge) Copy(newParent Node) Node

func (*Edge) Equal

func (e *Edge) Equal(n2 Node) bool

func (*Edge) LastPrimaryKey

func (e *Edge) LastPrimaryKey() *d2ast.Key

func (*Edge) LastRef

func (e *Edge) LastRef() Reference

func (*Edge) Map

func (n *Edge) Map() *Map

func (*Edge) Parent

func (n *Edge) Parent() Node

func (*Edge) Primary

func (n *Edge) Primary() *Scalar

func (*Edge) String

func (n *Edge) String() string

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"`
	Glob  bool `json:"glob"`
}

func NewEdgeIDs

func NewEdgeIDs(k *d2ast.Key) (eida []*EdgeID)

func (*EdgeID) Copy

func (eid *EdgeID) Copy() *EdgeID

func (*EdgeID) Match

func (eid *EdgeID) Match(eid2 *EdgeID) bool

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 ParentField(n Node) *Field

func (*Field) AST

func (f *Field) AST() d2ast.Node

func (*Field) Copy

func (f *Field) Copy(newParent Node) Node

func (*Field) Equal

func (f *Field) Equal(n2 Node) bool

func (*Field) LastPrimaryKey

func (f *Field) LastPrimaryKey() *d2ast.Key

func (*Field) LastRef

func (f *Field) LastRef() Reference

func (*Field) Map

func (n *Field) Map() *Map

func (*Field) Parent

func (n *Field) Parent() Node

func (*Field) Primary

func (n *Field) Primary() *Scalar

func (*Field) Root

func (f *Field) Root() bool

func (*Field) String

func (n *Field) String() string

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 Compile

func Compile(ast *d2ast.Map, opts *CompileOptions) (*Map, error)

func ParentMap

func ParentMap(n Node) *Map

func RootMap

func RootMap(m *Map) *Map

func (*Map) AST

func (m *Map) AST() d2ast.Node

func (*Map) Copy

func (m *Map) Copy(newParent Node) Node

func (*Map) CopyBase

func (m *Map) CopyBase(newParent Node) *Map

CopyBase copies the map m without layers/scenarios/steps.

func (*Map) CreateEdge

func (m *Map) CreateEdge(eid *EdgeID, refctx *RefContext) ([]*Edge, error)

func (*Map) DeleteEdge

func (m *Map) DeleteEdge(eid *EdgeID) *Edge

func (*Map) DeleteField

func (m *Map) DeleteField(ida ...string) *Field

func (*Map) EdgeCountRecursive

func (m *Map) EdgeCountRecursive() int

func (*Map) EnsureField

func (m *Map) EnsureField(kp *d2ast.KeyPath, refctx *RefContext, create bool) ([]*Field, error)

EnsureField is a bit of a misnomer. It's more of a Query/Ensure combination function at this point.

func (*Map) Equal

func (m *Map) Equal(n2 Node) bool

func (*Map) FieldCountRecursive

func (m *Map) FieldCountRecursive() int

func (*Map) GetClassMap

func (m *Map) GetClassMap(name string) *Map

func (*Map) GetEdges

func (m *Map) GetEdges(eid *EdgeID, refctx *RefContext) []*Edge

func (*Map) GetField

func (m *Map) GetField(ida ...string) *Field

func (*Map) InClass

func (m *Map) InClass(key *d2ast.Key) bool

func (*Map) IsClass

func (m *Map) IsClass() bool

func (*Map) IsContainer

func (m *Map) IsContainer() bool

func (*Map) LastPrimaryKey

func (n *Map) LastPrimaryKey() *d2ast.Key

func (*Map) LastRef

func (n *Map) LastRef() Reference

func (*Map) Map

func (n *Map) Map() *Map

func (*Map) Parent

func (n *Map) Parent() Node

func (*Map) Primary

func (n *Map) Primary() *Scalar

func (*Map) Query

func (m *Map) Query(idStr string) (Node, error)

Query is only for tests and debugging.

func (*Map) QueryAll

func (m *Map) QueryAll(idStr string) (na []Node, _ error)

QueryAll is only for tests and debugging.

func (*Map) Root

func (m *Map) Root() bool

Root reports whether the Map is the root of the D2 tree.

func (*Map) String

func (n *Map) String() string

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
	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

func ParentBoard(n Node) Node

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:"-"`
}

func (*RefContext) Copy

func (rc *RefContext) Copy() *RefContext

func (*RefContext) EdgeIndex

func (rc *RefContext) EdgeIndex() int

type Reference

type Reference interface {

	// Most specific AST node for the reference.
	AST() d2ast.Node
	Primary() bool
	// contains filtered or unexported methods
}

type Scalar

type Scalar struct {
	Value d2ast.Scalar `json:"value"`
	// contains filtered or unexported fields
}

func (*Scalar) AST

func (s *Scalar) AST() d2ast.Node

func (*Scalar) Copy

func (s *Scalar) Copy(newParent Node) Node

func (*Scalar) Equal

func (s *Scalar) Equal(n2 Node) bool

func (*Scalar) LastPrimaryKey

func (n *Scalar) LastPrimaryKey() *d2ast.Key

func (*Scalar) LastRef

func (n *Scalar) LastRef() Reference

func (*Scalar) Map

func (n *Scalar) Map() *Map

func (*Scalar) Parent

func (n *Scalar) Parent() Node

func (*Scalar) Primary

func (n *Scalar) Primary() *Scalar

func (*Scalar) String

func (n *Scalar) String() string

type Value

type Value interface {
	Node
	// contains filtered or unexported methods
}

Jump to

Keyboard shortcuts

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