Skip to content

Commit

Permalink
wip recurse
Browse files Browse the repository at this point in the history
  • Loading branch information
nhooyr committed Jul 14, 2023
1 parent fe3e5b8 commit b20ff5b
Show file tree
Hide file tree
Showing 3 changed files with 1,145 additions and 9 deletions.
8 changes: 7 additions & 1 deletion d2ir/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,11 @@ func (c *compiler) compileField(dst *Map, kp *d2ast.KeyPath, refctx *RefContext)
if len(kp.Path) == 1 {
c._compileField(f, refctx)
} else {
// TODO: recurse
// TODO: recurse with references
kp2 := *kp
kp2.Path = kp2.Path[1:]
println(d2format.Format(kp), d2format.Format(&kp2))
c.compileField(f.Map(), &kp2, refctx)
}
}
}
Expand All @@ -364,6 +368,8 @@ func (c *compiler) compileField(dst *Map, kp *d2ast.KeyPath, refctx *RefContext)
c._compileField(f, refctx)
}

func (c *compiler)

func (c *compiler) _compileField(f *Field, refctx *RefContext) {
if refctx.Key.Primary.Unbox() != nil {
f.Primary_ = &Scalar{
Expand Down
28 changes: 20 additions & 8 deletions d2ir/pattern_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ func testCompilePatterns(t *testing.T) {
t.Parallel()

tca := []testCase{
{
name: "escaped",
run: func(t testing.TB) {
m, err := compile(t, `animal: meow
action: yes
a\*: globbed`)
assert.Success(t, err)
assertQuery(t, m, 3, 0, nil, "")
assertQuery(t, m, 0, 0, "meow", "animal")
assertQuery(t, m, 0, 0, "yes", "action")
assertQuery(t, m, 0, 0, "globbed", `a\*`)
},
},
{
name: "prefix",
run: func(t testing.TB) {
Expand Down Expand Up @@ -71,16 +84,15 @@ t*ink*r*t*inke*: globbed`)
},
},
{
name: "escaped",
name: "nested/prefix-suffix/3",
run: func(t testing.TB) {
m, err := compile(t, `animal: meow
action: yes
a\*: globbed`)
m, err := compile(t, `animate.constant.tinkertinker: meow
astronaut.thinkerthinker: yes
a*n*t*.constant.t*ink*r*t*inke*: globbed`)
assert.Success(t, err)
assertQuery(t, m, 3, 0, nil, "")
assertQuery(t, m, 0, 0, "meow", "animal")
assertQuery(t, m, 0, 0, "yes", "action")
assertQuery(t, m, 0, 0, "globbed", `a\*`)
assertQuery(t, m, 6, 0, nil, "")
assertQuery(t, m, 0, 0, "globbed", "animate.constant.tinkertinker")
assertQuery(t, m, 0, 0, "globbed", "astronaut.constant.thinkerthinker")
},
},
}
Expand Down
Loading

0 comments on commit b20ff5b

Please sign in to comment.