fix underscore bug in compiler

This commit is contained in:
Alexander Wang 2023-02-14 16:45:55 -08:00
parent c57d0ee252
commit 40b4879f47
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
4 changed files with 1122 additions and 1 deletions

View file

@ -337,6 +337,13 @@ x: {
tassert.Equal(t, g.Objects[0].AbsID(), g.Objects[1].References[0].ScopeObj.AbsID())
},
},
{
name: "underscore_connection",
text: `a: {
_.c.d -> _.c.b
}
`,
},
{
name: "underscore_parent_not_root",

View file

@ -770,7 +770,8 @@ func (m *Map) CreateEdge(eid *EdgeID, refctx *RefContext) (*Edge, error) {
if len(common) > 0 {
tmp := *refctx.Edge.Src
kp := &tmp
kp.Path = kp.Path[:len(common)]
underscores := countUnderscores(kp.IDA())
kp.Path = kp.Path[underscores : len(common)+underscores]
f, err := m.EnsureField(kp, nil)
if err != nil {
return nil, err

View file

@ -0,0 +1,489 @@
{
"graph": {
"name": "",
"ast": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,0:0:0-3:0:24",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,0:0:0-2:1:23",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,0:0:0-0:1:1",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,0:0:0-0:1:1",
"value": [
{
"string": "a",
"raw_string": "a"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,0:3:3-2:0:22",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,1:2:7-1:16:21",
"edges": [
{
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,1:2:7-1:16:21",
"src": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,1:2:7-1:8:13",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,1:2:7-1:3:8",
"value": [
{
"string": "_",
"raw_string": "_"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,1:4:9-1:5:10",
"value": [
{
"string": "c",
"raw_string": "c"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,1:6:11-1:7:12",
"value": [
{
"string": "d",
"raw_string": "d"
}
]
}
}
]
},
"src_arrow": "",
"dst": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,1:10:15-1:16:21",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,1:11:16-1:12:17",
"value": [
{
"string": "_",
"raw_string": "_"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,1:13:18-1:14:19",
"value": [
{
"string": "c",
"raw_string": "c"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,1:15:20-1:16:21",
"value": [
{
"string": "b",
"raw_string": "b"
}
]
}
}
]
},
"dst_arrow": ">"
}
],
"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": [
{
"index": 0,
"minWidth": 0,
"minHeight": 0,
"label_dimensions": {
"width": 0,
"height": 0
},
"isCurve": false,
"src_arrow": false,
"dst_arrow": true,
"references": [
{
"map_key_edge_index": 0
}
],
"attributes": {
"label": {
"value": ""
},
"style": {},
"near_key": null,
"shape": {
"value": ""
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
}
],
"objects": [
{
"id": "a",
"id_val": "a",
"label_dimensions": {
"width": 0,
"height": 0
},
"references": [
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,0:0:0-0:1:1",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,0:0:0-0:1:1",
"value": [
{
"string": "a",
"raw_string": "a"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
}
],
"attributes": {
"label": {
"value": "a"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
{
"id": "c",
"id_val": "c",
"label_dimensions": {
"width": 0,
"height": 0
},
"references": [
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,1:2:7-1:8:13",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,1:2:7-1:3:8",
"value": [
{
"string": "_",
"raw_string": "_"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,1:4:9-1:5:10",
"value": [
{
"string": "c",
"raw_string": "c"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,1:6:11-1:7:12",
"value": [
{
"string": "d",
"raw_string": "d"
}
]
}
}
]
},
"key_path_index": 1,
"map_key_edge_index": 0
},
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,1:10:15-1:16:21",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,1:11:16-1:12:17",
"value": [
{
"string": "_",
"raw_string": "_"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,1:13:18-1:14:19",
"value": [
{
"string": "c",
"raw_string": "c"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,1:15:20-1:16:21",
"value": [
{
"string": "b",
"raw_string": "b"
}
]
}
}
]
},
"key_path_index": 1,
"map_key_edge_index": 0
}
],
"attributes": {
"label": {
"value": "c"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
{
"id": "d",
"id_val": "d",
"label_dimensions": {
"width": 0,
"height": 0
},
"references": [
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,1:2:7-1:8:13",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,1:2:7-1:3:8",
"value": [
{
"string": "_",
"raw_string": "_"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,1:4:9-1:5:10",
"value": [
{
"string": "c",
"raw_string": "c"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,1:6:11-1:7:12",
"value": [
{
"string": "d",
"raw_string": "d"
}
]
}
}
]
},
"key_path_index": 2,
"map_key_edge_index": 0
}
],
"attributes": {
"label": {
"value": "d"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
{
"id": "b",
"id_val": "b",
"label_dimensions": {
"width": 0,
"height": 0
},
"references": [
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,1:10:15-1:16:21",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,1:11:16-1:12:17",
"value": [
{
"string": "_",
"raw_string": "_"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,1:13:18-1:14:19",
"value": [
{
"string": "c",
"raw_string": "c"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/underscore_connection.d2,1:15:20-1:16:21",
"value": [
{
"string": "b",
"raw_string": "b"
}
]
}
}
]
},
"key_path_index": 2,
"map_key_edge_index": 0
}
],
"attributes": {
"label": {
"value": "b"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
}
]
},
"err": null
}

View file

@ -0,0 +1,624 @@
{
"graph": {
"name": "",
"ast": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,0:0:0-8:0:40",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,0:0:0-2:1:23",
"key": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,0:0:0-0:1:1",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,0:0:0-0:1:1",
"value": [
{
"string": "a",
"raw_string": "a"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,0:3:3-2:0:22",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,1:2:7-1:16:21",
"edges": [
{
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,1:2:7-1:16:21",
"src": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,1:2:7-1:8:13",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,1:2:7-1:3:8",
"value": [
{
"string": "_",
"raw_string": "_"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,1:4:9-1:5:10",
"value": [
{
"string": "c",
"raw_string": "c"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,1:6:11-1:7:12",
"value": [
{
"string": "d",
"raw_string": "d"
}
]
}
}
]
},
"src_arrow": "",
"dst": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,1:10:15-1:16:21",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,1:11:16-1:12:17",
"value": [
{
"string": "_",
"raw_string": "_"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,1:13:18-1:14:19",
"value": [
{
"string": "c",
"raw_string": "c"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,1:15:20-1:16:21",
"value": [
{
"string": "b",
"raw_string": "b"
}
]
}
}
]
},
"dst_arrow": ">"
}
],
"primary": {},
"value": {}
}
}
]
}
}
}
},
{
"map_key": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,4:0:25-7:1:39",
"key": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,4:0:25-4:1:26",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,4:0:25-4:1:26",
"value": [
{
"string": "c",
"raw_string": "c"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,4:3:28-7:0:38",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,5:2:32-5:3:33",
"key": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,5:2:32-5:3:33",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,5:2:32-5:3:33",
"value": [
{
"string": "d",
"raw_string": "d"
}
]
}
}
]
},
"primary": {},
"value": {}
}
},
{
"map_key": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,6:2:36-6:3:37",
"key": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,6:2:36-6:3:37",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,6:2:36-6:3:37",
"value": [
{
"string": "b",
"raw_string": "b"
}
]
}
}
]
},
"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": [
{
"index": 0,
"minWidth": 0,
"minHeight": 0,
"label_dimensions": {
"width": 0,
"height": 0
},
"isCurve": false,
"src_arrow": false,
"dst_arrow": true,
"references": [
{
"map_key_edge_index": 0
}
],
"attributes": {
"label": {
"value": ""
},
"style": {},
"near_key": null,
"shape": {
"value": ""
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
}
],
"objects": [
{
"id": "a",
"id_val": "a",
"label_dimensions": {
"width": 0,
"height": 0
},
"references": [
{
"key": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,0:0:0-0:1:1",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,0:0:0-0:1:1",
"value": [
{
"string": "a",
"raw_string": "a"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
}
],
"attributes": {
"label": {
"value": "a"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
{
"id": "c",
"id_val": "c",
"label_dimensions": {
"width": 0,
"height": 0
},
"references": [
{
"key": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,1:2:7-1:8:13",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,1:2:7-1:3:8",
"value": [
{
"string": "_",
"raw_string": "_"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,1:4:9-1:5:10",
"value": [
{
"string": "c",
"raw_string": "c"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,1:6:11-1:7:12",
"value": [
{
"string": "d",
"raw_string": "d"
}
]
}
}
]
},
"key_path_index": 1,
"map_key_edge_index": 0
},
{
"key": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,1:10:15-1:16:21",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,1:11:16-1:12:17",
"value": [
{
"string": "_",
"raw_string": "_"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,1:13:18-1:14:19",
"value": [
{
"string": "c",
"raw_string": "c"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,1:15:20-1:16:21",
"value": [
{
"string": "b",
"raw_string": "b"
}
]
}
}
]
},
"key_path_index": 1,
"map_key_edge_index": 0
},
{
"key": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,4:0:25-4:1:26",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,4:0:25-4:1:26",
"value": [
{
"string": "c",
"raw_string": "c"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
}
],
"attributes": {
"label": {
"value": "c"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
{
"id": "d",
"id_val": "d",
"label_dimensions": {
"width": 0,
"height": 0
},
"references": [
{
"key": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,1:2:7-1:8:13",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,1:2:7-1:3:8",
"value": [
{
"string": "_",
"raw_string": "_"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,1:4:9-1:5:10",
"value": [
{
"string": "c",
"raw_string": "c"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,1:6:11-1:7:12",
"value": [
{
"string": "d",
"raw_string": "d"
}
]
}
}
]
},
"key_path_index": 2,
"map_key_edge_index": 0
},
{
"key": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,5:2:32-5:3:33",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,5:2:32-5:3:33",
"value": [
{
"string": "d",
"raw_string": "d"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
}
],
"attributes": {
"label": {
"value": "d"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
{
"id": "b",
"id_val": "b",
"label_dimensions": {
"width": 0,
"height": 0
},
"references": [
{
"key": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,1:10:15-1:16:21",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,1:11:16-1:12:17",
"value": [
{
"string": "_",
"raw_string": "_"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,1:13:18-1:14:19",
"value": [
{
"string": "c",
"raw_string": "c"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,1:15:20-1:16:21",
"value": [
{
"string": "b",
"raw_string": "b"
}
]
}
}
]
},
"key_path_index": 2,
"map_key_edge_index": 0
},
{
"key": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,6:2:36-6:3:37",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2oracle/TestMove/underscore-connection.d2,6:2:36-6:3:37",
"value": [
{
"string": "b",
"raw_string": "b"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
}
],
"attributes": {
"label": {
"value": "b"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
}
]
},
"err": "<nil>"
}