diff --git a/d2compiler/compile.go b/d2compiler/compile.go index 4e1face77..f865bfb9b 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -266,6 +266,8 @@ func (c *compiler) compileKey(obj *d2graph.Object, m *d2ast.Map, mk *d2ast.Key) }, unresolvedObj) } else if obj.Parent == nil { // Top level reserved key set on root. + c.compileAttributes(&obj.Attributes, mk) + c.applyScalar(&obj.Attributes, reserved, mk.Value.ScalarBox()) return } diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index c43639cb8..da1947f28 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -1501,6 +1501,26 @@ dst.id <-> src.dst_id } }, }, + { + name: "basic_sequence", + + text: `x: { + shape: sequence +} +`, + assertions: func(t *testing.T, g *d2graph.Graph) { + diff.AssertStringEq(t, "sequence", g.Objects[0].Attributes.Shape.Value) + }, + }, + { + name: "root_sequence", + + text: `shape: sequence +`, + assertions: func(t *testing.T, g *d2graph.Graph) { + diff.AssertStringEq(t, "sequence", g.Root.Attributes.Shape.Value) + }, + }, } for _, tc := range testCases { diff --git a/d2target/d2target.go b/d2target/d2target.go index 94c630099..6c15c0703 100644 --- a/d2target/d2target.go +++ b/d2target/d2target.go @@ -277,6 +277,7 @@ const ( ShapeClass = "class" ShapeSQLTable = "sql_table" ShapeImage = "image" + ShapeSequence = "sequence" ) var Shapes = []string{ @@ -302,6 +303,7 @@ var Shapes = []string{ ShapeClass, ShapeSQLTable, ShapeImage, + ShapeSequence, } func IsShape(s string) bool { @@ -368,6 +370,7 @@ var DSL_SHAPE_TO_SHAPE_TYPE = map[string]string{ ShapeClass: shape.CLASS_TYPE, ShapeSQLTable: shape.TABLE_TYPE, ShapeImage: shape.IMAGE_TYPE, + ShapeSequence: shape.SQUARE_TYPE, } var SHAPE_TYPE_TO_DSL_SHAPE map[string]string diff --git a/testdata/d2compiler/TestCompile/basic_sequence.exp.json b/testdata/d2compiler/TestCompile/basic_sequence.exp.json new file mode 100644 index 000000000..06f523536 --- /dev/null +++ b/testdata/d2compiler/TestCompile/basic_sequence.exp.json @@ -0,0 +1,133 @@ +{ + "graph": { + "ast": { + "range": "d2/testdata/d2compiler/TestCompile/basic_sequence.d2,0:0:0-3:0:25", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/basic_sequence.d2,0:0:0-2:1:24", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/basic_sequence.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/basic_sequence.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/basic_sequence.d2,0:3:3-2:0:23", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/basic_sequence.d2,1:2:7-1:17:22", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/basic_sequence.d2,1:2:7-1:7:12", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/basic_sequence.d2,1:2:7-1:7:12", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/basic_sequence.d2,1:9:14-1:17:22", + "value": [ + { + "string": "sequence", + "raw_string": "sequence" + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + } + } + }, + "edges": null, + "objects": [ + { + "id": "x", + "id_val": "x", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/basic_sequence.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/basic_sequence.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "sequence" + } + } + } + ] + }, + "err": null +} diff --git a/testdata/d2compiler/TestCompile/root_sequence.exp.json b/testdata/d2compiler/TestCompile/root_sequence.exp.json new file mode 100644 index 000000000..52b290a32 --- /dev/null +++ b/testdata/d2compiler/TestCompile/root_sequence.exp.json @@ -0,0 +1,63 @@ +{ + "graph": { + "ast": { + "range": "d2/testdata/d2compiler/TestCompile/root_sequence.d2,0:0:0-1:0:16", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/root_sequence.d2,0:0:0-0:15:15", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/root_sequence.d2,0:0:0-0:5:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/root_sequence.d2,0:0:0-0:5:5", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/root_sequence.d2,0:7:7-0:15:15", + "value": [ + { + "string": "sequence", + "raw_string": "sequence" + } + ] + } + } + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "sequence" + } + } + }, + "edges": null, + "objects": null + }, + "err": null +}