2022-11-28 02:10:24PM
This commit is contained in:
parent
3d6c19697e
commit
1796dd9020
5 changed files with 221 additions and 0 deletions
|
|
@ -266,6 +266,8 @@ func (c *compiler) compileKey(obj *d2graph.Object, m *d2ast.Map, mk *d2ast.Key)
|
||||||
}, unresolvedObj)
|
}, unresolvedObj)
|
||||||
} else if obj.Parent == nil {
|
} else if obj.Parent == nil {
|
||||||
// Top level reserved key set on root.
|
// Top level reserved key set on root.
|
||||||
|
c.compileAttributes(&obj.Attributes, mk)
|
||||||
|
c.applyScalar(&obj.Attributes, reserved, mk.Value.ScalarBox())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
for _, tc := range testCases {
|
||||||
|
|
|
||||||
|
|
@ -277,6 +277,7 @@ const (
|
||||||
ShapeClass = "class"
|
ShapeClass = "class"
|
||||||
ShapeSQLTable = "sql_table"
|
ShapeSQLTable = "sql_table"
|
||||||
ShapeImage = "image"
|
ShapeImage = "image"
|
||||||
|
ShapeSequence = "sequence"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Shapes = []string{
|
var Shapes = []string{
|
||||||
|
|
@ -302,6 +303,7 @@ var Shapes = []string{
|
||||||
ShapeClass,
|
ShapeClass,
|
||||||
ShapeSQLTable,
|
ShapeSQLTable,
|
||||||
ShapeImage,
|
ShapeImage,
|
||||||
|
ShapeSequence,
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsShape(s string) bool {
|
func IsShape(s string) bool {
|
||||||
|
|
@ -368,6 +370,7 @@ var DSL_SHAPE_TO_SHAPE_TYPE = map[string]string{
|
||||||
ShapeClass: shape.CLASS_TYPE,
|
ShapeClass: shape.CLASS_TYPE,
|
||||||
ShapeSQLTable: shape.TABLE_TYPE,
|
ShapeSQLTable: shape.TABLE_TYPE,
|
||||||
ShapeImage: shape.IMAGE_TYPE,
|
ShapeImage: shape.IMAGE_TYPE,
|
||||||
|
ShapeSequence: shape.SQUARE_TYPE,
|
||||||
}
|
}
|
||||||
|
|
||||||
var SHAPE_TYPE_TO_DSL_SHAPE map[string]string
|
var SHAPE_TYPE_TO_DSL_SHAPE map[string]string
|
||||||
|
|
|
||||||
133
testdata/d2compiler/TestCompile/basic_sequence.exp.json
vendored
Normal file
133
testdata/d2compiler/TestCompile/basic_sequence.exp.json
vendored
Normal file
|
|
@ -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
|
||||||
|
}
|
||||||
63
testdata/d2compiler/TestCompile/root_sequence.exp.json
vendored
Normal file
63
testdata/d2compiler/TestCompile/root_sequence.exp.json
vendored
Normal file
|
|
@ -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
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue