Merge pull request #766 from alixander/link-layers

link to boards
This commit is contained in:
Alexander Wang 2023-03-02 19:36:31 -08:00 committed by GitHub
commit 7bc49556c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 4511 additions and 6 deletions

View file

@ -56,6 +56,10 @@ func compileIR(ast *d2ast.Map, m *d2ir.Map) (*d2graph.Graph, error) {
if len(c.err.Errors) > 0 {
return nil, c.err
}
c.validateBoardLinks(g)
if len(c.err.Errors) > 0 {
return nil, c.err
}
return g, nil
}
@ -93,6 +97,7 @@ func (c *compiler) compileBoardsField(g *d2graph.Graph, ir *d2ir.Map, fieldName
continue
}
g2 := d2graph.NewGraph()
g2.Parent = g
g2.AST = g.AST
c.compileBoard(g2, f.Map())
g2.Name = f.Name
@ -193,7 +198,7 @@ func (c *compiler) compileField(obj *d2graph.Object, f *d2ir.Field) {
obj.Map = fr.Context.Key.Value.Map
}
}
scopeObjIDA := d2ir.IDA(fr.Context.ScopeMap)
scopeObjIDA := d2ir.BoardIDA(fr.Context.ScopeMap)
scopeObj := obj.Graph.Root.EnsureChildIDVal(scopeObjIDA)
obj.References = append(obj.References, d2graph.Reference{
Key: fr.KeyPath,
@ -431,7 +436,7 @@ func (c *compiler) compileEdge(obj *d2graph.Object, e *d2ir.Edge) {
edge.Attributes.Label.MapKey = e.LastPrimaryKey()
for _, er := range e.References {
scopeObjIDA := d2ir.IDA(er.Context.ScopeMap)
scopeObjIDA := d2ir.BoardIDA(er.Context.ScopeMap)
scopeObj := edge.Src.Graph.Root.EnsureChildIDVal(scopeObjIDA)
edge.References = append(edge.References, d2graph.EdgeReference{
Edge: er.Context.Edge,
@ -715,6 +720,72 @@ func (c *compiler) validateNear(g *d2graph.Graph) {
}
}
func (c *compiler) validateBoardLinks(g *d2graph.Graph) {
for _, obj := range g.Objects {
if obj.Attributes.Link == nil {
continue
}
linkKey, err := d2parser.ParseKey(obj.Attributes.Link.Value)
if err != nil {
continue
}
if linkKey.Path[0].Unbox().ScalarString() != "root" {
continue
}
if !hasBoard(g.RootBoard(), linkKey.IDA()) {
c.errorf(obj.Attributes.Link.MapKey, "linked board not found")
continue
}
}
for _, b := range g.Layers {
c.validateBoardLinks(b)
}
for _, b := range g.Scenarios {
c.validateBoardLinks(b)
}
for _, b := range g.Steps {
c.validateBoardLinks(b)
}
}
func hasBoard(root *d2graph.Graph, ida []string) bool {
if len(ida) == 0 {
return true
}
if ida[0] == "root" {
return hasBoard(root, ida[1:])
}
id := ida[0]
if len(ida) == 1 {
return root.Name == id
}
nextID := ida[1]
switch id {
case "layers":
for _, b := range root.Layers {
if b.Name == nextID {
return hasBoard(b, ida[2:])
}
}
case "scenarios":
for _, b := range root.Scenarios {
if b.Name == nextID {
return hasBoard(b, ida[2:])
}
}
case "steps":
for _, b := range root.Steps {
if b.Name == nextID {
return hasBoard(b, ida[2:])
}
}
}
return false
}
func init() {
FullToShortLanguageAliases = make(map[string]string, len(ShortToFullLanguageAliases))
for k, v := range ShortToFullLanguageAliases {

View file

@ -2027,6 +2027,121 @@ Chinchillas_Collectibles.chinchilla -> Chinchillas.id`,
tassert.Equal(t, 2, *g.Edges[0].SrcTableColumnIndex)
},
},
{
name: "link-board-ok",
text: `x.link: layers.x
layers: {
x: {
y
}
}`,
assertions: func(t *testing.T, g *d2graph.Graph) {
tassert.Equal(t, "root.layers.x", g.Objects[0].Attributes.Link.Value)
},
},
{
name: "link-board-mixed",
text: `question: How does the cat go?
question.link: layers.cat
layers: {
cat: {
the cat -> meeeowwww: goes
}
}
scenarios: {
green: {
question.style.fill: green
}
}`,
assertions: func(t *testing.T, g *d2graph.Graph) {
tassert.Equal(t, "root.layers.cat", g.Objects[0].Attributes.Link.Value)
tassert.Equal(t, "root.layers.cat", g.Scenarios[0].Objects[0].Attributes.Link.Value)
},
},
{
name: "link-board-not-found",
text: `x.link: layers.x
`,
expErr: `d2/testdata/d2compiler/TestCompile/link-board-not-found.d2:1:1: linked board not found`,
},
{
name: "link-board-not-board",
text: `zzz
x.link: layers.x.y
layers: {
x: {
y
}
}`,
expErr: `d2/testdata/d2compiler/TestCompile/link-board-not-board.d2:2:1: linked board not found`,
},
{
name: "link-board-nested",
text: `x.link: layers.x.layers.x
layers: {
x: {
layers: {
x: {
hello
}
}
}
}`,
assertions: func(t *testing.T, g *d2graph.Graph) {
tassert.Equal(t, "root.layers.x.layers.x", g.Objects[0].Attributes.Link.Value)
},
},
{
name: "link-board-key-nested",
text: `x: {
y.link: layers.x
}
layers: {
x: {
yo
}
}`,
assertions: func(t *testing.T, g *d2graph.Graph) {
tassert.Equal(t, "root.layers.x", g.Objects[1].Attributes.Link.Value)
},
},
{
name: "link-board-underscore",
text: `x
layers: {
x: {
yo
layers: {
x: {
hello.link: _._.layers.x
hey.link: _
}
}
}
}`,
assertions: func(t *testing.T, g *d2graph.Graph) {
tassert.NotNil(t, g.Layers[0].Layers[0].Objects[0].Attributes.Link.Value)
tassert.Equal(t, "root.layers.x", g.Layers[0].Layers[0].Objects[0].Attributes.Link.Value)
tassert.Equal(t, "root.layers.x", g.Layers[0].Layers[0].Objects[1].Attributes.Link.Value)
},
},
{
name: "link-board-underscore-not-found",
text: `x
layers: {
x: {
yo
layers: {
x: {
hello.link: _._._
}
}
}
}`,
expErr: `d2/testdata/d2compiler/TestCompile/link-board-underscore-not-found.d2:7:9: invalid underscore usage`,
},
}
for _, tc := range testCases {

View file

@ -28,7 +28,8 @@ const DEFAULT_SHAPE_SIZE = 100.
const MIN_SHAPE_SIZE = 5
type Graph struct {
Name string `json:"name"`
Parent *Graph `json:"-"`
Name string `json:"name"`
// IsFolderOnly indicates a board or scenario itself makes no modifications from its
// base. Folder only boards do not have a render and are used purely for organizing
// the board tree.
@ -55,6 +56,13 @@ func NewGraph() *Graph {
return d
}
func (g *Graph) RootBoard() *Graph {
for g.Parent != nil {
g = g.Parent
}
return g
}
// TODO consider having different Scalar types
// Right now we'll hold any types in Value and just convert, e.g. floats
type Scalar struct {

View file

@ -2,6 +2,7 @@ package d2ir
import (
"oss.terrastruct.com/d2/d2ast"
"oss.terrastruct.com/d2/d2format"
"oss.terrastruct.com/d2/d2parser"
)
@ -127,6 +128,10 @@ func (c *compiler) compileField(dst *Map, kp *d2ast.KeyPath, refctx *RefContext)
}
c.compileMap(f.Map(), refctx.Key.Value.Map)
} else if refctx.Key.Value.ScalarBox().Unbox() != nil {
// If the link is a board, we need to transform it into an absolute path.
if f.Name == "link" {
c.compileLink(refctx)
}
f.Primary_ = &Scalar{
parent: f,
Value: refctx.Key.Value.ScalarBox().Unbox(),
@ -134,6 +139,68 @@ func (c *compiler) compileField(dst *Map, kp *d2ast.KeyPath, refctx *RefContext)
}
}
func (c *compiler) compileLink(refctx *RefContext) {
val := refctx.Key.Value.ScalarBox().Unbox().ScalarString()
link, err := d2parser.ParseKey(val)
if err != nil {
return
}
scopeIDA := IDA(refctx.ScopeMap)
if len(scopeIDA) == 0 {
return
}
linkIDA := link.IDA()
if len(linkIDA) == 0 {
return
}
if linkIDA[0] == "root" {
c.errorf(refctx.Key.Key, "cannot refer to root in link")
return
}
// If it doesn't start with one of these reserved words, the link is definitely not a board link.
if linkIDA[0] != "layers" && linkIDA[0] != "scenarios" && linkIDA[0] != "steps" && linkIDA[0] != "_" {
return
}
// Chop off the non-board portion of the scope, like if this is being defined on a nested object (e.g. `x.y.z`)
for i := len(scopeIDA) - 1; i > 0; i-- {
if scopeIDA[i-1] == "layers" || scopeIDA[i-1] == "scenarios" || scopeIDA[i-1] == "steps" {
scopeIDA = scopeIDA[:i+1]
break
}
if scopeIDA[i-1] == "root" {
scopeIDA = scopeIDA[:i]
break
}
}
// Resolve underscores
for len(linkIDA) > 0 && linkIDA[0] == "_" {
if len(scopeIDA) < 2 {
// IR compiler only validates bad underscore usage
// The compiler will validate if the target board actually exists
c.errorf(refctx.Key.Key, "invalid underscore usage")
return
}
// pop 2 off path per one underscore
scopeIDA = scopeIDA[:len(scopeIDA)-2]
linkIDA = linkIDA[1:]
}
if len(scopeIDA) == 0 {
scopeIDA = []string{"root"}
}
// Create the absolute path by appending scope path with value specified
scopeIDA = append(scopeIDA, linkIDA...)
kp := d2ast.MakeKeyPath(scopeIDA)
refctx.Key.Value = d2ast.MakeValueBox(d2ast.RawString(d2format.Format(kp), true))
}
func (c *compiler) compileEdges(refctx *RefContext) {
if refctx.Key.Key != nil {
f, err := refctx.ScopeMap.EnsureField(refctx.Key.Key, refctx)

View file

@ -158,7 +158,7 @@ type Map struct {
func (m *Map) initRoot() {
m.parent = &Field{
Name: "",
Name: "root",
References: []*FieldReference{{
Context: &RefContext{
ScopeMap: m,
@ -1033,8 +1033,8 @@ func parentPrimaryKey(n Node) *d2ast.Key {
return nil
}
// IDA returns the absolute path to n from the nearest board root.
func IDA(n Node) (ida []string) {
// BoardIDA returns the absolute path to n from the nearest board root.
func BoardIDA(n Node) (ida []string) {
for {
f, ok := n.(*Field)
if ok {
@ -1053,6 +1053,26 @@ func IDA(n Node) (ida []string) {
}
}
// IDA returns the absolute path to n.
func IDA(n Node) (ida []string) {
for {
f, ok := n.(*Field)
if ok {
ida = append(ida, f.Name)
if f.Root() {
reverseIDA(ida)
return ida
}
}
f = ParentField(n)
if f == nil {
reverseIDA(ida)
return ida
}
n = f
}
}
func reverseIDA(ida []string) {
for i := 0; i < len(ida)/2; i++ {
tmp := ida[i]

View file

@ -0,0 +1,540 @@
{
"graph": {
"name": "",
"isFolderOnly": false,
"ast": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,0:0:0-7:1:55",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,0:0:0-2:1:25",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,0:0:0-0:1:1",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,0:0:0-0:1:1",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,0:3:3-2:0:24",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,1:2:7-1:18:23",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,1:2:7-1:8:13",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,1:2:7-1:3:8",
"value": [
{
"string": "y",
"raw_string": "y"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,1:4:9-1:8:13",
"value": [
{
"string": "link",
"raw_string": "link"
}
]
}
}
]
},
"primary": {},
"value": {
"double_quoted_string": {
"range": ",0:0:0-0:0:0",
"value": [
{
"string": "root.layers.x"
}
]
}
}
}
}
]
}
}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,3:0:26-7:1:55",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,3:0:26-3:6:32",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,3:0:26-3:6:32",
"value": [
{
"string": "layers",
"raw_string": "layers"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,3:8:34-7:0:54",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,4:2:38-6:3:53",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,4:2:38-4:3:39",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,4:2:38-4:3:39",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,4:5:41-6:2:52",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,5:4:47-5:6:49",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,5:4:47-5:6:49",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,5:4:47-5:6:49",
"value": [
{
"string": "yo",
"raw_string": "yo"
}
]
}
}
]
},
"primary": {},
"value": {}
}
}
]
}
}
}
}
]
}
}
}
}
]
},
"root": {
"id": "",
"id_val": "",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": ""
},
"style": {},
"near_key": null,
"shape": {
"value": ""
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
"edges": null,
"objects": [
{
"id": "x",
"id_val": "x",
"label_dimensions": {
"width": 0,
"height": 0
},
"references": [
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,0:0:0-0:1:1",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,0:0:0-0:1:1",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
}
],
"attributes": {
"label": {
"value": "x"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
{
"id": "y",
"id_val": "y",
"label_dimensions": {
"width": 0,
"height": 0
},
"references": [
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,1:2:7-1:8:13",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,1:2:7-1:3:8",
"value": [
{
"string": "y",
"raw_string": "y"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,1:4:9-1:8:13",
"value": [
{
"string": "link",
"raw_string": "link"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
}
],
"attributes": {
"label": {
"value": "y"
},
"style": {},
"link": {
"value": "root.layers.x"
},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
}
],
"layers": [
{
"name": "x",
"isFolderOnly": false,
"ast": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,0:0:0-7:1:55",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,0:0:0-2:1:25",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,0:0:0-0:1:1",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,0:0:0-0:1:1",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,0:3:3-2:0:24",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,1:2:7-1:18:23",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,1:2:7-1:8:13",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,1:2:7-1:3:8",
"value": [
{
"string": "y",
"raw_string": "y"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,1:4:9-1:8:13",
"value": [
{
"string": "link",
"raw_string": "link"
}
]
}
}
]
},
"primary": {},
"value": {
"double_quoted_string": {
"range": ",0:0:0-0:0:0",
"value": [
{
"string": "root.layers.x"
}
]
}
}
}
}
]
}
}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,3:0:26-7:1:55",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,3:0:26-3:6:32",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,3:0:26-3:6:32",
"value": [
{
"string": "layers",
"raw_string": "layers"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,3:8:34-7:0:54",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,4:2:38-6:3:53",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,4:2:38-4:3:39",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,4:2:38-4:3:39",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,4:5:41-6:2:52",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,5:4:47-5:6:49",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,5:4:47-5:6:49",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,5:4:47-5:6:49",
"value": [
{
"string": "yo",
"raw_string": "yo"
}
]
}
}
]
},
"primary": {},
"value": {}
}
}
]
}
}
}
}
]
}
}
}
}
]
},
"root": {
"id": "",
"id_val": "",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": ""
},
"style": {},
"near_key": null,
"shape": {
"value": ""
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
"edges": null,
"objects": [
{
"id": "yo",
"id_val": "yo",
"label_dimensions": {
"width": 0,
"height": 0
},
"references": [
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,5:4:47-5:6:49",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,5:4:47-5:6:49",
"value": [
{
"string": "yo",
"raw_string": "yo"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
}
],
"attributes": {
"label": {
"value": "yo"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
}
]
}
]
},
"err": null
}

1364
testdata/d2compiler/TestCompile/link-board-mixed.exp.json generated vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,771 @@
{
"graph": {
"name": "",
"isFolderOnly": false,
"ast": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:0:0-9:1:101",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:0:0-0:25:25",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:0:0-0:6:6",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:0:0-0:1:1",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:2:2-0:6:6",
"value": [
{
"string": "link",
"raw_string": "link"
}
]
}
}
]
},
"primary": {},
"value": {
"double_quoted_string": {
"range": ",0:0:0-0:0:0",
"value": [
{
"string": "root.layers.x.layers.x"
}
]
}
}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,1:0:26-9:1:101",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,1:0:26-1:6:32",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,1:0:26-1:6:32",
"value": [
{
"string": "layers",
"raw_string": "layers"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,1:8:34-9:0:100",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,2:2:38-8:3:99",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,2:2:38-2:3:39",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,2:2:38-2:3:39",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,2:5:41-8:2:98",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,3:4:47-7:5:95",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,3:4:47-3:10:53",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,3:4:47-3:10:53",
"value": [
{
"string": "layers",
"raw_string": "layers"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,3:12:55-7:4:94",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,4:6:63-6:7:89",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,4:6:63-4:7:64",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,4:6:63-4:7:64",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,4:9:66-6:6:88",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,5:8:76-5:13:81",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,5:8:76-5:13:81",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,5:8:76-5:13:81",
"value": [
{
"string": "hello",
"raw_string": "hello"
}
]
}
}
]
},
"primary": {},
"value": {}
}
}
]
}
}
}
}
]
}
}
}
}
]
}
}
}
}
]
}
}
}
}
]
},
"root": {
"id": "",
"id_val": "",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": ""
},
"style": {},
"near_key": null,
"shape": {
"value": ""
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
"edges": null,
"objects": [
{
"id": "x",
"id_val": "x",
"label_dimensions": {
"width": 0,
"height": 0
},
"references": [
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:0:0-0:6:6",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:0:0-0:1:1",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:2:2-0:6:6",
"value": [
{
"string": "link",
"raw_string": "link"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
}
],
"attributes": {
"label": {
"value": "x"
},
"style": {},
"link": {
"value": "root.layers.x.layers.x"
},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
}
],
"layers": [
{
"name": "x",
"isFolderOnly": true,
"ast": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:0:0-9:1:101",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:0:0-0:25:25",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:0:0-0:6:6",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:0:0-0:1:1",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:2:2-0:6:6",
"value": [
{
"string": "link",
"raw_string": "link"
}
]
}
}
]
},
"primary": {},
"value": {
"double_quoted_string": {
"range": ",0:0:0-0:0:0",
"value": [
{
"string": "root.layers.x.layers.x"
}
]
}
}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,1:0:26-9:1:101",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,1:0:26-1:6:32",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,1:0:26-1:6:32",
"value": [
{
"string": "layers",
"raw_string": "layers"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,1:8:34-9:0:100",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,2:2:38-8:3:99",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,2:2:38-2:3:39",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,2:2:38-2:3:39",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,2:5:41-8:2:98",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,3:4:47-7:5:95",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,3:4:47-3:10:53",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,3:4:47-3:10:53",
"value": [
{
"string": "layers",
"raw_string": "layers"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,3:12:55-7:4:94",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,4:6:63-6:7:89",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,4:6:63-4:7:64",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,4:6:63-4:7:64",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,4:9:66-6:6:88",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,5:8:76-5:13:81",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,5:8:76-5:13:81",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,5:8:76-5:13:81",
"value": [
{
"string": "hello",
"raw_string": "hello"
}
]
}
}
]
},
"primary": {},
"value": {}
}
}
]
}
}
}
}
]
}
}
}
}
]
}
}
}
}
]
}
}
}
}
]
},
"root": {
"id": "",
"id_val": "",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": ""
},
"style": {},
"near_key": null,
"shape": {
"value": ""
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
"edges": null,
"objects": null,
"layers": [
{
"name": "x",
"isFolderOnly": false,
"ast": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:0:0-9:1:101",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:0:0-0:25:25",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:0:0-0:6:6",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:0:0-0:1:1",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:2:2-0:6:6",
"value": [
{
"string": "link",
"raw_string": "link"
}
]
}
}
]
},
"primary": {},
"value": {
"double_quoted_string": {
"range": ",0:0:0-0:0:0",
"value": [
{
"string": "root.layers.x.layers.x"
}
]
}
}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,1:0:26-9:1:101",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,1:0:26-1:6:32",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,1:0:26-1:6:32",
"value": [
{
"string": "layers",
"raw_string": "layers"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,1:8:34-9:0:100",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,2:2:38-8:3:99",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,2:2:38-2:3:39",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,2:2:38-2:3:39",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,2:5:41-8:2:98",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,3:4:47-7:5:95",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,3:4:47-3:10:53",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,3:4:47-3:10:53",
"value": [
{
"string": "layers",
"raw_string": "layers"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,3:12:55-7:4:94",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,4:6:63-6:7:89",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,4:6:63-4:7:64",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,4:6:63-4:7:64",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,4:9:66-6:6:88",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,5:8:76-5:13:81",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,5:8:76-5:13:81",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,5:8:76-5:13:81",
"value": [
{
"string": "hello",
"raw_string": "hello"
}
]
}
}
]
},
"primary": {},
"value": {}
}
}
]
}
}
}
}
]
}
}
}
}
]
}
}
}
}
]
}
}
}
}
]
},
"root": {
"id": "",
"id_val": "",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": ""
},
"style": {},
"near_key": null,
"shape": {
"value": ""
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
"edges": null,
"objects": [
{
"id": "hello",
"id_val": "hello",
"label_dimensions": {
"width": 0,
"height": 0
},
"references": [
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,5:8:76-5:13:81",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,5:8:76-5:13:81",
"value": [
{
"string": "hello",
"raw_string": "hello"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
}
],
"attributes": {
"label": {
"value": "hello"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
}
]
}
]
}
]
},
"err": null
}

View file

@ -0,0 +1,12 @@
{
"graph": null,
"err": {
"ioerr": null,
"errs": [
{
"range": "d2/testdata/d2compiler/TestCompile/link-board-not-board.d2,1:0:4-1:18:22",
"errmsg": "d2/testdata/d2compiler/TestCompile/link-board-not-board.d2:2:1: linked board not found"
}
]
}
}

View file

@ -0,0 +1,12 @@
{
"graph": null,
"err": {
"ioerr": null,
"errs": [
{
"range": "d2/testdata/d2compiler/TestCompile/link-board-not-found.d2,0:0:0-0:16:16",
"errmsg": "d2/testdata/d2compiler/TestCompile/link-board-not-found.d2:1:1: linked board not found"
}
]
}
}

435
testdata/d2compiler/TestCompile/link-board-ok.exp.json generated vendored Normal file
View file

@ -0,0 +1,435 @@
{
"graph": {
"name": "",
"isFolderOnly": false,
"ast": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,0:0:0-5:1:42",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,0:0:0-0:16:16",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,0:0:0-0:6:6",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,0:0:0-0:1:1",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,0:2:2-0:6:6",
"value": [
{
"string": "link",
"raw_string": "link"
}
]
}
}
]
},
"primary": {},
"value": {
"double_quoted_string": {
"range": ",0:0:0-0:0:0",
"value": [
{
"string": "root.layers.x"
}
]
}
}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,1:0:17-5:1:42",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,1:0:17-1:6:23",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,1:0:17-1:6:23",
"value": [
{
"string": "layers",
"raw_string": "layers"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,1:8:25-5:0:41",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,2:1:28-4:2:40",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,2:1:28-2:2:29",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,2:1:28-2:2:29",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,2:4:31-4:1:39",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,3:3:36-3:4:37",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,3:3:36-3:4:37",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,3:3:36-3:4:37",
"value": [
{
"string": "y",
"raw_string": "y"
}
]
}
}
]
},
"primary": {},
"value": {}
}
}
]
}
}
}
}
]
}
}
}
}
]
},
"root": {
"id": "",
"id_val": "",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": ""
},
"style": {},
"near_key": null,
"shape": {
"value": ""
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
"edges": null,
"objects": [
{
"id": "x",
"id_val": "x",
"label_dimensions": {
"width": 0,
"height": 0
},
"references": [
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,0:0:0-0:6:6",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,0:0:0-0:1:1",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,0:2:2-0:6:6",
"value": [
{
"string": "link",
"raw_string": "link"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
}
],
"attributes": {
"label": {
"value": "x"
},
"style": {},
"link": {
"value": "root.layers.x"
},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
}
],
"layers": [
{
"name": "x",
"isFolderOnly": false,
"ast": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,0:0:0-5:1:42",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,0:0:0-0:16:16",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,0:0:0-0:6:6",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,0:0:0-0:1:1",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,0:2:2-0:6:6",
"value": [
{
"string": "link",
"raw_string": "link"
}
]
}
}
]
},
"primary": {},
"value": {
"double_quoted_string": {
"range": ",0:0:0-0:0:0",
"value": [
{
"string": "root.layers.x"
}
]
}
}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,1:0:17-5:1:42",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,1:0:17-1:6:23",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,1:0:17-1:6:23",
"value": [
{
"string": "layers",
"raw_string": "layers"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,1:8:25-5:0:41",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,2:1:28-4:2:40",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,2:1:28-2:2:29",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,2:1:28-2:2:29",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,2:4:31-4:1:39",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,3:3:36-3:4:37",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,3:3:36-3:4:37",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,3:3:36-3:4:37",
"value": [
{
"string": "y",
"raw_string": "y"
}
]
}
}
]
},
"primary": {},
"value": {}
}
}
]
}
}
}
}
]
}
}
}
}
]
},
"root": {
"id": "",
"id_val": "",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": ""
},
"style": {},
"near_key": null,
"shape": {
"value": ""
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
"edges": null,
"objects": [
{
"id": "y",
"id_val": "y",
"label_dimensions": {
"width": 0,
"height": 0
},
"references": [
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,3:3:36-3:4:37",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,3:3:36-3:4:37",
"value": [
{
"string": "y",
"raw_string": "y"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
}
],
"attributes": {
"label": {
"value": "y"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
}
]
}
]
},
"err": null
}

View file

@ -0,0 +1,12 @@
{
"graph": null,
"err": {
"ioerr": null,
"errs": [
{
"range": "d2/testdata/d2compiler/TestCompile/link-board-underscore-not-found.d2,6:8:59-6:18:69",
"errmsg": "d2/testdata/d2compiler/TestCompile/link-board-underscore-not-found.d2:7:9: invalid underscore usage"
}
]
}
}

File diff suppressed because it is too large Load diff