Merge pull request #245 from alixander/alixander/shape-sequence
syntax: shape: sequence
This commit is contained in:
commit
3f6b14cb00
5 changed files with 266 additions and 45 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1501,6 +1501,26 @@ dst.id <-> src.dst_id
|
|||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "basic_sequence",
|
||||
|
||||
text: `x: {
|
||||
shape: sequence_diagram
|
||||
}
|
||||
`,
|
||||
assertions: func(t *testing.T, g *d2graph.Graph) {
|
||||
diff.AssertStringEq(t, "sequence_diagram", g.Objects[0].Attributes.Shape.Value)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "root_sequence",
|
||||
|
||||
text: `shape: sequence_diagram
|
||||
`,
|
||||
assertions: func(t *testing.T, g *d2graph.Graph) {
|
||||
diff.AssertStringEq(t, "sequence_diagram", g.Root.Attributes.Shape.Value)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
|
|
|
|||
|
|
@ -255,28 +255,29 @@ func NewPoint(x, y int) Point {
|
|||
}
|
||||
|
||||
const (
|
||||
ShapeRectangle = "rectangle"
|
||||
ShapeSquare = "square"
|
||||
ShapePage = "page"
|
||||
ShapeParallelogram = "parallelogram"
|
||||
ShapeDocument = "document"
|
||||
ShapeCylinder = "cylinder"
|
||||
ShapeQueue = "queue"
|
||||
ShapePackage = "package"
|
||||
ShapeStep = "step"
|
||||
ShapeCallout = "callout"
|
||||
ShapeStoredData = "stored_data"
|
||||
ShapePerson = "person"
|
||||
ShapeDiamond = "diamond"
|
||||
ShapeOval = "oval"
|
||||
ShapeCircle = "circle"
|
||||
ShapeHexagon = "hexagon"
|
||||
ShapeCloud = "cloud"
|
||||
ShapeText = "text"
|
||||
ShapeCode = "code"
|
||||
ShapeClass = "class"
|
||||
ShapeSQLTable = "sql_table"
|
||||
ShapeImage = "image"
|
||||
ShapeRectangle = "rectangle"
|
||||
ShapeSquare = "square"
|
||||
ShapePage = "page"
|
||||
ShapeParallelogram = "parallelogram"
|
||||
ShapeDocument = "document"
|
||||
ShapeCylinder = "cylinder"
|
||||
ShapeQueue = "queue"
|
||||
ShapePackage = "package"
|
||||
ShapeStep = "step"
|
||||
ShapeCallout = "callout"
|
||||
ShapeStoredData = "stored_data"
|
||||
ShapePerson = "person"
|
||||
ShapeDiamond = "diamond"
|
||||
ShapeOval = "oval"
|
||||
ShapeCircle = "circle"
|
||||
ShapeHexagon = "hexagon"
|
||||
ShapeCloud = "cloud"
|
||||
ShapeText = "text"
|
||||
ShapeCode = "code"
|
||||
ShapeClass = "class"
|
||||
ShapeSQLTable = "sql_table"
|
||||
ShapeImage = "image"
|
||||
ShapeSequenceDiagram = "sequence_diagram"
|
||||
)
|
||||
|
||||
var Shapes = []string{
|
||||
|
|
@ -302,6 +303,7 @@ var Shapes = []string{
|
|||
ShapeClass,
|
||||
ShapeSQLTable,
|
||||
ShapeImage,
|
||||
ShapeSequenceDiagram,
|
||||
}
|
||||
|
||||
func IsShape(s string) bool {
|
||||
|
|
@ -345,29 +347,30 @@ func (text MText) GetColor(theme *d2themes.Theme, isItalic bool) string {
|
|||
}
|
||||
|
||||
var DSL_SHAPE_TO_SHAPE_TYPE = map[string]string{
|
||||
"": shape.SQUARE_TYPE,
|
||||
ShapeRectangle: shape.SQUARE_TYPE,
|
||||
ShapeSquare: shape.REAL_SQUARE_TYPE,
|
||||
ShapePage: shape.PAGE_TYPE,
|
||||
ShapeParallelogram: shape.PARALLELOGRAM_TYPE,
|
||||
ShapeDocument: shape.DOCUMENT_TYPE,
|
||||
ShapeCylinder: shape.CYLINDER_TYPE,
|
||||
ShapeQueue: shape.QUEUE_TYPE,
|
||||
ShapePackage: shape.PACKAGE_TYPE,
|
||||
ShapeStep: shape.STEP_TYPE,
|
||||
ShapeCallout: shape.CALLOUT_TYPE,
|
||||
ShapeStoredData: shape.STORED_DATA_TYPE,
|
||||
ShapePerson: shape.PERSON_TYPE,
|
||||
ShapeDiamond: shape.DIAMOND_TYPE,
|
||||
ShapeOval: shape.OVAL_TYPE,
|
||||
ShapeCircle: shape.CIRCLE_TYPE,
|
||||
ShapeHexagon: shape.HEXAGON_TYPE,
|
||||
ShapeCloud: shape.CLOUD_TYPE,
|
||||
ShapeText: shape.TEXT_TYPE,
|
||||
ShapeCode: shape.CODE_TYPE,
|
||||
ShapeClass: shape.CLASS_TYPE,
|
||||
ShapeSQLTable: shape.TABLE_TYPE,
|
||||
ShapeImage: shape.IMAGE_TYPE,
|
||||
"": shape.SQUARE_TYPE,
|
||||
ShapeRectangle: shape.SQUARE_TYPE,
|
||||
ShapeSquare: shape.REAL_SQUARE_TYPE,
|
||||
ShapePage: shape.PAGE_TYPE,
|
||||
ShapeParallelogram: shape.PARALLELOGRAM_TYPE,
|
||||
ShapeDocument: shape.DOCUMENT_TYPE,
|
||||
ShapeCylinder: shape.CYLINDER_TYPE,
|
||||
ShapeQueue: shape.QUEUE_TYPE,
|
||||
ShapePackage: shape.PACKAGE_TYPE,
|
||||
ShapeStep: shape.STEP_TYPE,
|
||||
ShapeCallout: shape.CALLOUT_TYPE,
|
||||
ShapeStoredData: shape.STORED_DATA_TYPE,
|
||||
ShapePerson: shape.PERSON_TYPE,
|
||||
ShapeDiamond: shape.DIAMOND_TYPE,
|
||||
ShapeOval: shape.OVAL_TYPE,
|
||||
ShapeCircle: shape.CIRCLE_TYPE,
|
||||
ShapeHexagon: shape.HEXAGON_TYPE,
|
||||
ShapeCloud: shape.CLOUD_TYPE,
|
||||
ShapeText: shape.TEXT_TYPE,
|
||||
ShapeCode: shape.CODE_TYPE,
|
||||
ShapeClass: shape.CLASS_TYPE,
|
||||
ShapeSQLTable: shape.TABLE_TYPE,
|
||||
ShapeImage: shape.IMAGE_TYPE,
|
||||
ShapeSequenceDiagram: shape.SQUARE_TYPE,
|
||||
}
|
||||
|
||||
var SHAPE_TYPE_TO_DSL_SHAPE map[string]string
|
||||
|
|
|
|||
133
testdata/d2compiler/TestCompile/basic_sequence.exp.json
generated
vendored
Normal file
133
testdata/d2compiler/TestCompile/basic_sequence.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
{
|
||||
"graph": {
|
||||
"ast": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/basic_sequence.d2,0:0:0-3:0:33",
|
||||
"nodes": [
|
||||
{
|
||||
"map_key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/basic_sequence.d2,0:0:0-2:1:32",
|
||||
"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:31",
|
||||
"nodes": [
|
||||
{
|
||||
"map_key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/basic_sequence.d2,1:2:7-1:25:30",
|
||||
"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:25:30",
|
||||
"value": [
|
||||
{
|
||||
"string": "sequence_diagram",
|
||||
"raw_string": "sequence_diagram"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"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_diagram"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"err": null
|
||||
}
|
||||
63
testdata/d2compiler/TestCompile/root_sequence.exp.json
generated
vendored
Normal file
63
testdata/d2compiler/TestCompile/root_sequence.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
{
|
||||
"graph": {
|
||||
"ast": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/root_sequence.d2,0:0:0-1:0:24",
|
||||
"nodes": [
|
||||
{
|
||||
"map_key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/root_sequence.d2,0:0:0-0:23:23",
|
||||
"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:23:23",
|
||||
"value": [
|
||||
{
|
||||
"string": "sequence_diagram",
|
||||
"raw_string": "sequence_diagram"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"root": {
|
||||
"id": "",
|
||||
"id_val": "",
|
||||
"label_dimensions": {
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": ""
|
||||
},
|
||||
"style": {},
|
||||
"near_key": null,
|
||||
"shape": {
|
||||
"value": "sequence_diagram"
|
||||
}
|
||||
}
|
||||
},
|
||||
"edges": null,
|
||||
"objects": null
|
||||
},
|
||||
"err": null
|
||||
}
|
||||
Loading…
Reference in a new issue