This commit is contained in:
Alexander Wang 2023-07-11 13:44:00 -07:00
parent 741a9aa306
commit b193b9be8a
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
13 changed files with 26 additions and 38 deletions

View file

@ -423,7 +423,6 @@ func (s *BlockString) value() {}
func (a *Array) value() {} func (a *Array) value() {}
func (m *Map) value() {} func (m *Map) value() {}
func (i *Import) value() {} func (i *Import) value() {}
func (i *Substitution) value() {}
func (n *Null) scalar() {} func (n *Null) scalar() {}
func (b *Boolean) scalar() {} func (b *Boolean) scalar() {}
@ -924,7 +923,6 @@ type ValueBox struct {
Array *Array `json:"array,omitempty"` Array *Array `json:"array,omitempty"`
Map *Map `json:"map,omitempty"` Map *Map `json:"map,omitempty"`
Import *Import `json:"import,omitempty"` Import *Import `json:"import,omitempty"`
Substitution *Substitution `json:"substitution,omitempty"`
} }
func (vb ValueBox) Unbox() Value { func (vb ValueBox) Unbox() Value {
@ -949,8 +947,6 @@ func (vb ValueBox) Unbox() Value {
return vb.Map return vb.Map
case vb.Import != nil: case vb.Import != nil:
return vb.Import return vb.Import
case vb.Substitution != nil:
return vb.Substitution
default: default:
return nil return nil
} }
@ -979,8 +975,6 @@ func MakeValueBox(v Value) ValueBox {
vb.Map = v vb.Map = v
case *Import: case *Import:
vb.Import = v vb.Import = v
case *Substitution:
vb.Substitution = v
} }
return vb return vb
} }

View file

@ -109,11 +109,6 @@ func (c *compiler) resolveSubstitutions(refctx *RefContext) {
} }
switch { switch {
case refctx.Key.Value.Substitution != nil:
resolvedField := c.resolveSubstitution(varsMap, refctx.Key, refctx.Key.Value.Substitution)
if resolvedField != nil {
refctx.Key.Value = d2ast.MakeValueBox(resolvedField.Primary().Value)
}
case refctx.Key.Value.UnquotedString != nil: case refctx.Key.Value.UnquotedString != nil:
for i, box := range refctx.Key.Value.UnquotedString.Value { for i, box := range refctx.Key.Value.UnquotedString.Value {
if box.Substitution != nil { if box.Substitution != nil {
@ -245,7 +240,6 @@ func (c *compiler) compileMap(dst *Map, ast, scopeAST *d2ast.Map) {
} }
func (c *compiler) compileKey(refctx *RefContext) { func (c *compiler) compileKey(refctx *RefContext) {
// resolve substitutions here
c.resolveSubstitutions(refctx) c.resolveSubstitutions(refctx)
if len(refctx.Key.Edges) == 0 { if len(refctx.Key.Edges) == 0 {
c.compileField(refctx.ScopeMap, refctx.Key.Key, refctx) c.compileField(refctx.ScopeMap, refctx.Key.Key, refctx)

View file

@ -1596,9 +1596,6 @@ func (p *parser) parseValue() d2ast.ValueBox {
case '@': case '@':
box.Import = p.parseImport(false) box.Import = p.parseImport(false)
return box return box
case '$':
box.Substitution = p.parseSubstitution(false)
return box
} }
p.replay(r) p.replay(r)

View file

@ -111,7 +111,7 @@
"primary": {}, "primary": {},
"value": { "value": {
"unquoted_string": { "unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,2:5:14-2:13:22", "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,4:8:33-4:9:34",
"value": [ "value": [
{ {
"string": "im a var" "string": "im a var"

View file

@ -88,7 +88,7 @@
"primary": {}, "primary": {},
"value": { "value": {
"unquoted_string": { "unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/vars/basic/label.d2,2:5:14-2:13:22", "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/label.d2,4:4:29-4:5:30",
"value": [ "value": [
{ {
"string": "im a var" "string": "im a var"

View file

@ -181,7 +181,7 @@
"primary": {}, "primary": {},
"value": { "value": {
"unquoted_string": { "unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,4:14:49-4:17:52", "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,9:14:85-9:15:86",
"value": [ "value": [
{ {
"string": "red" "string": "red"

View file

@ -108,10 +108,13 @@
}, },
"primary": {}, "primary": {},
"value": { "value": {
"number": { "unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,2:10:19-2:11:20", "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,5:15:44-5:16:45",
"raw": "2", "value": [
"value": "2" {
"string": "2"
}
]
} }
} }
} }

View file

@ -123,7 +123,7 @@
"primary": {}, "primary": {},
"value": { "value": {
"unquoted_string": { "unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,2:17:26-2:20:29", "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,5:14:52-5:15:53",
"value": [ "value": [
{ {
"string": "red" "string": "red"

View file

@ -136,7 +136,7 @@
"primary": {}, "primary": {},
"value": { "value": {
"unquoted_string": { "unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,2:5:14-2:13:22", "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,7:8:51-7:9:52",
"value": [ "value": [
{ {
"string": "im a var" "string": "im a var"
@ -269,7 +269,7 @@
}, },
"primary": { "primary": {
"unquoted_string": { "unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,2:5:14-2:13:22", "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,7:8:51-7:9:52",
"value": [ "value": [
{ {
"string": "im a var" "string": "im a var"

View file

@ -197,7 +197,7 @@
"primary": {}, "primary": {},
"value": { "value": {
"unquoted_string": { "unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:5:14-2:13:22", "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,10:7:89-10:8:90",
"value": [ "value": [
{ {
"string": "im x var" "string": "im x var"
@ -229,7 +229,7 @@
"primary": {}, "primary": {},
"value": { "value": {
"unquoted_string": { "unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,8:9:67-8:17:75", "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,11:7:101-11:8:102",
"value": [ "value": [
{ {
"string": "im y var" "string": "im y var"
@ -380,7 +380,7 @@
"primary": {}, "primary": {},
"value": { "value": {
"unquoted_string": { "unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:5:14-2:13:22", "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,19:7:173-19:8:174",
"value": [ "value": [
{ {
"string": "im x var" "string": "im x var"
@ -412,7 +412,7 @@
"primary": {}, "primary": {},
"value": { "value": {
"unquoted_string": { "unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,17:9:151-17:17:159", "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,20:7:185-20:8:186",
"value": [ "value": [
{ {
"string": "im y var" "string": "im y var"
@ -576,7 +576,7 @@
}, },
"primary": { "primary": {
"unquoted_string": { "unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:5:14-2:13:22", "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,19:7:173-19:8:174",
"value": [ "value": [
{ {
"string": "im x var" "string": "im x var"
@ -607,7 +607,7 @@
}, },
"primary": { "primary": {
"unquoted_string": { "unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,17:9:151-17:17:159", "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,20:7:185-20:8:186",
"value": [ "value": [
{ {
"string": "im y var" "string": "im y var"
@ -855,7 +855,7 @@
}, },
"primary": { "primary": {
"unquoted_string": { "unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:5:14-2:13:22", "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,10:7:89-10:8:90",
"value": [ "value": [
{ {
"string": "im x var" "string": "im x var"
@ -886,7 +886,7 @@
}, },
"primary": { "primary": {
"unquoted_string": { "unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,8:9:67-8:17:75", "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,11:7:101-11:8:102",
"value": [ "value": [
{ {
"string": "im y var" "string": "im y var"

View file

@ -197,7 +197,7 @@
"primary": {}, "primary": {},
"value": { "value": {
"unquoted_string": { "unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,8:9:67-8:26:84", "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,10:7:98-10:8:99",
"value": [ "value": [
{ {
"string": "im replaced x var" "string": "im replaced x var"
@ -330,7 +330,7 @@
}, },
"primary": { "primary": {
"unquoted_string": { "unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,8:9:67-8:26:84", "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,10:7:98-10:8:99",
"value": [ "value": [
{ {
"string": "im replaced x var" "string": "im replaced x var"

View file

@ -136,7 +136,7 @@
"primary": {}, "primary": {},
"value": { "value": {
"unquoted_string": { "unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,2:5:14-2:13:22", "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,7:8:54-7:9:55",
"value": [ "value": [
{ {
"string": "im a var" "string": "im a var"
@ -269,7 +269,7 @@
}, },
"primary": { "primary": {
"unquoted_string": { "unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,2:5:14-2:13:22", "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,7:8:54-7:9:55",
"value": [ "value": [
{ {
"string": "im a var" "string": "im a var"

View file

@ -88,7 +88,7 @@
"primary": {}, "primary": {},
"value": { "value": {
"unquoted_string": { "unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,2:5:14-2:13:22", "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,4:4:29-4:5:30",
"value": [ "value": [
{ {
"string": "im a var" "string": "im a var"