package d2ast
Import Path
oss.terrastruct.com/d2/d2ast (on go.dev)
Dependency Relation
imports 13 packages, and imported by 7 packages
Involved Source Files
TODO: Remove boxes and cleanup like d2ir
d2ast implements the d2 language's abstract syntax tree.
Special characters to think about in parser:
#
"""
;
[]
{}
|
$
'
"
\
:
.
--
<>
*
&
()
error.go
keywords.go
Package-Level Type Names (total 32)
Nodes []ArrayNodeBox
Range Range
(*Array) Children() []Node
(*Array) GetRange() Range
(*Array) Type() string
*Array : ArrayNode
*Array : Node
*Array : Value
ArrayNode is implemented by nodes that may be children of Arrays.
( ArrayNode) Children() []Node
GetRange returns the range a node occupies in its file.
Type returns the user friendly name of the node.
*Array
*BlockComment
*BlockString
*Boolean
*Comment
*DoubleQuotedString
*Import
*Map
*Null
*Number
Scalar (interface)
*SingleQuotedString
String (interface)
*Substitution
*UnquotedString
Value (interface)
ArrayNode : Node
func ArrayNodeBox.Unbox() ArrayNode
func MakeArrayNodeBox(an ArrayNode) ArrayNodeBox
ArrayNodeBox is used to box ArrayNode for JSON persistence.
Array *Array
BlockComment *BlockComment
BlockString *BlockString
Boolean *Boolean
Comment *Comment
DoubleQuotedString *DoubleQuotedString
Import *Import
Map *Map
Null *Null
Number *Number
SingleQuotedString *SingleQuotedString
Substitution *Substitution
UnquotedString *UnquotedString
( ArrayNodeBox) Unbox() ArrayNode
func MakeArrayNodeBox(an ArrayNode) ArrayNodeBox
Range Range
Value string
(*BlockComment) Children() []Node
(*BlockComment) GetRange() Range
(*BlockComment) Type() string
*BlockComment : ArrayNode
*BlockComment : MapNode
*BlockComment : Node
Quote contains the pipe delimiter for the block string.
e.g. if 5 pipes were used to begin a block string, then Quote == "||||".
The tag is not included.
Range Range
Tag string
Value string
(*BlockString) Children() []Node
(*BlockString) Copy() String
(*BlockString) GetRange() Range
(*BlockString) IsUnquoted() bool
(*BlockString) ScalarString() string
(*BlockString) SetString(s2 string)
(*BlockString) Type() string
*BlockString : ArrayNode
*BlockString : Node
*BlockString : Scalar
*BlockString : String
*BlockString : Value
Range Range
Value bool
(*Boolean) Children() []Node
(*Boolean) GetRange() Range
(*Boolean) ScalarString() string
(*Boolean) Type() string
*Boolean : ArrayNode
*Boolean : Node
*Boolean : Scalar
*Boolean : Value
Range Range
Value string
(*Comment) Children() []Node
(*Comment) GetRange() Range
(*Comment) Type() string
*Comment : ArrayNode
*Comment : MapNode
*Comment : Node
Range Range
Value []InterpolationBox
(*DoubleQuotedString) Children() []Node
(*DoubleQuotedString) Coalesce()
(*DoubleQuotedString) Copy() String
(*DoubleQuotedString) GetRange() Range
(*DoubleQuotedString) IsUnquoted() bool
(*DoubleQuotedString) ScalarString() string
(*DoubleQuotedString) SetString(s2 string)
(*DoubleQuotedString) Type() string
*DoubleQuotedString : ArrayNode
*DoubleQuotedString : Node
*DoubleQuotedString : Scalar
*DoubleQuotedString : String
*DoubleQuotedString : Value
func FlatDoubleQuotedString(s string) *DoubleQuotedString
Dst *KeyPath
empty, > or *
Range Range
Src *KeyPath
empty, < or *
(*Edge) Children() []Node
(*Edge) Equals(e2 *Edge) bool
(*Edge) GetRange() Range
(*Edge) Type() string
*Edge : Node
func oss.terrastruct.com/d2/d2graph.(*Edge).GetAstEdge() *Edge
func (*Edge).Equals(e2 *Edge) bool
Glob bool
[n] or [*]
Range Range
(*EdgeIndex) Children() []Node
(*EdgeIndex) Equals(ei2 *EdgeIndex) bool
(*EdgeIndex) GetRange() Range
(*EdgeIndex) Type() string
*EdgeIndex : Node
func (*EdgeIndex).Equals(ei2 *EdgeIndex) bool
TODO: Right now this is here to be available in both the Parser and Compiler but
eventually we should make this a real part of the AST so that autofmt works on
files with parse errors and semantically it makes more sense.
Compile would continue to maintain a separate set of errors and then we'd do a
merge & sort to get the final list of errors for user display.
Message string
Range Range
( Error) Error() string
Error : error
Path []*StringBox
Pre string
Range Range
Spread bool
(*Import) Children() []Node
(*Import) Dir() string
(*Import) GetRange() Range
(*Import) IDA() (ida []String)
(*Import) PathWithPre() string
(*Import) Type() string
*Import : ArrayNode
*Import : MapNode
*Import : Node
*Import : Value
InterpolationBox is used to select between strings and substitutions in unquoted and
double quoted strings. There is no corresponding interface to avoid unnecessary
abstraction.
String *string
StringRaw *string
Substitution *Substitution
TODO: require @ on import values for readability
Indicates this MapKey is a filter selector.
EdgeIndex *EdgeIndex
EdgeKey *KeyPath
Edges []*Edge
At least one of Key and Edges will be set but all four can also be set.
The following are all valid MapKeys:
Key:
x
Edges:
x -> y
Edges and EdgeIndex:
(x -> y)[*]
Edges and EdgeKey:
(x -> y).label
Key and Edges:
container.(x -> y)
Key, Edges and EdgeKey:
container.(x -> y -> z).label
Key, Edges, EdgeIndex EdgeKey:
container.(x -> y -> z)[4].label
Indicates this MapKey is a not filter selector.
Primary ScalarBox
Range Range
Value ValueBox
(*Key) Children() []Node
(*Key) Copy() *Key
(*Key) D2OracleEquals(mk2 *Key) bool
(*Key) Equals(mk2 *Key) bool
(*Key) GetRange() Range
(*Key) HasGlob() bool
(*Key) HasMultiGlob() bool
(*Key) HasTripleGlob() bool
(*Key) SetScalar(scalar ScalarBox)
(*Key) SupportsGlobFilters() bool
(*Key) Type() string
*Key : MapNode
*Key : Node
func (*Key).Copy() *Key
func oss.terrastruct.com/d2/d2ir.(*Array).LastPrimaryKey() *Key
func oss.terrastruct.com/d2/d2ir.Composite.LastPrimaryKey() *Key
func oss.terrastruct.com/d2/d2ir.(*Edge).LastPrimaryKey() *Key
func oss.terrastruct.com/d2/d2ir.(*Field).LastPrimaryKey() *Key
func oss.terrastruct.com/d2/d2ir.(*Map).LastPrimaryKey() *Key
func oss.terrastruct.com/d2/d2ir.Node.LastPrimaryKey() *Key
func oss.terrastruct.com/d2/d2ir.(*Scalar).LastPrimaryKey() *Key
func oss.terrastruct.com/d2/d2ir.Value.LastPrimaryKey() *Key
func oss.terrastruct.com/d2/d2parser.ParseMapKey(mapKey string) (*Key, error)
func (*Key).D2OracleEquals(mk2 *Key) bool
func (*Key).Equals(mk2 *Key) bool
func oss.terrastruct.com/d2/d2graph.(*Object).FindEdges(mk *Key) ([]*d2graph.Edge, bool)
func oss.terrastruct.com/d2/d2graph.(*Object).HasEdge(mk *Key) (*d2graph.Edge, bool)
func oss.terrastruct.com/d2/d2ir.NewEdgeIDs(k *Key) (eida []*d2ir.EdgeID)
func oss.terrastruct.com/d2/d2ir.(*Map).InClass(key *Key) bool
Path []*StringBox
Range Range
(*KeyPath) Children() []Node
(*KeyPath) Copy() *KeyPath
(*KeyPath) Equals(kp2 *KeyPath) bool
(*KeyPath) FirstGlob() int
(*KeyPath) GetRange() Range
(*KeyPath) HasGlob() bool
(*KeyPath) HasMultiGlob() bool
(*KeyPath) HasTripleGlob() bool
(*KeyPath) IDA() (ida []String)
(*KeyPath) Last() *StringBox
(*KeyPath) StringIDA() (ida []string)
(*KeyPath) Type() string
*KeyPath : Node
func MakeKeyPath(a []string) *KeyPath
func MakeKeyPathString(a []String) *KeyPath
func (*KeyPath).Copy() *KeyPath
func oss.terrastruct.com/d2/d2parser.ParseKey(key string) (*KeyPath, error)
func (*KeyPath).Equals(kp2 *KeyPath) bool
func oss.terrastruct.com/d2/d2format.KeyPath(kp *KeyPath) (ida []string)
func oss.terrastruct.com/d2/d2graph.Key(k *KeyPath) []string
func oss.terrastruct.com/d2/d2ir.(*Map).EnsureField(kp *KeyPath, refctx *d2ir.RefContext, create bool, c *d2ir.compiler) ([]*d2ir.Field, error)
Nodes []MapNodeBox
Range Range
(*Map) Children() []Node
(*Map) GetRange() Range
(*Map) HasFilter() bool
(*Map) InsertAfter(cursor, n MapNode)
(*Map) InsertBefore(cursor, n MapNode)
(*Map) IsFileMap() bool
(*Map) Type() string
*Map : ArrayNode
*Map : Node
*Map : Value
func oss.terrastruct.com/d2/d2lib.Parse(ctx context.Context, input string, compileOpts *d2lib.CompileOptions) (*Map, error)
func oss.terrastruct.com/d2/d2parser.Parse(path string, r io.Reader, opts *d2parser.ParseOptions) (*Map, error)
func oss.terrastruct.com/d2/d2ir.Compile(ast *Map, opts *d2ir.CompileOptions) (*d2ir.Map, []string, error)
MapNode is implemented by nodes that may be children of Maps.
( MapNode) Children() []Node
GetRange returns the range a node occupies in its file.
Type returns the user friendly name of the node.
*BlockComment
*Comment
*Import
*Key
*Substitution
MapNode : Node
func MapNodeBox.Unbox() MapNode
func MakeMapNodeBox(n MapNode) MapNodeBox
func (*Map).InsertAfter(cursor, n MapNode)
func (*Map).InsertBefore(cursor, n MapNode)
MapNodeBox is used to box MapNode for JSON persistence.
BlockComment *BlockComment
Comment *Comment
Import *Import
MapKey *Key
Substitution *Substitution
( MapNodeBox) IsBoardNode() bool
( MapNodeBox) Unbox() MapNode
func MakeMapNodeBox(n MapNode) MapNodeBox
Node is the base interface implemented by all d2 AST nodes.
TODO: add error node for autofmt of incomplete AST
( Node) Children() []Node
GetRange returns the range a node occupies in its file.
Type returns the user friendly name of the node.
*Array
ArrayNode (interface)
*BlockComment
*BlockString
*Boolean
*Comment
*DoubleQuotedString
*Edge
*EdgeIndex
*Import
*Key
*KeyPath
*Map
MapNode (interface)
*Null
*Number
Scalar (interface)
*SingleQuotedString
String (interface)
*Substitution
*UnquotedString
Value (interface)
func (*Array).Children() []Node
func ArrayNode.Children() []Node
func (*BlockComment).Children() []Node
func (*BlockString).Children() []Node
func (*Boolean).Children() []Node
func (*Comment).Children() []Node
func (*DoubleQuotedString).Children() []Node
func (*Edge).Children() []Node
func (*EdgeIndex).Children() []Node
func (*Import).Children() []Node
func (*Key).Children() []Node
func (*KeyPath).Children() []Node
func (*Map).Children() []Node
func MapNode.Children() []Node
func Node.Children() []Node
func (*Null).Children() []Node
func (*Number).Children() []Node
func Scalar.Children() []Node
func (*SingleQuotedString).Children() []Node
func String.Children() []Node
func (*Substitution).Children() []Node
func (*UnquotedString).Children() []Node
func Value.Children() []Node
func oss.terrastruct.com/d2/d2ir.(*Array).AST() Node
func oss.terrastruct.com/d2/d2ir.Composite.AST() Node
func oss.terrastruct.com/d2/d2ir.(*Edge).AST() Node
func oss.terrastruct.com/d2/d2ir.(*Edge).ImportAST() Node
func oss.terrastruct.com/d2/d2ir.(*EdgeReference).AST() Node
func oss.terrastruct.com/d2/d2ir.(*Field).AST() Node
func oss.terrastruct.com/d2/d2ir.(*Field).ImportAST() Node
func oss.terrastruct.com/d2/d2ir.(*FieldReference).AST() Node
func oss.terrastruct.com/d2/d2ir.Importable.ImportAST() Node
func oss.terrastruct.com/d2/d2ir.(*Map).AST() Node
func oss.terrastruct.com/d2/d2ir.(*Map).ImportAST() Node
func oss.terrastruct.com/d2/d2ir.Node.AST() Node
func oss.terrastruct.com/d2/d2ir.Reference.AST() Node
func oss.terrastruct.com/d2/d2ir.(*Scalar).AST() Node
func oss.terrastruct.com/d2/d2ir.Value.AST() Node
func Walk(node Node, fn func(Node) bool)
func oss.terrastruct.com/d2/d2format.Format(n Node) string
func oss.terrastruct.com/d2/d2ir.(*Edge).SetImportAST(node Node)
func oss.terrastruct.com/d2/d2ir.(*Field).SetImportAST(node Node)
func oss.terrastruct.com/d2/d2ir.Importable.SetImportAST(Node)
func oss.terrastruct.com/d2/d2ir.(*Map).SetImportAST(node Node)
func oss.terrastruct.com/d2/d2parser.Errorf(n Node, f string, v ...interface{}) error
Range Range
(*Null) Children() []Node
(*Null) GetRange() Range
TODO: mistake, move into parse.go
(*Null) Type() string
*Null : ArrayNode
*Null : Node
*Null : Scalar
*Null : Value
Range Range
Raw string
Value *big.Rat
(*Number) Children() []Node
(*Number) GetRange() Range
(*Number) ScalarString() string
(*Number) Type() string
*Number : ArrayNode
*Number : Node
*Number : Scalar
*Number : Value
Position represents a line:column and byte position in a file.
note: Line and Column are zero indexed.
note: Column and Byte are UTF-8 byte indexes unless byUTF16 was passed to Position.Advance in
. which they are UTF-16 code unit indexes.
. If intended for Javascript consumption like in the browser or via LSP, byUTF16 is
. set to true.
-1 is used as sentinel that a constructed position is missing byte offset (for LSP usage)
Column int
Line int
Advance advances p's Line, Column and Byte by r and returns
the new Position.
Set byUTF16 to advance the position as though r represents
a UTF-16 codepoint.
( Position) AdvanceString(s string, byUTF16 bool) Position
( Position) Before(p2 Position) bool
( Position) Debug() string
From copies src into p. It's used in the d2parser package to set a node's Range.End to
the parser's current pos on all return paths with defer.
See docs on Range.
String returns a line:column representation of the position suitable for error messages.
note: Should not normally be used directly, see Range.String()
( Position) Subtract(r rune, byUTF16 bool) Position
( Position) SubtractString(s string, byUTF16 bool) Position
See docs on Range.
Position : encoding.TextMarshaler
*Position : encoding.TextUnmarshaler
Position : expvar.Var
Position : fmt.Stringer
func Position.Advance(r rune, byUTF16 bool) Position
func Position.AdvanceString(s string, byUTF16 bool) Position
func Position.Subtract(r rune, byUTF16 bool) Position
func Position.SubtractString(s string, byUTF16 bool) Position
func Position.Before(p2 Position) bool
func (*Position).From(src *Position)
Range represents a range between Start and End in Path.
It's also used in the d2parser package to represent the range of an error.
note: See docs on Position.
It has a custom JSON string encoding with encoding.TextMarshaler and
encoding.TextUnmarshaler to keep it compact as the JSON struct encoding is too verbose,
especially with json.MarshalIndent.
It looks like path,start-end
End Position
Path string
Start Position
( Range) Before(r2 Range) bool
See docs on Range.
OneLine returns true if the Range starts and ends on the same line.
String returns a string representation of the range including only the path and start.
If path is empty, it will be omitted.
The format is path:start
See docs on Range.
Range : encoding.TextMarshaler
*Range : encoding.TextUnmarshaler
Range : expvar.Var
Range : fmt.Stringer
func MakeRange(s string) Range
func (*Array).GetRange() Range
func ArrayNode.GetRange() Range
func (*BlockComment).GetRange() Range
func (*BlockString).GetRange() Range
func (*Boolean).GetRange() Range
func (*Comment).GetRange() Range
func (*DoubleQuotedString).GetRange() Range
func (*Edge).GetRange() Range
func (*EdgeIndex).GetRange() Range
func (*Import).GetRange() Range
func (*Key).GetRange() Range
func (*KeyPath).GetRange() Range
func (*Map).GetRange() Range
func MapNode.GetRange() Range
func Node.GetRange() Range
func (*Null).GetRange() Range
func (*Number).GetRange() Range
func Scalar.GetRange() Range
func (*SingleQuotedString).GetRange() Range
func String.GetRange() Range
func (*Substitution).GetRange() Range
func (*UnquotedString).GetRange() Range
func Value.GetRange() Range
func Range.Before(r2 Range) bool
Scalar is implemented by nodes that represent scalar values.
( Scalar) Children() []Node
GetRange returns the range a node occupies in its file.
( Scalar) ScalarString() string
Type returns the user friendly name of the node.
*BlockString
*Boolean
*DoubleQuotedString
*Null
*Number
*SingleQuotedString
String (interface)
*UnquotedString
Scalar : ArrayNode
Scalar : Node
Scalar : Value
func ScalarBox.Unbox() Scalar
ScalarBox is used to box Scalar for JSON persistence.
TODO: implement ScalarString()
BlockString *BlockString
Boolean *Boolean
DoubleQuotedString *DoubleQuotedString
Null *Null
Number *Number
SingleQuotedString *SingleQuotedString
UnquotedString *UnquotedString
( ScalarBox) ScalarString() string
( ScalarBox) Unbox() Scalar
func ValueBox.ScalarBox() ScalarBox
func (*Key).SetScalar(scalar ScalarBox)
Range Range
Raw string
Value string
(*SingleQuotedString) Children() []Node
(*SingleQuotedString) Copy() String
(*SingleQuotedString) GetRange() Range
(*SingleQuotedString) IsUnquoted() bool
(*SingleQuotedString) ScalarString() string
(*SingleQuotedString) SetString(s2 string)
(*SingleQuotedString) Type() string
*SingleQuotedString : ArrayNode
*SingleQuotedString : Node
*SingleQuotedString : Scalar
*SingleQuotedString : String
*SingleQuotedString : Value
String is implemented by nodes that represent strings.
( String) Children() []Node
( String) Copy() String
GetRange returns the range a node occupies in its file.
( String) IsUnquoted() bool
( String) ScalarString() string
( String) SetString(string)
Type returns the user friendly name of the node.
*BlockString
*DoubleQuotedString
*SingleQuotedString
*UnquotedString
String : ArrayNode
String : Node
String : Scalar
String : Value
func RawString(s string, inKey bool) String
func (*BlockString).Copy() String
func (*DoubleQuotedString).Copy() String
func (*Import).IDA() (ida []String)
func (*KeyPath).IDA() (ida []String)
func (*SingleQuotedString).Copy() String
func String.Copy() String
func (*StringBox).Unbox() String
func (*UnquotedString).Copy() String
func oss.terrastruct.com/d2/d2ir.BoardIDA(n d2ir.Node) (ida []String)
func oss.terrastruct.com/d2/d2ir.IDA(n d2ir.Node) (ida []String)
func oss.terrastruct.com/d2/d2ir.RelIDA(p, n d2ir.Node) (ida []String)
func oss.terrastruct.com/d2/d2ir.(*Edge).IDString() String
func MakeKeyPathString(a []String) *KeyPath
func oss.terrastruct.com/d2/d2graph.(*Object).Connect(srcID, dstID []String, srcArrow, dstArrow bool, label string) (*d2graph.Edge, error)
func oss.terrastruct.com/d2/d2graph.(*Object).EnsureChild(ida []String) *d2graph.Object
func oss.terrastruct.com/d2/d2ir.(*Map).GetField(ida ...String) *d2ir.Field
StringBox is used to box String for JSON persistence.
BlockString *BlockString
DoubleQuotedString *DoubleQuotedString
SingleQuotedString *SingleQuotedString
UnquotedString *UnquotedString
(*StringBox) ScalarString() string
(*StringBox) Unbox() String
func RawStringBox(s string, inKey bool) *StringBox
func (*KeyPath).Last() *StringBox
func ValueBox.StringBox() *StringBox
Path []*StringBox
Range Range
Spread bool
(*Substitution) Children() []Node
(*Substitution) GetRange() Range
(*Substitution) IDA() (ida []string)
(*Substitution) Type() string
*Substitution : ArrayNode
*Substitution : MapNode
*Substitution : Node
Pattern holds the parsed glob pattern if in a key and the unquoted string represents a valid pattern.
Range Range
Value []InterpolationBox
(*UnquotedString) Children() []Node
(*UnquotedString) Coalesce()
(*UnquotedString) Copy() String
(*UnquotedString) GetRange() Range
(*UnquotedString) IsUnquoted() bool
(*UnquotedString) ScalarString() string
(*UnquotedString) SetString(s2 string)
(*UnquotedString) Type() string
*UnquotedString : ArrayNode
*UnquotedString : Node
*UnquotedString : Scalar
*UnquotedString : String
*UnquotedString : Value
func FlatUnquotedString(s string) *UnquotedString
Value is implemented by nodes that may be values of a key.
( Value) Children() []Node
GetRange returns the range a node occupies in its file.
Type returns the user friendly name of the node.
*Array
*BlockString
*Boolean
*DoubleQuotedString
*Import
*Map
*Null
*Number
Scalar (interface)
*SingleQuotedString
String (interface)
*UnquotedString
Value : ArrayNode
Value : Node
func ValueBox.Unbox() Value
func oss.terrastruct.com/d2/d2parser.ParseValue(value string) (Value, error)
func MakeValueBox(v Value) ValueBox
ValueBox is used to box Value for JSON persistence.
Array *Array
BlockString *BlockString
Boolean *Boolean
DoubleQuotedString *DoubleQuotedString
Import *Import
Map *Map
Null *Null
Number *Number
SingleQuotedString *SingleQuotedString
UnquotedString *UnquotedString
( ValueBox) ScalarBox() ScalarBox
( ValueBox) StringBox() *StringBox
( ValueBox) Unbox() Value
func MakeValueBox(v Value) ValueBox
Package-Level Functions (total 13)
func FlatUnquotedString(s string) *UnquotedString func IsDoubleGlob(pattern []string) bool func IsTripleGlob(pattern []string) bool func MakeArrayNodeBox(an ArrayNode) ArrayNodeBox func MakeKeyPath(a []string) *KeyPath func MakeKeyPathString(a []String) *KeyPath func MakeMapNodeBox(n MapNode) MapNodeBox func MakeValueBox(v Value) ValueBox
RawString returns s in a AST String node that can format s in the most aesthetically
pleasing way.
func RawStringBox(s string, inKey bool) *StringBox
Package-Level Variables (total 15)
BoardKeywords contains the keywords that create new boards.
CompositeReservedKeywords are reserved keywords that can hold composites
var FillPatterns []string var LabelPositions map[string]struct{}
LabelPositionsArray are the values that labels and icons can set `near` to
var LabelPositionsMapping map[string]label.Position var NearConstants map[string]struct{}
TODO maybe autofmt should allow other values, and transform them to conform
e.g. left-center becomes center-left
ReservedKeywordHolders are reserved keywords that are meaningless on its own and must hold composites
All reserved keywords. See init below.
Non Style/Holder keywords.
StyleKeywords are reserved keywords which cannot exist outside of the "style" keyword
var TextTransforms []string
& is only special if it begins a key.
- is only special if followed by another - in a key.
' " and | are only special if they begin an unquoted key or value.
![]() |
The pages are generated with Golds v0.8.2. (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. |