d2ir: Add single field filtering

See test.
This commit is contained in:
Anmol Sethi 2023-07-29 16:32:30 -07:00
parent 0002817b0a
commit 43166110b8
No known key found for this signature in database
GPG key ID: 8CEF1878FF10ADEB
6 changed files with 1885 additions and 101 deletions

View file

@ -344,6 +344,20 @@ func (c *compiler) overlay(base *Map, f *Field) {
}
func (c *compiler) compileMap(dst *Map, ast, scopeAST *d2ast.Map) {
for _, n := range ast.Nodes {
switch {
case n.MapKey != nil:
ok := c.ampersandFilter(&RefContext{
Key: n.MapKey,
Scope: ast,
ScopeMap: dst,
ScopeAST: scopeAST,
})
if !ok {
return
}
}
}
for _, n := range ast.Nodes {
switch {
case n.MapKey != nil:
@ -407,32 +421,57 @@ func (c *compiler) compileField(dst *Map, kp *d2ast.KeyPath, refctx *RefContext)
}
}
func (c *compiler) _compileField(f *Field, refctx *RefContext) {
if refctx.Key.Ampersand {
f2 := ParentMap(f).Map().GetField(refctx.Key.Key.IDA()...)
if f2 == nil {
return
func (c *compiler) ampersandFilter(refctx *RefContext) bool {
if !refctx.Key.Ampersand {
return true
}
if len(refctx.Key.Edges) > 0 {
return true
}
fa, err := refctx.ScopeMap.EnsureField(refctx.Key.Key, refctx, false)
if err != nil {
c.err.Errors = append(c.err.Errors, err.(d2ast.Error))
return false
}
if len(fa) == 0 {
return false
}
for _, f := range fa {
ok := c._ampersandFilter(f, refctx)
if !ok {
return false
}
if refctx.Key.Primary.Unbox() != nil {
if f2.Primary_ == nil {
return
}
if refctx.Key.Primary.Unbox().ScalarString() != f2.Primary_.Value.ScalarString() {
return
}
}
return true
}
func (c *compiler) _ampersandFilter(f *Field, refctx *RefContext) bool {
f2 := ParentMap(f).Map().GetField(refctx.Key.Key.IDA()...)
if f2 == nil {
return false
}
if refctx.Key.Primary.Unbox() != nil {
if f2.Primary_ == nil {
return false
}
if refctx.Key.Value.ScalarBox().Unbox() != nil {
if f2.Primary_ == nil {
return
}
if refctx.Key.Value.ScalarBox().Unbox().ScalarString() != f2.Primary_.Value.ScalarString() {
println(refctx.Key.Value.ScalarBox().Unbox().ScalarString())
println(f2.Primary_.Value.ScalarString())
return
}
if refctx.Key.Primary.Unbox().ScalarString() != f2.Primary_.Value.ScalarString() {
return false
}
}
if refctx.Key.Value.ScalarBox().Unbox() != nil {
if f2.Primary_ == nil {
return false
}
if refctx.Key.Value.ScalarBox().Unbox().ScalarString() != f2.Primary_.Value.ScalarString() {
return false
}
}
return true
}
func (c *compiler) _compileField(f *Field, refctx *RefContext) {
if len(refctx.Key.Edges) == 0 && refctx.Key.Value.Null != nil {
// For vars, if we delete the field, it may just resolve to an outer scope var of the same name
// Instead we keep it around, so that resolveSubstitutions can find it

View file

@ -11,7 +11,7 @@ func testCompileFilters(t *testing.T) {
tca := []testCase{
{
name: "escaped",
name: "base",
run: func(t testing.TB) {
m, err := compile(t, `jacob: {
shape: circle
@ -24,9 +24,27 @@ jeremy: {
label: I'm a rectangle
}`)
assert.Success(t, err)
t.Log(m.String())
assertQuery(t, m, 1, 0, nil, "jacob")
assertQuery(t, m, 2, 0, "", "jeremy")
assertQuery(t, m, 2, 0, nil, "jeremy")
assertQuery(t, m, 0, 0, "I'm a rectangle", "jeremy.label")
},
},
{
name: "order",
run: func(t testing.TB) {
m, err := compile(t, `jacob: {
shape: circle
}
jeremy: {
shape: rectangle
}
*: {
label: I'm a rectangle
&shape: rectangle
}`)
assert.Success(t, err)
assertQuery(t, m, 1, 0, nil, "jacob")
assertQuery(t, m, 2, 0, nil, "jeremy")
assertQuery(t, m, 0, 0, "I'm a rectangle", "jeremy.label")
},
},

560
testdata/d2ir/TestCompile/filters/base#01.exp.json generated vendored Normal file
View file

@ -0,0 +1,560 @@
{
"fields": [
{
"name": "jacob",
"composite": {
"fields": [
{
"name": "shape",
"primary": {
"value": {
"range": "TestCompile/filters/base#01.d2,1:8:17-1:14:23",
"value": [
{
"string": "circle",
"raw_string": "circle"
}
]
}
},
"references": [
{
"string": {
"range": "TestCompile/filters/base#01.d2,1:1:10-1:6:15",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
},
"key_path": {
"range": "TestCompile/filters/base#01.d2,1:1:10-1:6:15",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base#01.d2,1:1:10-1:6:15",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/filters/base#01.d2,1:1:10-1:14:23",
"key": {
"range": "TestCompile/filters/base#01.d2,1:1:10-1:6:15",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base#01.d2,1:1:10-1:6:15",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/filters/base#01.d2,1:8:17-1:14:23",
"value": [
{
"string": "circle",
"raw_string": "circle"
}
]
}
}
}
}
},
{
"string": {
"range": "TestCompile/filters/base#01.d2,7:2:63-7:7:68",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
},
"key_path": {
"range": "TestCompile/filters/base#01.d2,7:2:63-7:7:68",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base#01.d2,7:2:63-7:7:68",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/filters/base#01.d2,7:1:62-7:18:79",
"ampersand": true,
"key": {
"range": "TestCompile/filters/base#01.d2,7:2:63-7:7:68",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base#01.d2,7:2:63-7:7:68",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/filters/base#01.d2,7:9:70-7:18:79",
"value": [
{
"string": "rectangle",
"raw_string": "rectangle"
}
]
}
}
}
}
}
]
}
],
"edges": null
},
"references": [
{
"string": {
"range": "TestCompile/filters/base#01.d2,0:0:0-0:5:5",
"value": [
{
"string": "jacob",
"raw_string": "jacob"
}
]
},
"key_path": {
"range": "TestCompile/filters/base#01.d2,0:0:0-0:5:5",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base#01.d2,0:0:0-0:5:5",
"value": [
{
"string": "jacob",
"raw_string": "jacob"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/filters/base#01.d2,0:0:0-2:1:25",
"key": {
"range": "TestCompile/filters/base#01.d2,0:0:0-0:5:5",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base#01.d2,0:0:0-0:5:5",
"value": [
{
"string": "jacob",
"raw_string": "jacob"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "TestCompile/filters/base#01.d2,0:7:7-2:1:25",
"nodes": [
{
"map_key": {
"range": "TestCompile/filters/base#01.d2,1:1:10-1:14:23",
"key": {
"range": "TestCompile/filters/base#01.d2,1:1:10-1:6:15",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base#01.d2,1:1:10-1:6:15",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/filters/base#01.d2,1:8:17-1:14:23",
"value": [
{
"string": "circle",
"raw_string": "circle"
}
]
}
}
}
}
]
}
}
}
}
}
]
},
{
"name": "jeremy",
"composite": {
"fields": [
{
"name": "shape",
"primary": {
"value": {
"range": "TestCompile/filters/base#01.d2,7:9:70-7:18:79",
"value": [
{
"string": "rectangle",
"raw_string": "rectangle"
}
]
}
},
"references": [
{
"string": {
"range": "TestCompile/filters/base#01.d2,4:1:37-4:6:42",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
},
"key_path": {
"range": "TestCompile/filters/base#01.d2,4:1:37-4:6:42",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base#01.d2,4:1:37-4:6:42",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/filters/base#01.d2,4:1:37-4:17:53",
"key": {
"range": "TestCompile/filters/base#01.d2,4:1:37-4:6:42",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base#01.d2,4:1:37-4:6:42",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/filters/base#01.d2,4:8:44-4:17:53",
"value": [
{
"string": "rectangle",
"raw_string": "rectangle"
}
]
}
}
}
}
},
{
"string": {
"range": "TestCompile/filters/base#01.d2,7:2:63-7:7:68",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
},
"key_path": {
"range": "TestCompile/filters/base#01.d2,7:2:63-7:7:68",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base#01.d2,7:2:63-7:7:68",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/filters/base#01.d2,7:1:62-7:18:79",
"ampersand": true,
"key": {
"range": "TestCompile/filters/base#01.d2,7:2:63-7:7:68",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base#01.d2,7:2:63-7:7:68",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/filters/base#01.d2,7:9:70-7:18:79",
"value": [
{
"string": "rectangle",
"raw_string": "rectangle"
}
]
}
}
}
}
}
]
},
{
"name": "label",
"primary": {
"value": {
"range": "TestCompile/filters/base#01.d2,8:8:88-8:23:103",
"value": [
{
"string": "I'm a rectangle",
"raw_string": "I'm a rectangle"
}
]
}
},
"references": [
{
"string": {
"range": "TestCompile/filters/base#01.d2,8:1:81-8:6:86",
"value": [
{
"string": "label",
"raw_string": "label"
}
]
},
"key_path": {
"range": "TestCompile/filters/base#01.d2,8:1:81-8:6:86",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base#01.d2,8:1:81-8:6:86",
"value": [
{
"string": "label",
"raw_string": "label"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/filters/base#01.d2,8:1:81-8:23:103",
"key": {
"range": "TestCompile/filters/base#01.d2,8:1:81-8:6:86",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base#01.d2,8:1:81-8:6:86",
"value": [
{
"string": "label",
"raw_string": "label"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/filters/base#01.d2,8:8:88-8:23:103",
"value": [
{
"string": "I'm a rectangle",
"raw_string": "I'm a rectangle"
}
]
}
}
}
}
}
]
}
],
"edges": null
},
"references": [
{
"string": {
"range": "TestCompile/filters/base#01.d2,3:0:26-3:6:32",
"value": [
{
"string": "jeremy",
"raw_string": "jeremy"
}
]
},
"key_path": {
"range": "TestCompile/filters/base#01.d2,3:0:26-3:6:32",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base#01.d2,3:0:26-3:6:32",
"value": [
{
"string": "jeremy",
"raw_string": "jeremy"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/filters/base#01.d2,3:0:26-5:1:55",
"key": {
"range": "TestCompile/filters/base#01.d2,3:0:26-3:6:32",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base#01.d2,3:0:26-3:6:32",
"value": [
{
"string": "jeremy",
"raw_string": "jeremy"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "TestCompile/filters/base#01.d2,3:8:34-5:1:55",
"nodes": [
{
"map_key": {
"range": "TestCompile/filters/base#01.d2,4:1:37-4:17:53",
"key": {
"range": "TestCompile/filters/base#01.d2,4:1:37-4:6:42",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base#01.d2,4:1:37-4:6:42",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/filters/base#01.d2,4:8:44-4:17:53",
"value": [
{
"string": "rectangle",
"raw_string": "rectangle"
}
]
}
}
}
}
]
}
}
}
}
}
]
}
],
"edges": null
}

622
testdata/d2ir/TestCompile/filters/base.exp.json generated vendored Normal file
View file

@ -0,0 +1,622 @@
{
"fields": [
{
"name": "jacob",
"composite": {
"fields": [
{
"name": "shape",
"primary": {
"value": {
"range": "TestCompile/filters/base.d2,1:8:17-1:14:23",
"value": [
{
"string": "circle",
"raw_string": "circle"
}
]
}
},
"references": [
{
"string": {
"range": "TestCompile/filters/base.d2,1:1:10-1:6:15",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
},
"key_path": {
"range": "TestCompile/filters/base.d2,1:1:10-1:6:15",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base.d2,1:1:10-1:6:15",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/filters/base.d2,1:1:10-1:14:23",
"key": {
"range": "TestCompile/filters/base.d2,1:1:10-1:6:15",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base.d2,1:1:10-1:6:15",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/filters/base.d2,1:8:17-1:14:23",
"value": [
{
"string": "circle",
"raw_string": "circle"
}
]
}
}
}
}
},
{
"string": {
"range": "TestCompile/filters/base.d2,7:2:63-7:7:68",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
},
"key_path": {
"range": "TestCompile/filters/base.d2,7:2:63-7:7:68",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base.d2,7:2:63-7:7:68",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/filters/base.d2,7:1:62-7:18:79",
"ampersand": true,
"key": {
"range": "TestCompile/filters/base.d2,7:2:63-7:7:68",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base.d2,7:2:63-7:7:68",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/filters/base.d2,7:9:70-7:18:79",
"value": [
{
"string": "rectangle",
"raw_string": "rectangle"
}
]
}
}
}
}
}
]
}
],
"edges": null
},
"references": [
{
"string": {
"range": "TestCompile/filters/base.d2,0:0:0-0:5:5",
"value": [
{
"string": "jacob",
"raw_string": "jacob"
}
]
},
"key_path": {
"range": "TestCompile/filters/base.d2,0:0:0-0:5:5",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base.d2,0:0:0-0:5:5",
"value": [
{
"string": "jacob",
"raw_string": "jacob"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/filters/base.d2,0:0:0-2:1:25",
"key": {
"range": "TestCompile/filters/base.d2,0:0:0-0:5:5",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base.d2,0:0:0-0:5:5",
"value": [
{
"string": "jacob",
"raw_string": "jacob"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "TestCompile/filters/base.d2,0:7:7-2:1:25",
"nodes": [
{
"map_key": {
"range": "TestCompile/filters/base.d2,1:1:10-1:14:23",
"key": {
"range": "TestCompile/filters/base.d2,1:1:10-1:6:15",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base.d2,1:1:10-1:6:15",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/filters/base.d2,1:8:17-1:14:23",
"value": [
{
"string": "circle",
"raw_string": "circle"
}
]
}
}
}
}
]
}
}
}
}
}
]
},
{
"name": "jeremy",
"composite": {
"fields": [
{
"name": "shape",
"primary": {
"value": {
"range": "TestCompile/filters/base.d2,7:9:70-7:18:79",
"value": [
{
"string": "rectangle",
"raw_string": "rectangle"
}
]
}
},
"references": [
{
"string": {
"range": "TestCompile/filters/base.d2,4:1:37-4:6:42",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
},
"key_path": {
"range": "TestCompile/filters/base.d2,4:1:37-4:6:42",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base.d2,4:1:37-4:6:42",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/filters/base.d2,4:1:37-4:17:53",
"key": {
"range": "TestCompile/filters/base.d2,4:1:37-4:6:42",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base.d2,4:1:37-4:6:42",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/filters/base.d2,4:8:44-4:17:53",
"value": [
{
"string": "rectangle",
"raw_string": "rectangle"
}
]
}
}
}
}
},
{
"string": {
"range": "TestCompile/filters/base.d2,7:2:63-7:7:68",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
},
"key_path": {
"range": "TestCompile/filters/base.d2,7:2:63-7:7:68",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base.d2,7:2:63-7:7:68",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/filters/base.d2,7:1:62-7:18:79",
"ampersand": true,
"key": {
"range": "TestCompile/filters/base.d2,7:2:63-7:7:68",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base.d2,7:2:63-7:7:68",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/filters/base.d2,7:9:70-7:18:79",
"value": [
{
"string": "rectangle",
"raw_string": "rectangle"
}
]
}
}
}
}
},
{
"string": {
"range": "TestCompile/filters/base.d2,7:2:63-7:7:68",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
},
"key_path": {
"range": "TestCompile/filters/base.d2,7:2:63-7:7:68",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base.d2,7:2:63-7:7:68",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/filters/base.d2,7:1:62-7:18:79",
"ampersand": true,
"key": {
"range": "TestCompile/filters/base.d2,7:2:63-7:7:68",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base.d2,7:2:63-7:7:68",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/filters/base.d2,7:9:70-7:18:79",
"value": [
{
"string": "rectangle",
"raw_string": "rectangle"
}
]
}
}
}
}
}
]
},
{
"name": "label",
"primary": {
"value": {
"range": "TestCompile/filters/base.d2,8:8:88-8:23:103",
"value": [
{
"string": "I'm a rectangle",
"raw_string": "I'm a rectangle"
}
]
}
},
"references": [
{
"string": {
"range": "TestCompile/filters/base.d2,8:1:81-8:6:86",
"value": [
{
"string": "label",
"raw_string": "label"
}
]
},
"key_path": {
"range": "TestCompile/filters/base.d2,8:1:81-8:6:86",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base.d2,8:1:81-8:6:86",
"value": [
{
"string": "label",
"raw_string": "label"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/filters/base.d2,8:1:81-8:23:103",
"key": {
"range": "TestCompile/filters/base.d2,8:1:81-8:6:86",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base.d2,8:1:81-8:6:86",
"value": [
{
"string": "label",
"raw_string": "label"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/filters/base.d2,8:8:88-8:23:103",
"value": [
{
"string": "I'm a rectangle",
"raw_string": "I'm a rectangle"
}
]
}
}
}
}
}
]
}
],
"edges": null
},
"references": [
{
"string": {
"range": "TestCompile/filters/base.d2,3:0:26-3:6:32",
"value": [
{
"string": "jeremy",
"raw_string": "jeremy"
}
]
},
"key_path": {
"range": "TestCompile/filters/base.d2,3:0:26-3:6:32",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base.d2,3:0:26-3:6:32",
"value": [
{
"string": "jeremy",
"raw_string": "jeremy"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/filters/base.d2,3:0:26-5:1:55",
"key": {
"range": "TestCompile/filters/base.d2,3:0:26-3:6:32",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base.d2,3:0:26-3:6:32",
"value": [
{
"string": "jeremy",
"raw_string": "jeremy"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "TestCompile/filters/base.d2,3:8:34-5:1:55",
"nodes": [
{
"map_key": {
"range": "TestCompile/filters/base.d2,4:1:37-4:17:53",
"key": {
"range": "TestCompile/filters/base.d2,4:1:37-4:6:42",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/base.d2,4:1:37-4:6:42",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/filters/base.d2,4:8:44-4:17:53",
"value": [
{
"string": "rectangle",
"raw_string": "rectangle"
}
]
}
}
}
}
]
}
}
}
}
}
]
}
],
"edges": null
}

View file

@ -142,83 +142,6 @@
}
}
]
},
{
"name": "label",
"primary": {
"value": {
"range": "TestCompile/filters/escaped.d2,8:8:88-8:23:103",
"value": [
{
"string": "I'm a rectangle",
"raw_string": "I'm a rectangle"
}
]
}
},
"references": [
{
"string": {
"range": "TestCompile/filters/escaped.d2,8:1:81-8:6:86",
"value": [
{
"string": "label",
"raw_string": "label"
}
]
},
"key_path": {
"range": "TestCompile/filters/escaped.d2,8:1:81-8:6:86",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/escaped.d2,8:1:81-8:6:86",
"value": [
{
"string": "label",
"raw_string": "label"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/filters/escaped.d2,8:1:81-8:23:103",
"key": {
"range": "TestCompile/filters/escaped.d2,8:1:81-8:6:86",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/escaped.d2,8:1:81-8:6:86",
"value": [
{
"string": "label",
"raw_string": "label"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/filters/escaped.d2,8:8:88-8:23:103",
"value": [
{
"string": "I'm a rectangle",
"raw_string": "I'm a rectangle"
}
]
}
}
}
}
}
]
}
],
"edges": null

622
testdata/d2ir/TestCompile/filters/order.exp.json generated vendored Normal file
View file

@ -0,0 +1,622 @@
{
"fields": [
{
"name": "jacob",
"composite": {
"fields": [
{
"name": "shape",
"primary": {
"value": {
"range": "TestCompile/filters/order.d2,1:8:17-1:14:23",
"value": [
{
"string": "circle",
"raw_string": "circle"
}
]
}
},
"references": [
{
"string": {
"range": "TestCompile/filters/order.d2,1:1:10-1:6:15",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
},
"key_path": {
"range": "TestCompile/filters/order.d2,1:1:10-1:6:15",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/order.d2,1:1:10-1:6:15",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/filters/order.d2,1:1:10-1:14:23",
"key": {
"range": "TestCompile/filters/order.d2,1:1:10-1:6:15",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/order.d2,1:1:10-1:6:15",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/filters/order.d2,1:8:17-1:14:23",
"value": [
{
"string": "circle",
"raw_string": "circle"
}
]
}
}
}
}
},
{
"string": {
"range": "TestCompile/filters/order.d2,8:2:87-8:7:92",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
},
"key_path": {
"range": "TestCompile/filters/order.d2,8:2:87-8:7:92",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/order.d2,8:2:87-8:7:92",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/filters/order.d2,8:1:86-8:18:103",
"ampersand": true,
"key": {
"range": "TestCompile/filters/order.d2,8:2:87-8:7:92",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/order.d2,8:2:87-8:7:92",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/filters/order.d2,8:9:94-8:18:103",
"value": [
{
"string": "rectangle",
"raw_string": "rectangle"
}
]
}
}
}
}
}
]
}
],
"edges": null
},
"references": [
{
"string": {
"range": "TestCompile/filters/order.d2,0:0:0-0:5:5",
"value": [
{
"string": "jacob",
"raw_string": "jacob"
}
]
},
"key_path": {
"range": "TestCompile/filters/order.d2,0:0:0-0:5:5",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/order.d2,0:0:0-0:5:5",
"value": [
{
"string": "jacob",
"raw_string": "jacob"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/filters/order.d2,0:0:0-2:1:25",
"key": {
"range": "TestCompile/filters/order.d2,0:0:0-0:5:5",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/order.d2,0:0:0-0:5:5",
"value": [
{
"string": "jacob",
"raw_string": "jacob"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "TestCompile/filters/order.d2,0:7:7-2:1:25",
"nodes": [
{
"map_key": {
"range": "TestCompile/filters/order.d2,1:1:10-1:14:23",
"key": {
"range": "TestCompile/filters/order.d2,1:1:10-1:6:15",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/order.d2,1:1:10-1:6:15",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/filters/order.d2,1:8:17-1:14:23",
"value": [
{
"string": "circle",
"raw_string": "circle"
}
]
}
}
}
}
]
}
}
}
}
}
]
},
{
"name": "jeremy",
"composite": {
"fields": [
{
"name": "shape",
"primary": {
"value": {
"range": "TestCompile/filters/order.d2,8:9:94-8:18:103",
"value": [
{
"string": "rectangle",
"raw_string": "rectangle"
}
]
}
},
"references": [
{
"string": {
"range": "TestCompile/filters/order.d2,4:1:37-4:6:42",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
},
"key_path": {
"range": "TestCompile/filters/order.d2,4:1:37-4:6:42",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/order.d2,4:1:37-4:6:42",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/filters/order.d2,4:1:37-4:17:53",
"key": {
"range": "TestCompile/filters/order.d2,4:1:37-4:6:42",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/order.d2,4:1:37-4:6:42",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/filters/order.d2,4:8:44-4:17:53",
"value": [
{
"string": "rectangle",
"raw_string": "rectangle"
}
]
}
}
}
}
},
{
"string": {
"range": "TestCompile/filters/order.d2,8:2:87-8:7:92",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
},
"key_path": {
"range": "TestCompile/filters/order.d2,8:2:87-8:7:92",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/order.d2,8:2:87-8:7:92",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/filters/order.d2,8:1:86-8:18:103",
"ampersand": true,
"key": {
"range": "TestCompile/filters/order.d2,8:2:87-8:7:92",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/order.d2,8:2:87-8:7:92",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/filters/order.d2,8:9:94-8:18:103",
"value": [
{
"string": "rectangle",
"raw_string": "rectangle"
}
]
}
}
}
}
},
{
"string": {
"range": "TestCompile/filters/order.d2,8:2:87-8:7:92",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
},
"key_path": {
"range": "TestCompile/filters/order.d2,8:2:87-8:7:92",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/order.d2,8:2:87-8:7:92",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/filters/order.d2,8:1:86-8:18:103",
"ampersand": true,
"key": {
"range": "TestCompile/filters/order.d2,8:2:87-8:7:92",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/order.d2,8:2:87-8:7:92",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/filters/order.d2,8:9:94-8:18:103",
"value": [
{
"string": "rectangle",
"raw_string": "rectangle"
}
]
}
}
}
}
}
]
},
{
"name": "label",
"primary": {
"value": {
"range": "TestCompile/filters/order.d2,7:8:69-7:23:84",
"value": [
{
"string": "I'm a rectangle",
"raw_string": "I'm a rectangle"
}
]
}
},
"references": [
{
"string": {
"range": "TestCompile/filters/order.d2,7:1:62-7:6:67",
"value": [
{
"string": "label",
"raw_string": "label"
}
]
},
"key_path": {
"range": "TestCompile/filters/order.d2,7:1:62-7:6:67",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/order.d2,7:1:62-7:6:67",
"value": [
{
"string": "label",
"raw_string": "label"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/filters/order.d2,7:1:62-7:23:84",
"key": {
"range": "TestCompile/filters/order.d2,7:1:62-7:6:67",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/order.d2,7:1:62-7:6:67",
"value": [
{
"string": "label",
"raw_string": "label"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/filters/order.d2,7:8:69-7:23:84",
"value": [
{
"string": "I'm a rectangle",
"raw_string": "I'm a rectangle"
}
]
}
}
}
}
}
]
}
],
"edges": null
},
"references": [
{
"string": {
"range": "TestCompile/filters/order.d2,3:0:26-3:6:32",
"value": [
{
"string": "jeremy",
"raw_string": "jeremy"
}
]
},
"key_path": {
"range": "TestCompile/filters/order.d2,3:0:26-3:6:32",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/order.d2,3:0:26-3:6:32",
"value": [
{
"string": "jeremy",
"raw_string": "jeremy"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/filters/order.d2,3:0:26-5:1:55",
"key": {
"range": "TestCompile/filters/order.d2,3:0:26-3:6:32",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/order.d2,3:0:26-3:6:32",
"value": [
{
"string": "jeremy",
"raw_string": "jeremy"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "TestCompile/filters/order.d2,3:8:34-5:1:55",
"nodes": [
{
"map_key": {
"range": "TestCompile/filters/order.d2,4:1:37-4:17:53",
"key": {
"range": "TestCompile/filters/order.d2,4:1:37-4:6:42",
"path": [
{
"unquoted_string": {
"range": "TestCompile/filters/order.d2,4:1:37-4:6:42",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/filters/order.d2,4:8:44-4:17:53",
"value": [
{
"string": "rectangle",
"raw_string": "rectangle"
}
]
}
}
}
}
]
}
}
}
}
}
]
}
],
"edges": null
}