From 8802676b3c7b73ed6ca814bdf0c52e958543c4e5 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sat, 23 Nov 2024 18:40:36 -0800 Subject: [PATCH] reserved keywords must be unquoted --- d2ast/d2ast.go | 6 + d2compiler/compile.go | 91 +- d2compiler/compile_test.go | 5 +- d2graph/d2graph.go | 32 +- d2ir/compile.go | 22 +- d2ir/compile_test.go | 17 + d2ir/d2ir.go | 59 +- d2ir/d2ir_test.go | 4 +- d2ir/merge.go | 4 +- d2ir/pattern.go | 10 +- .../TestCompile/reserved_quoted/1.exp.json | 190 ++++ .../TestCompile/reserved_quoted/2.exp.json | 457 +++++++++ .../TestCompile/reserved_quoted/3.exp.json | 304 ++++++ .../TestCompile/reserved_quoted/4.exp.json | 284 ++++++ .../d2ir/TestCompile/fields/array.exp.json | 10 +- .../d2ir/TestCompile/fields/label.exp.json | 10 +- .../d2ir/TestCompile/fields/nested.exp.json | 20 +- .../fields/primary/nested.exp.json | 30 +- .../TestCompile/fields/primary/root.exp.json | 20 +- .../d2ir/TestCompile/fields/quoted.exp.json | 898 ++++++++++++++++++ .../d2ir/TestCompile/fields/root.exp.json | 10 +- .../imports/pattern-value.exp.json | 60 +- .../d2ir/TestCompile/imports/value.exp.json | 30 +- 23 files changed, 2442 insertions(+), 131 deletions(-) create mode 100644 testdata/d2compiler/TestCompile/reserved_quoted/1.exp.json create mode 100644 testdata/d2compiler/TestCompile/reserved_quoted/2.exp.json create mode 100644 testdata/d2compiler/TestCompile/reserved_quoted/3.exp.json create mode 100644 testdata/d2compiler/TestCompile/reserved_quoted/4.exp.json create mode 100644 testdata/d2ir/TestCompile/fields/quoted.exp.json diff --git a/d2ast/d2ast.go b/d2ast/d2ast.go index 24592d22e..446a8975b 100644 --- a/d2ast/d2ast.go +++ b/d2ast/d2ast.go @@ -338,6 +338,7 @@ type String interface { SetString(string) Copy() String _string() + IsUnquoted() bool } var _ String = &UnquotedString{} @@ -611,6 +612,11 @@ func (s *DoubleQuotedString) _string() {} func (s *SingleQuotedString) _string() {} func (s *BlockString) _string() {} +func (s *UnquotedString) IsUnquoted() bool { return true } +func (s *DoubleQuotedString) IsUnquoted() bool { return false } +func (s *SingleQuotedString) IsUnquoted() bool { return false } +func (s *BlockString) IsUnquoted() bool { return false } + type Comment struct { Range Range `json:"range"` Value string `json:"value"` diff --git a/d2compiler/compile.go b/d2compiler/compile.go index 7d4eb7ba1..dca3c6039 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -119,7 +119,7 @@ func (c *compiler) compileBoardsField(g *d2graph.Graph, ir *d2ir.Map, fieldName if f.Map() == nil { m = &d2ir.Map{} } - if g.GetBoard(f.Name) != nil { + if g.GetBoard(f.Name.ScalarString()) != nil { c.errorf(f.References[0].AST(), "board name %v already used by another board", f.Name) continue } @@ -133,7 +133,7 @@ func (c *compiler) compileBoardsField(g *d2graph.Graph, ir *d2ir.Map, fieldName if f.Primary() != nil { c.compileLabel(&g2.Root.Attributes, f) } - g2.Name = f.Name + g2.Name = f.Name.ScalarString() switch fieldName { case "layers": g.Layers = append(g.Layers, g2) @@ -149,7 +149,7 @@ func findFieldAST(ast *d2ast.Map, f *d2ir.Field) *d2ast.Map { path := []string{} curr := f for { - path = append([]string{curr.Name}, path...) + path = append([]string{curr.Name.ScalarString()}, path...) boardKind := d2ir.NodeBoardKind(curr) if boardKind == "" { break @@ -274,10 +274,10 @@ func (c *compiler) compileMap(obj *d2graph.Object, m *d2ir.Map) { } } for _, f := range m.Fields { - if f.Name == "shape" { + if f.Name.ScalarString() == "shape" && f.Name.IsUnquoted() { continue } - if _, ok := d2ast.BoardKeywords[f.Name]; ok { + if _, ok := d2ast.BoardKeywords[f.Name.ScalarString()]; ok && f.Name.IsUnquoted() { continue } c.compileField(obj, f) @@ -298,14 +298,15 @@ func (c *compiler) compileMap(obj *d2graph.Object, m *d2ir.Map) { } func (c *compiler) compileField(obj *d2graph.Object, f *d2ir.Field) { - keyword := strings.ToLower(f.Name) + keyword := strings.ToLower(f.Name.ScalarString()) _, isStyleReserved := d2ast.StyleKeywords[keyword] - if isStyleReserved { + if isStyleReserved && f.Name.IsUnquoted() { c.errorf(f.LastRef().AST(), "%v must be style.%v", f.Name, f.Name) return } _, isReserved := d2ast.SimpleReservedKeywords[keyword] - if f.Name == "classes" { + isReserved = isReserved && f.Name.IsUnquoted() + if f.Name.ScalarString() == "classes" && f.Name.IsUnquoted() { if f.Map() != nil { if len(f.Map().Edges) > 0 { c.errorf(f.Map().Edges[0].LastRef().AST(), "classes cannot contain an edge") @@ -315,26 +316,26 @@ func (c *compiler) compileField(obj *d2graph.Object, f *d2ir.Field) { continue } for _, cf := range classesField.Map().Fields { - if _, ok := d2ast.ReservedKeywords[cf.Name]; !ok { + if _, ok := d2ast.ReservedKeywords[cf.Name.ScalarString()]; !(ok && f.Name.IsUnquoted()) { c.errorf(cf.LastRef().AST(), "%s is an invalid class field, must be reserved keyword", cf.Name) } - if cf.Name == "class" { + if cf.Name.ScalarString() == "class" && cf.Name.IsUnquoted() { c.errorf(cf.LastRef().AST(), `"class" cannot appear within "classes"`) } } } } return - } else if f.Name == "vars" { + } else if f.Name.ScalarString() == "vars" && f.Name.IsUnquoted() { return - } else if f.Name == "source-arrowhead" || f.Name == "target-arrowhead" { + } else if (f.Name.ScalarString() == "source-arrowhead" || f.Name.ScalarString() == "target-arrowhead") && f.Name.IsUnquoted() { c.errorf(f.LastRef().AST(), `%#v can only be used on connections`, f.Name) return } else if isReserved { c.compileReserved(&obj.Attributes, f) return - } else if f.Name == "style" { + } else if f.Name.ScalarString() == "style" && f.Name.IsUnquoted() { if f.Map() == nil || len(f.Map().Fields) == 0 { c.errorf(f.LastRef().AST(), `"style" expected to be set to a map of key-values, or contain an additional keyword like "style.opacity: 0.4"`) return @@ -358,7 +359,7 @@ func (c *compiler) compileField(obj *d2graph.Object, f *d2ir.Field) { } parent := obj - obj = obj.EnsureChild(d2graphIDA([]string{f.Name})) + obj = obj.EnsureChild(([]d2ast.String{f.Name})) if f.Primary() != nil { c.compileLabel(&obj.Attributes, f) } @@ -440,7 +441,7 @@ func (c *compiler) compilePosition(attrs *d2graph.Attributes, f *d2ir.Field) { name := f.Name if f.Map() != nil { for _, f := range f.Map().Fields { - if f.Name == "near" { + if f.Name.ScalarString() == "near" && f.Name.IsUnquoted() { if f.Primary() == nil { c.errorf(f.LastPrimaryKey(), `invalid "near" field`) } else { @@ -452,7 +453,7 @@ func (c *compiler) compilePosition(attrs *d2graph.Attributes, f *d2ir.Field) { if _, ok := d2ast.LabelPositions[scalar.ScalarString()]; !ok { c.errorf(f.LastPrimaryKey(), `invalid "near" field`) } else { - switch name { + switch name.ScalarString() { case "label": attrs.LabelPosition = &d2graph.Scalar{} attrs.LabelPosition.Value = scalar.ScalarString() @@ -480,7 +481,7 @@ func (c *compiler) compilePosition(attrs *d2graph.Attributes, f *d2ir.Field) { func (c *compiler) compileReserved(attrs *d2graph.Attributes, f *d2ir.Field) { if f.Primary() == nil { if f.Composite != nil { - switch f.Name { + switch f.Name.ScalarString() { case "class": if arr, ok := f.Composite.(*d2ir.Array); ok { for _, class := range arr.Values { @@ -511,7 +512,7 @@ func (c *compiler) compileReserved(attrs *d2graph.Attributes, f *d2ir.Field) { return } scalar := f.Primary().Value - switch f.Name { + switch f.Name.ScalarString() { case "label": c.compileLabel(attrs, f) c.compilePosition(attrs, f) @@ -695,7 +696,7 @@ func (c *compiler) compileStyle(attrs *d2graph.Attributes, m *d2ir.Map) { } func (c *compiler) compileStyleField(attrs *d2graph.Attributes, f *d2ir.Field) { - if _, ok := d2ast.StyleKeywords[strings.ToLower(f.Name)]; !ok { + if _, ok := d2ast.StyleKeywords[strings.ToLower(f.Name.ScalarString())]; !(ok && f.Name.IsUnquoted()) { c.errorf(f.LastRef().AST(), `invalid style keyword: "%s"`, f.Name) return } @@ -704,7 +705,7 @@ func (c *compiler) compileStyleField(attrs *d2graph.Attributes, f *d2ir.Field) { } compileStyleFieldInit(attrs, f) scalar := f.Primary().Value - err := attrs.Style.Apply(f.Name, scalar.ScalarString()) + err := attrs.Style.Apply(f.Name.ScalarString(), scalar.ScalarString()) if err != nil { c.errorf(scalar, err.Error()) return @@ -712,7 +713,7 @@ func (c *compiler) compileStyleField(attrs *d2graph.Attributes, f *d2ir.Field) { } func compileStyleFieldInit(attrs *d2graph.Attributes, f *d2ir.Field) { - switch f.Name { + switch f.Name.ScalarString() { case "opacity": attrs.Style.Opacity = &d2graph.Scalar{MapKey: f.LastPrimaryKey()} case "stroke": @@ -824,8 +825,8 @@ func (c *compiler) compileEdgeMap(edge *d2graph.Edge, m *d2ir.Map) { } } for _, f := range m.Fields { - _, ok := d2ast.ReservedKeywords[f.Name] - if !ok { + _, ok := d2ast.ReservedKeywords[f.Name.ScalarString()] + if !(ok && f.Name.IsUnquoted()) { c.errorf(f.References[0].AST(), `edge map keys must be reserved keywords`) continue } @@ -834,8 +835,9 @@ func (c *compiler) compileEdgeMap(edge *d2graph.Edge, m *d2ir.Map) { } func (c *compiler) compileEdgeField(edge *d2graph.Edge, f *d2ir.Field) { - keyword := strings.ToLower(f.Name) + keyword := strings.ToLower(f.Name.ScalarString()) _, isStyleReserved := d2ast.StyleKeywords[keyword] + isStyleReserved = isStyleReserved && f.Name.IsUnquoted() if isStyleReserved { c.errorf(f.LastRef().AST(), "%v must be style.%v", f.Name, f.Name) return @@ -844,7 +846,7 @@ func (c *compiler) compileEdgeField(edge *d2graph.Edge, f *d2ir.Field) { if isReserved { c.compileReserved(&edge.Attributes, f) return - } else if f.Name == "style" { + } else if f.Name.ScalarString() == "style" { if f.Map() == nil { return } @@ -852,14 +854,14 @@ func (c *compiler) compileEdgeField(edge *d2graph.Edge, f *d2ir.Field) { return } - if f.Name == "source-arrowhead" || f.Name == "target-arrowhead" { + if (f.Name.ScalarString() == "source-arrowhead" || f.Name.ScalarString() == "target-arrowhead") && f.Name.IsUnquoted() { c.compileArrowheads(edge, f) } } func (c *compiler) compileArrowheads(edge *d2graph.Edge, f *d2ir.Field) { var attrs *d2graph.Attributes - if f.Name == "source-arrowhead" { + if f.Name.ScalarString() == "source-arrowhead" { if edge.SrcArrowhead == nil { edge.SrcArrowhead = &d2graph.Attributes{} } @@ -877,12 +879,13 @@ func (c *compiler) compileArrowheads(edge *d2graph.Edge, f *d2ir.Field) { if f.Map() != nil { for _, f2 := range f.Map().Fields { - keyword := strings.ToLower(f2.Name) + keyword := strings.ToLower(f2.Name.ScalarString()) _, isReserved := d2ast.SimpleReservedKeywords[keyword] + isReserved = isReserved && f2.Name.IsUnquoted() if isReserved { c.compileReserved(attrs, f2) continue - } else if f2.Name == "style" { + } else if f2.Name.ScalarString() == "style" && f2.Name.IsUnquoted() { if f2.Map() == nil { continue } @@ -995,7 +998,7 @@ func (c *compiler) compileSQLTable(obj *d2graph.Object) { func (c *compiler) validateKeys(obj *d2graph.Object, m *d2ir.Map) { for _, f := range m.Fields { - if _, ok := d2ast.BoardKeywords[f.Name]; ok { + if _, ok := d2ast.BoardKeywords[f.Name.ScalarString()]; ok && f.Name.IsUnquoted() { continue } c.validateKey(obj, f) @@ -1003,8 +1006,9 @@ func (c *compiler) validateKeys(obj *d2graph.Object, m *d2ir.Map) { } func (c *compiler) validateKey(obj *d2graph.Object, f *d2ir.Field) { - keyword := strings.ToLower(f.Name) + keyword := strings.ToLower(f.Name.ScalarString()) _, isReserved := d2ast.ReservedKeywords[keyword] + isReserved = isReserved && f.Name.IsUnquoted() if isReserved { switch obj.Shape.Value { case d2target.ShapeCircle, d2target.ShapeSquare: @@ -1014,7 +1018,7 @@ func (c *compiler) validateKey(obj *d2graph.Object, f *d2ir.Field) { } } - switch f.Name { + switch f.Name.ScalarString() { case "style": if obj.Style.ThreeDee != nil { if !strings.EqualFold(obj.Shape.Value, d2target.ShapeSquare) && !strings.EqualFold(obj.Shape.Value, d2target.ShapeRectangle) && !strings.EqualFold(obj.Shape.Value, d2target.ShapeHexagon) { @@ -1049,7 +1053,7 @@ func (c *compiler) validateKey(obj *d2graph.Object, f *d2ir.Field) { return } - obj, ok := obj.HasChild([]string{f.Name}) + obj, ok := obj.HasChild([]string{f.Name.ScalarString()}) if ok && f.Map() != nil { c.validateKeys(obj, f.Map()) } @@ -1284,12 +1288,9 @@ func init() { } } -func d2graphIDA(irIDA []string) (ida []string) { +func d2graphIDA(irIDA []string) (ida []d2ast.String) { for _, el := range irIDA { - n := &d2ast.KeyPath{ - Path: []*d2ast.StringBox{d2ast.MakeValueBox(d2ast.RawString(el, true)).StringBox()}, - } - ida = append(ida, d2format.Format(n)) + ida = append(ida, d2ast.RawString(el, true)) } return ida } @@ -1297,7 +1298,7 @@ func d2graphIDA(irIDA []string) (ida []string) { // Unused for now until shape: edge_group func (c *compiler) preprocessSeqDiagrams(m *d2ir.Map) { for _, f := range m.Fields { - if f.Name == "shape" && f.Primary_.Value.ScalarString() == d2target.ShapeSequenceDiagram { + if f.Name.ScalarString() == "shape" && f.Name.IsUnquoted() && f.Primary_.Value.ScalarString() == d2target.ShapeSequenceDiagram { c.preprocessEdgeGroup(m, m) return } @@ -1360,12 +1361,12 @@ func (c *compiler) preprocessEdgeGroup(seqDiagram, m *d2ir.Map) { } func hoistActor(seqDiagram *d2ir.Map, f *d2ir.Field) { - f2 := seqDiagram.GetField(f.Name) + f2 := seqDiagram.GetField(f.Name.ScalarString()) if f2 == nil { seqDiagram.Fields = append(seqDiagram.Fields, f.Copy(seqDiagram).(*d2ir.Field)) } else { d2ir.OverlayField(f2, f) - d2ir.ParentMap(f).DeleteField(f.Name) + d2ir.ParentMap(f).DeleteField(f.Name.ScalarString()) } } @@ -1410,7 +1411,7 @@ func parentSeqDiagram(n d2ir.Node) *d2ir.Map { return nil } for _, f := range m.Fields { - if f.Name == "shape" && f.Primary_.Value.ScalarString() == d2target.ShapeSequenceDiagram { + if f.Name.ScalarString() == "shape" && f.Name.IsUnquoted() && f.Primary_.Value.ScalarString() == d2target.ShapeSequenceDiagram { return m } } @@ -1478,7 +1479,7 @@ func compileConfig(ir *d2ir.Map) (*d2target.Config, error) { config.Data = make(map[string]interface{}) for _, f := range f.Map().Fields { if f.Primary() != nil { - config.Data[f.Name] = f.Primary().Value.ScalarString() + config.Data[f.Name.ScalarString()] = f.Primary().Value.ScalarString() } else if f.Composite != nil { var arr []interface{} switch c := f.Composite.(type) { @@ -1490,7 +1491,7 @@ func compileConfig(ir *d2ir.Map) (*d2target.Config, error) { } } } - config.Data[f.Name] = arr + config.Data[f.Name.ScalarString()] = arr } } } @@ -1507,7 +1508,7 @@ func compileThemeOverrides(m *d2ir.Map) (*d2target.ThemeOverrides, error) { err := &d2parser.ParseError{} FOR: for _, f := range m.Fields { - switch strings.ToUpper(f.Name) { + switch strings.ToUpper(f.Name.ScalarString()) { case "N1": themeOverrides.N1 = go2.Pointer(f.Primary().Value.ScalarString()) case "N2": diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 701dad396..d644b7fa9 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -1731,6 +1731,7 @@ y `, assertions: func(t *testing.T, g *d2graph.Graph) { assert.Equal(t, 2, len(g.Objects)) + assert.Equal(t, "x", g.Objects[0].Label.Value) }, }, { @@ -1747,7 +1748,7 @@ y `, assertions: func(t *testing.T, g *d2graph.Graph) { assert.Equal(t, 4, len(g.Objects[0].SQLTable.Columns)) - assert.Equal(t, `"shape"`, g.Objects[0].SQLTable.Columns[0].Name.Label) + assert.Equal(t, `shape`, g.Objects[0].SQLTable.Columns[0].Name.Label) }, }, { @@ -1757,7 +1758,7 @@ x `, assertions: func(t *testing.T, g *d2graph.Graph) { assert.Equal(t, 2, len(g.Objects)) - assert.Equal(t, `x.'"shape"'`, g.Objects[0].AbsID()) + assert.Equal(t, `x.shape`, g.Objects[0].AbsID()) }, }, { diff --git a/d2graph/d2graph.go b/d2graph/d2graph.go index 40c37e55e..30d9123c5 100644 --- a/d2graph/d2graph.go +++ b/d2graph/d2graph.go @@ -847,7 +847,7 @@ func (obj *Object) FindEdges(mk *d2ast.Key) ([]*Edge, bool) { return ea, true } -func (obj *Object) ensureChildEdge(ida []string) *Object { +func (obj *Object) ensureChildEdge(ida []d2ast.String) *Object { for i := range ida { switch obj.Shape.Value { case d2target.ShapeClass, d2target.ShapeSQLTable: @@ -863,12 +863,12 @@ func (obj *Object) ensureChildEdge(ida []string) *Object { // EnsureChild grabs the child by ids or creates it if it does not exist including all // intermediate nodes. -func (obj *Object) EnsureChild(ida []string) *Object { +func (obj *Object) EnsureChild(ida []d2ast.String) *Object { seq := obj.OuterSequenceDiagram() if seq != nil { for _, c := range seq.ChildrenArray { - if c.ID == ida[0] { - if obj.ID == ida[0] { + if c.ID == ida[0].ScalarString() { + if obj.ID == ida[0].ScalarString() { // In cases of a.a where EnsureChild is called on the parent a, the second a should // be created as a child of a and not as a child of the diagram. This is super // unfortunate code but alas. @@ -884,9 +884,11 @@ func (obj *Object) EnsureChild(ida []string) *Object { return obj } - _, is := d2ast.ReservedKeywordHolders[ida[0]] + _, is := d2ast.ReservedKeywordHolders[ida[0].ScalarString()] + is = is && ida[0].IsUnquoted() if len(ida) == 1 && !is { - _, ok := d2ast.ReservedKeywords[ida[0]] + _, ok := d2ast.ReservedKeywords[ida[0].ScalarString()] + ok = ok && ida[0].IsUnquoted() if ok { return obj } @@ -895,13 +897,13 @@ func (obj *Object) EnsureChild(ida []string) *Object { id := ida[0] ida = ida[1:] - if id == "_" { + if id.ScalarString() == "_" && id.IsUnquoted() { return obj.Parent.EnsureChild(ida) } - child, ok := obj.Children[strings.ToLower(id)] + child, ok := obj.Children[strings.ToLower(id.ScalarString())] if !ok { - child = obj.newObject(id) + child = obj.newObject(id.ScalarString()) } if len(ida) >= 1 { @@ -1298,10 +1300,10 @@ func (e *Edge) AbsID() string { return fmt.Sprintf("%s(%s %s %s)[%d]", commonKey, strings.Join(srcIDA, "."), e.ArrowString(), strings.Join(dstIDA, "."), e.Index) } -func (obj *Object) Connect(srcID, dstID []string, srcArrow, dstArrow bool, label string) (*Edge, error) { - for _, id := range [][]string{srcID, dstID} { +func (obj *Object) Connect(srcID, dstID []d2ast.String, srcArrow, dstArrow bool, label string) (*Edge, error) { + for _, id := range [][]d2ast.String{srcID, dstID} { for _, p := range id { - if _, ok := d2ast.ReservedKeywords[p]; ok { + if _, ok := d2ast.ReservedKeywords[p.ScalarString()]; ok && p.IsUnquoted() { return nil, errors.New("cannot connect to reserved keyword") } } @@ -1329,7 +1331,7 @@ func (obj *Object) Connect(srcID, dstID []string, srcArrow, dstArrow bool, label return e, nil } -func addSQLTableColumnIndices(e *Edge, srcID, dstID []string, obj, src, dst *Object) { +func addSQLTableColumnIndices(e *Edge, srcID, dstID []d2ast.String, obj, src, dst *Object) { if src.Shape.Value == d2target.ShapeSQLTable { if src == dst { // Ignore edge to column inside table. @@ -1339,7 +1341,7 @@ func addSQLTableColumnIndices(e *Edge, srcID, dstID []string, obj, src, dst *Obj srcAbsID := src.AbsIDArray() if len(objAbsID)+len(srcID) > len(srcAbsID) { for i, d2col := range src.SQLTable.Columns { - if d2col.Name.Label == srcID[len(srcID)-1] { + if d2col.Name.Label == srcID[len(srcID)-1].ScalarString() { d2col.Reference = dst.AbsID() e.SrcTableColumnIndex = new(int) *e.SrcTableColumnIndex = i @@ -1353,7 +1355,7 @@ func addSQLTableColumnIndices(e *Edge, srcID, dstID []string, obj, src, dst *Obj dstAbsID := dst.AbsIDArray() if len(objAbsID)+len(dstID) > len(dstAbsID) { for i, d2col := range dst.SQLTable.Columns { - if d2col.Name.Label == dstID[len(dstID)-1] { + if d2col.Name.Label == dstID[len(dstID)-1].ScalarString() { d2col.Reference = dst.AbsID() e.DstTableColumnIndex = new(int) *e.DstTableColumnIndex = i diff --git a/d2ir/compile.go b/d2ir/compile.go index ecc13a32b..41b1bce99 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -126,7 +126,7 @@ func (c *compiler) overlayClasses(m *Map) { func (c *compiler) compileSubstitutions(m *Map, varsStack []*Map) { for _, f := range m.Fields { - if f.Name == "vars" && f.Map() != nil { + if f.Name.ScalarString() == "vars" && f.Name.IsUnquoted() && f.Map() != nil { varsStack = append([]*Map{f.Map()}, varsStack...) } } @@ -148,7 +148,7 @@ func (c *compiler) compileSubstitutions(m *Map, varsStack []*Map) { } } } else if f.Map() != nil { - if f.Name == "vars" { + if f.Name.ScalarString() == "vars" && f.Name.IsUnquoted() { c.compileSubstitutions(f.Map(), varsStack) c.validateConfigs(f.Map().GetField("d2-config")) } else { @@ -179,7 +179,7 @@ func (c *compiler) validateConfigs(configs *Field) { for _, f := range configs.Map().Fields { var val string if f.Primary() == nil { - if f.Name != "theme-overrides" && f.Name != "dark-theme-overrides" && f.Name != "data" { + if f.Name.ScalarString() != "theme-overrides" && f.Name.ScalarString() != "dark-theme-overrides" && f.Name.ScalarString() != "data" { c.errorf(f.LastRef().AST(), `"%s" needs a value`, f.Name) continue } @@ -187,7 +187,7 @@ func (c *compiler) validateConfigs(configs *Field) { val = f.Primary().Value.ScalarString() } - switch f.Name { + switch f.Name.ScalarString() { case "sketch", "center": _, err := strconv.ParseBool(val) if err != nil { @@ -362,7 +362,7 @@ func (c *compiler) collectVariables(vars *Map, variables map[string]string) { } for _, f := range vars.Fields { if f.Primary() != nil { - variables[f.Name] = f.Primary().Value.ScalarString() + variables[f.Name.ScalarString()] = f.Primary().Value.ScalarString() } else if f.Map() != nil { c.collectVariables(f.Map(), variables) } @@ -398,7 +398,7 @@ func (c *compiler) resolveSubstitution(vars *Map, node Node, substitution *d2ast // // When resolving hi.vars.x, the vars stack includes itself. // So this next if clause says, "ignore if we're using the current scope's vars to try to resolve a substitution that requires a var from further in the stack" - if fok && fieldNode.Name == p.Unbox().ScalarString() && isCurrentScopeVars && parent.Name == "vars" { + if fok && fieldNode.Name.ScalarString() == p.Unbox().ScalarString() && isCurrentScopeVars && parent.Name.ScalarString() == "vars" && parent.Name.IsUnquoted() { return nil } @@ -758,7 +758,7 @@ func (c *compiler) ampersandFilter(refctx *RefContext) bool { case *Field: // The label value for fields is their key value f.Primary_ = &Scalar{ - Value: d2ast.FlatUnquotedString(n.Name), + Value: n.Name, } case *Edge: // But for edges, it's nothing @@ -834,7 +834,7 @@ func (c *compiler) _compileField(f *Field, refctx *RefContext) { // 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 if !IsVar(ParentMap(f)) { - ParentMap(f).DeleteField(f.Name) + ParentMap(f).DeleteField(f.Name.ScalarString()) return } } @@ -943,7 +943,7 @@ func (c *compiler) _compileField(f *Field, refctx *RefContext) { Value: refctx.Key.Value.ScalarBox().Unbox(), } // If the link is a board, we need to transform it into an absolute path. - if f.Name == "link" { + if f.Name.ScalarString() == "link" && f.Name.IsUnquoted() { c.compileLink(f, refctx) } } @@ -966,7 +966,7 @@ func (c *compiler) extendLinks(m *Map, importF *Field, importDir string) { nodeBoardKind := NodeBoardKind(m) importIDA := IDA(importF) for _, f := range m.Fields { - if f.Name == "link" { + if f.Name.ScalarString() == "link" && f.Name.IsUnquoted() { if nodeBoardKind != "" { c.errorf(f.LastRef().AST(), "a board itself cannot be linked; only objects within a board can be linked") continue @@ -1005,7 +1005,7 @@ func (c *compiler) extendLinks(m *Map, importF *Field, importDir string) { s := d2format.Format(kp) f.Primary_.Value = d2ast.MakeValueBox(d2ast.FlatUnquotedString(s)).ScalarBox().Unbox() } - if f.Name == "icon" && f.Primary() != nil { + if f.Name.ScalarString() == "icon" && f.Name.IsUnquoted() && f.Primary() != nil { val := f.Primary().Value.ScalarString() // It's likely a substitution if val == "" { diff --git a/d2ir/compile_test.go b/d2ir/compile_test.go index e65a03ae2..c514df86e 100644 --- a/d2ir/compile_test.go +++ b/d2ir/compile_test.go @@ -195,6 +195,23 @@ func testCompileFields(t *testing.T) { assert.String(t, `[1; 2; 3; 4]`, f.Composite.String()) }, }, + { + name: "quoted", + run: func(t testing.TB) { + m, err := compile(t, `my_table: { + shape: sql_table + width: 200 + height: 200 + "shape": string + "icon": string + "width": int + "height": int +}`) + assert.Success(t, err) + assertQuery(t, m, 0, 0, "sql_table", "my_table.shape") + assertQuery(t, m, 0, 0, "string", `my_table."shape"`) + }, + }, { name: "null", run: func(t testing.TB) { diff --git a/d2ir/d2ir.go b/d2ir/d2ir.go index ae7d35147..1a86e7271 100644 --- a/d2ir/d2ir.go +++ b/d2ir/d2ir.go @@ -176,7 +176,7 @@ type Map struct { func (m *Map) initRoot() { m.parent = &Field{ - Name: "root", + Name: d2ast.FlatUnquotedString("root"), References: []*FieldReference{{ Context_: &RefContext{ ScopeMap: m, @@ -293,7 +293,7 @@ func NodeBoardKind(n Node) BoardKind { if f == nil { return "" } - switch f.Name { + switch f.Name.ScalarString() { case "layers": return BoardLayer case "scenarios": @@ -319,7 +319,7 @@ type Field struct { parent Node importAST d2ast.Node - Name string `json:"name"` + Name d2ast.String `json:"name"` // Primary_ to avoid clashing with Primary(). We need to keep it exported for // encoding/json to marshal it so cannot prefix _ instead. @@ -458,13 +458,13 @@ func (eid *EdgeID) resolve(m *Map) (_ *EdgeID, _ *Map, common []string, _ error) eid.SrcPath = eid.SrcPath[1:] } else { mf := ParentField(m) - eid.SrcPath = append([]string{mf.Name}, eid.SrcPath...) + eid.SrcPath = append([]string{mf.Name.ScalarString()}, eid.SrcPath...) } if eid.DstPath[0] == "_" { eid.DstPath = eid.DstPath[1:] } else { mf := ParentField(m) - eid.DstPath = append([]string{mf.Name}, eid.DstPath...) + eid.DstPath = append([]string{mf.Name.ScalarString()}, eid.DstPath...) } m = ParentMap(m) if m == nil { @@ -674,8 +674,8 @@ func (m *Map) IsContainer() bool { return false } for _, f := range m.Fields { - _, isReserved := d2ast.ReservedKeywords[f.Name] - if !isReserved { + _, isReserved := d2ast.ReservedKeywords[f.Name.ScalarString()] + if !(isReserved && f.Name.IsUnquoted()) { return true } } @@ -735,7 +735,7 @@ func (m *Map) getField(ida []string) *Field { } for _, f := range m.Fields { - if !strings.EqualFold(f.Name, s) { + if !strings.EqualFold(f.Name.ScalarString(), s) { continue } if len(rest) == 0 { @@ -841,7 +841,7 @@ func (m *Map) ensureField(i int, kp *d2ast.KeyPath, refctx *RefContext, create b return nil } for _, f := range m.Fields { - if matchPattern(f.Name, us.Pattern) { + if matchPattern(f.Name.ScalarString(), us.Pattern) { if i == len(kp.Path)-1 { faAppend(f) } else { @@ -863,29 +863,28 @@ func (m *Map) ensureField(i int, kp *d2ast.KeyPath, refctx *RefContext, create b return nil } - head := kp.Path[i].Unbox().ScalarString() + head := kp.Path[i].Unbox() - if _, ok := d2ast.ReservedKeywords[strings.ToLower(head)]; ok { - head = strings.ToLower(head) - if _, ok := d2ast.CompositeReservedKeywords[head]; !ok && i < len(kp.Path)-1 { + if _, ok := d2ast.ReservedKeywords[strings.ToLower(head.ScalarString())]; ok && head.IsUnquoted() { + if _, ok := d2ast.CompositeReservedKeywords[strings.ToLower(head.ScalarString())]; !ok && i < len(kp.Path)-1 { return d2parser.Errorf(kp.Path[i].Unbox(), fmt.Sprintf(`"%s" must be the last part of the key`, head)) } } - if head == "_" { + if head.ScalarString() == "_" && head.IsUnquoted() { return d2parser.Errorf(kp.Path[i].Unbox(), `parent "_" can only be used in the beginning of paths, e.g. "_.x"`) } - if head == "classes" && NodeBoardKind(m) == "" { + if head.ScalarString() == "classes" && head.IsUnquoted() && NodeBoardKind(m) == "" { return d2parser.Errorf(kp.Path[i].Unbox(), "%s is only allowed at a board root", head) } - if findBoardKeyword(head) != -1 && NodeBoardKind(m) == "" { + if findBoardKeyword(head.ScalarString()) != -1 && head.IsUnquoted() && NodeBoardKind(m) == "" { return d2parser.Errorf(kp.Path[i].Unbox(), "%s is only allowed at a board root", head) } for _, f := range m.Fields { - if !strings.EqualFold(f.Name, head) { + if !(strings.EqualFold(f.Name.ScalarString(), head.ScalarString()) && f.Name.IsUnquoted() == head.IsUnquoted()) { continue } @@ -922,14 +921,14 @@ func (m *Map) ensureField(i int, kp *d2ast.KeyPath, refctx *RefContext, create b return nil } shape := ParentShape(m) - if _, ok := d2ast.ReservedKeywords[strings.ToLower(head)]; !ok && len(c.globRefContextStack) > 0 { + if _, ok := d2ast.ReservedKeywords[strings.ToLower(head.ScalarString())]; !(ok && head.IsUnquoted()) && len(c.globRefContextStack) > 0 { if shape == d2target.ShapeClass || shape == d2target.ShapeSQLTable { return nil } } f := &Field{ parent: m, - Name: head, + Name: kp.Path[i].Unbox(), } defer func() { if i < kp.FirstGlob() { @@ -995,7 +994,7 @@ func (m *Map) DeleteField(ida ...string) *Field { rest := ida[1:] for i, f := range m.Fields { - if !strings.EqualFold(f.Name, s) { + if !strings.EqualFold(f.Name.ScalarString(), s) { continue } if len(rest) == 0 { @@ -1022,10 +1021,10 @@ func (m *Map) DeleteField(ida ...string) *Field { // then that holder becomes meaningless and should be deleted too parent := ParentField(f) for keywordHolder := range d2ast.ReservedKeywordHolders { - if parent != nil && parent.Name == keywordHolder && len(parent.Map().Fields) == 0 { + if parent != nil && parent.Name.ScalarString() == keywordHolder && parent.Name.IsUnquoted() && len(parent.Map().Fields) == 0 { keywordHolderParentMap := ParentMap(parent) for i, f := range keywordHolderParentMap.Fields { - if f.Name == keywordHolder { + if f.Name.ScalarString() == keywordHolder && f.Name.IsUnquoted() { keywordHolderParentMap.Fields = append(keywordHolderParentMap.Fields[:i], keywordHolderParentMap.Fields[i+1:]...) break } @@ -1376,7 +1375,7 @@ func (f *Field) AST() d2ast.Node { k := &d2ast.Key{ Key: &d2ast.KeyPath{ Path: []*d2ast.StringBox{ - d2ast.MakeValueBox(d2ast.RawString(f.Name, true)).StringBox(), + d2ast.MakeValueBox(f.Name).StringBox(), }, }, } @@ -1517,7 +1516,7 @@ func IsVar(n Node) bool { if NodeBoardKind(n) != "" { return false } - if f, ok := n.(*Field); ok && f.Name == "vars" { + if f, ok := n.(*Field); ok && f.Name.ScalarString() == "vars" && f.Name.IsUnquoted() { return true } if n == (*Map)(nil) { @@ -1644,7 +1643,7 @@ func BoardIDA(n Node) (ida []string) { reverseIDA(ida) return ida } - ida = append(ida, n.Name) + ida = append(ida, n.Name.ScalarString()) case *Edge: ida = append(ida, n.IDString()) } @@ -1661,7 +1660,7 @@ func IDA(n Node) (ida []string) { for { switch n := n.(type) { case *Field: - ida = append(ida, n.Name) + ida = append(ida, n.Name.ScalarString()) if n.Root() { reverseIDA(ida) return ida @@ -1682,7 +1681,7 @@ func RelIDA(p, n Node) (ida []string) { for { switch n := n.(type) { case *Field: - ida = append(ida, n.Name) + ida = append(ida, n.Name.ScalarString()) if n.Root() { reverseIDA(ida) return ida @@ -1834,7 +1833,7 @@ func (m *Map) FindBoardRoot(path []string) *Map { if layersf != nil && layersf.Map() != nil { for _, f := range layersf.Map().Fields { - if f.Name == path[0] { + if f.Name.ScalarString() == path[0] { if len(path) == 1 { return f.Map() } @@ -1845,7 +1844,7 @@ func (m *Map) FindBoardRoot(path []string) *Map { if scenariosf != nil && scenariosf.Map() != nil { for _, f := range scenariosf.Map().Fields { - if f.Name == path[0] { + if f.Name.ScalarString() == path[0] { if len(path) == 1 { return f.Map() } @@ -1856,7 +1855,7 @@ func (m *Map) FindBoardRoot(path []string) *Map { if stepsf != nil && stepsf.Map() != nil { for _, f := range stepsf.Map().Fields { - if f.Name == path[0] { + if f.Name.ScalarString() == path[0] { if len(path) == 1 { return f.Map() } diff --git a/d2ir/d2ir_test.go b/d2ir/d2ir_test.go index c8b34dbc0..45ae84254 100644 --- a/d2ir/d2ir_test.go +++ b/d2ir/d2ir_test.go @@ -33,7 +33,7 @@ func TestCopy(t *testing.T) { const keyStr = `Absence makes the heart grow frantic.` f := &d2ir.Field{ - Name: keyStr, + Name: d2ast.FlatUnquotedString(keyStr), Primary_: s, Composite: a, @@ -48,7 +48,7 @@ func TestCopy(t *testing.T) { } m = m.Copy(nil).(*d2ir.Map) - f.Name = `Many a wife thinks her husband is the world's greatest lover.` + f.Name = d2ast.FlatUnquotedString(`Many a wife thinks her husband is the world's greatest lover.`) assert.Equal(t, m, m.Fields[0].Parent()) assert.Equal(t, keyStr, m.Fields[0].Name) diff --git a/d2ir/merge.go b/d2ir/merge.go index 3b22b27df..dd2e77be0 100644 --- a/d2ir/merge.go +++ b/d2ir/merge.go @@ -2,7 +2,7 @@ package d2ir func OverlayMap(base, overlay *Map) { for _, of := range overlay.Fields { - bf := base.GetField(of.Name) + bf := base.GetField(of.Name.ScalarString()) if bf == nil { base.Fields = append(base.Fields, of.Copy(base).(*Field)) continue @@ -31,7 +31,7 @@ func ExpandSubstitution(m, resolved *Map, placeholder *Field) { } for _, of := range resolved.Fields { - bf := m.GetField(of.Name) + bf := m.GetField(of.Name.ScalarString()) if bf == nil { m.Fields = append(m.Fields[:fi], append([]*Field{of.Copy(m).(*Field)}, m.Fields[fi:]...)...) fi++ diff --git a/d2ir/pattern.go b/d2ir/pattern.go index 474c99d38..35722e241 100644 --- a/d2ir/pattern.go +++ b/d2ir/pattern.go @@ -21,11 +21,11 @@ func (m *Map) multiGlob(pattern []string) ([]*Field, bool) { func (m *Map) _doubleGlob(fa *[]*Field) { for _, f := range m.Fields { - if _, ok := d2ast.ReservedKeywords[f.Name]; ok { - if f.Name == "layers" { + if _, ok := d2ast.ReservedKeywords[f.Name.ScalarString()]; ok && f.Name.IsUnquoted() { + if f.Name.ScalarString() == "layers" { continue } - if _, ok := d2ast.BoardKeywords[f.Name]; !ok { + if _, ok := d2ast.BoardKeywords[f.Name.ScalarString()]; !ok { continue } // We don't ever want to append layers, scenarios or steps directly. @@ -45,8 +45,8 @@ func (m *Map) _doubleGlob(fa *[]*Field) { func (m *Map) _tripleGlob(fa *[]*Field) { for _, f := range m.Fields { - if _, ok := d2ast.ReservedKeywords[f.Name]; ok { - if _, ok := d2ast.BoardKeywords[f.Name]; !ok { + if _, ok := d2ast.ReservedKeywords[f.Name.ScalarString()]; ok && f.Name.IsUnquoted() { + if _, ok := d2ast.BoardKeywords[f.Name.ScalarString()]; !ok { continue } // We don't ever want to append layers, scenarios or steps directly. diff --git a/testdata/d2compiler/TestCompile/reserved_quoted/1.exp.json b/testdata/d2compiler/TestCompile/reserved_quoted/1.exp.json new file mode 100644 index 000000000..2d3cfd527 --- /dev/null +++ b/testdata/d2compiler/TestCompile/reserved_quoted/1.exp.json @@ -0,0 +1,190 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/1.d2,0:0:0-3:0:24", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/1.d2,0:0:0-2:1:23", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/1.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/1.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/1.d2,0:3:3-2:1:23", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/1.d2,1:2:7-1:16:21", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/1.d2,1:2:7-1:9:14", + "path": [ + { + "double_quoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/1.d2,1:2:7-1:9:14", + "value": [ + { + "string": "label", + "raw_string": "label" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/1.d2,1:11:16-1:16:21", + "value": [ + { + "string": "hello", + "raw_string": "hello" + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "x", + "id_val": "x", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/1.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/1.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "label", + "id_val": "label", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/1.d2,1:2:7-1:9:14", + "path": [ + { + "double_quoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/1.d2,1:2:7-1:9:14", + "value": [ + { + "string": "label", + "raw_string": "label" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "hello" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": null +} diff --git a/testdata/d2compiler/TestCompile/reserved_quoted/2.exp.json b/testdata/d2compiler/TestCompile/reserved_quoted/2.exp.json new file mode 100644 index 000000000..003929f4e --- /dev/null +++ b/testdata/d2compiler/TestCompile/reserved_quoted/2.exp.json @@ -0,0 +1,457 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,0:0:0-9:2:128", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,0:0:0-8:1:125", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,0:0:0-0:8:8", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,0:0:0-0:8:8", + "value": [ + { + "string": "my_table", + "raw_string": "my_table" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,0:10:10-8:1:125", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,1:2:14-1:18:30", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,1:2:14-1:7:19", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,1:2:14-1:7:19", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,1:9:21-1:18:30", + "value": [ + { + "string": "sql_table", + "raw_string": "sql_table" + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,2:2:33-2:12:43", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,2:2:33-2:7:38", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,2:2:33-2:7:38", + "value": [ + { + "string": "width", + "raw_string": "width" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,2:9:40-2:12:43", + "raw": "200", + "value": "200" + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,3:2:46-3:13:57", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,3:2:46-3:8:52", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,3:2:46-3:8:52", + "value": [ + { + "string": "height", + "raw_string": "height" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,3:10:54-3:13:57", + "raw": "200", + "value": "200" + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,4:2:60-4:17:75", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,4:2:60-4:9:67", + "path": [ + { + "double_quoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,4:2:60-4:9:67", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,4:11:69-4:17:75", + "value": [ + { + "string": "string", + "raw_string": "string" + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,5:2:78-5:16:92", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,5:2:78-5:8:84", + "path": [ + { + "double_quoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,5:2:78-5:8:84", + "value": [ + { + "string": "icon", + "raw_string": "icon" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,5:10:86-5:16:92", + "value": [ + { + "string": "string", + "raw_string": "string" + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,6:2:95-6:14:107", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,6:2:95-6:9:102", + "path": [ + { + "double_quoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,6:2:95-6:9:102", + "value": [ + { + "string": "width", + "raw_string": "width" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,6:11:104-6:14:107", + "value": [ + { + "string": "int", + "raw_string": "int" + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,7:2:110-7:15:123", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,7:2:110-7:10:118", + "path": [ + { + "double_quoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,7:2:110-7:10:118", + "value": [ + { + "string": "height", + "raw_string": "height" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,7:12:120-7:15:123", + "value": [ + { + "string": "int", + "raw_string": "int" + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "my_table", + "id_val": "my_table", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,0:0:0-0:8:8", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/2.d2,0:0:0-0:8:8", + "value": [ + { + "string": "my_table", + "raw_string": "my_table" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "sql_table": { + "columns": [ + { + "name": { + "label": "shape", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0 + }, + "type": { + "label": "string", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0 + }, + "constraint": null, + "reference": "" + }, + { + "name": { + "label": "icon", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0 + }, + "type": { + "label": "string", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0 + }, + "constraint": null, + "reference": "" + }, + { + "name": { + "label": "width", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0 + }, + "type": { + "label": "int", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0 + }, + "constraint": null, + "reference": "" + }, + { + "name": { + "label": "height", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0 + }, + "type": { + "label": "int", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0 + }, + "constraint": null, + "reference": "" + } + ] + }, + "attributes": { + "label": { + "value": "my_table" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "width": { + "value": "200" + }, + "height": { + "value": "200" + }, + "near_key": null, + "shape": { + "value": "sql_table" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": null +} diff --git a/testdata/d2compiler/TestCompile/reserved_quoted/3.exp.json b/testdata/d2compiler/TestCompile/reserved_quoted/3.exp.json new file mode 100644 index 000000000..ee0fc6d36 --- /dev/null +++ b/testdata/d2compiler/TestCompile/reserved_quoted/3.exp.json @@ -0,0 +1,304 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/3.d2,0:0:0-2:2:14", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/3.d2,0:0:0-0:9:9", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/3.d2,0:0:0-0:9:9", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/3.d2,0:0:0-0:1:1", + "value": [ + { + "string": "*", + "raw_string": "*" + } + ], + "pattern": [ + "*" + ] + } + }, + { + "double_quoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/3.d2,0:2:2-0:9:9", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/3.d2,1:0:10-1:1:11", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/3.d2,1:0:10-1:1:11", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/3.d2,1:0:10-1:1:11", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "shape", + "id_val": "shape", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/3.d2,0:0:0-0:9:9", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/3.d2,0:0:0-0:1:1", + "value": [ + { + "string": "*", + "raw_string": "*" + } + ], + "pattern": [ + "*" + ] + } + }, + { + "double_quoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/3.d2,0:2:2-0:9:9", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "key_path_index": 1, + "map_key_edge_index": -1 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/3.d2,0:0:0-0:9:9", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/3.d2,0:0:0-0:1:1", + "value": [ + { + "string": "*", + "raw_string": "*" + } + ], + "pattern": [ + "*" + ] + } + }, + { + "double_quoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/3.d2,0:2:2-0:9:9", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "key_path_index": 1, + "map_key_edge_index": -1 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/3.d2,0:0:0-0:9:9", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/3.d2,0:0:0-0:1:1", + "value": [ + { + "string": "*", + "raw_string": "*" + } + ], + "pattern": [ + "*" + ] + } + }, + { + "double_quoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/3.d2,0:2:2-0:9:9", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "key_path_index": 1, + "map_key_edge_index": -1 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/3.d2,0:0:0-0:9:9", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/3.d2,0:0:0-0:1:1", + "value": [ + { + "string": "*", + "raw_string": "*" + } + ], + "pattern": [ + "*" + ] + } + }, + { + "double_quoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/3.d2,0:2:2-0:9:9", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "key_path_index": 1, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "shape" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "x", + "id_val": "x", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/3.d2,1:0:10-1:1:11", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/3.d2,1:0:10-1:1:11", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": null +} diff --git a/testdata/d2compiler/TestCompile/reserved_quoted/4.exp.json b/testdata/d2compiler/TestCompile/reserved_quoted/4.exp.json new file mode 100644 index 000000000..05f1d439a --- /dev/null +++ b/testdata/d2compiler/TestCompile/reserved_quoted/4.exp.json @@ -0,0 +1,284 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/4.d2,0:0:0-0:16:16", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/4.d2,0:0:0-0:16:16", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/4.d2,0:0:0-0:16:16", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/4.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + }, + { + "double_quoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/4.d2,0:2:2-0:9:9", + "value": [ + { + "string": "style", + "raw_string": "style" + } + ] + } + }, + { + "double_quoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/4.d2,0:10:10-0:16:16", + "value": [ + { + "string": "fill", + "raw_string": "fill" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "x", + "id_val": "x", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/4.d2,0:0:0-0:16:16", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/4.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + }, + { + "double_quoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/4.d2,0:2:2-0:9:9", + "value": [ + { + "string": "style", + "raw_string": "style" + } + ] + } + }, + { + "double_quoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/4.d2,0:10:10-0:16:16", + "value": [ + { + "string": "fill", + "raw_string": "fill" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "style", + "id_val": "style", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/4.d2,0:0:0-0:16:16", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/4.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + }, + { + "double_quoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/4.d2,0:2:2-0:9:9", + "value": [ + { + "string": "style", + "raw_string": "style" + } + ] + } + }, + { + "double_quoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/4.d2,0:10:10-0:16:16", + "value": [ + { + "string": "fill", + "raw_string": "fill" + } + ] + } + } + ] + }, + "key_path_index": 1, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "style" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "fill", + "id_val": "fill", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/4.d2,0:0:0-0:16:16", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/4.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + }, + { + "double_quoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/4.d2,0:2:2-0:9:9", + "value": [ + { + "string": "style", + "raw_string": "style" + } + ] + } + }, + { + "double_quoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/reserved_quoted/4.d2,0:10:10-0:16:16", + "value": [ + { + "string": "fill", + "raw_string": "fill" + } + ] + } + } + ] + }, + "key_path_index": 2, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "fill" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": null +} diff --git a/testdata/d2ir/TestCompile/fields/array.exp.json b/testdata/d2ir/TestCompile/fields/array.exp.json index d648144d6..78aa29981 100644 --- a/testdata/d2ir/TestCompile/fields/array.exp.json +++ b/testdata/d2ir/TestCompile/fields/array.exp.json @@ -1,7 +1,15 @@ { "fields": [ { - "name": "x", + "name": { + "range": "TestCompile/fields/array.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + }, "composite": { "values": [ { diff --git a/testdata/d2ir/TestCompile/fields/label.exp.json b/testdata/d2ir/TestCompile/fields/label.exp.json index 5c7aa801d..35311dec1 100644 --- a/testdata/d2ir/TestCompile/fields/label.exp.json +++ b/testdata/d2ir/TestCompile/fields/label.exp.json @@ -1,7 +1,15 @@ { "fields": [ { - "name": "x", + "name": { + "range": "TestCompile/fields/label.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + }, "primary": { "value": { "range": "TestCompile/fields/label.d2,0:3:3-0:6:6", diff --git a/testdata/d2ir/TestCompile/fields/nested.exp.json b/testdata/d2ir/TestCompile/fields/nested.exp.json index 3dfc1f981..f24741927 100644 --- a/testdata/d2ir/TestCompile/fields/nested.exp.json +++ b/testdata/d2ir/TestCompile/fields/nested.exp.json @@ -1,11 +1,27 @@ { "fields": [ { - "name": "x", + "name": { + "range": "TestCompile/fields/nested.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + }, "composite": { "fields": [ { - "name": "y", + "name": { + "range": "TestCompile/fields/nested.d2,0:2:2-0:3:3", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + }, "primary": { "value": { "range": "TestCompile/fields/nested.d2,0:5:5-0:8:8", diff --git a/testdata/d2ir/TestCompile/fields/primary/nested.exp.json b/testdata/d2ir/TestCompile/fields/primary/nested.exp.json index 9388dc418..d2220242c 100644 --- a/testdata/d2ir/TestCompile/fields/primary/nested.exp.json +++ b/testdata/d2ir/TestCompile/fields/primary/nested.exp.json @@ -1,11 +1,27 @@ { "fields": [ { - "name": "x", + "name": { + "range": "TestCompile/fields/primary/nested.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + }, "composite": { "fields": [ { - "name": "y", + "name": { + "range": "TestCompile/fields/primary/nested.d2,0:2:2-0:3:3", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + }, "primary": { "value": { "range": "TestCompile/fields/primary/nested.d2,0:5:5-0:8:8", @@ -20,7 +36,15 @@ "composite": { "fields": [ { - "name": "pqrs", + "name": { + "range": "TestCompile/fields/primary/nested.d2,0:11:11-0:15:15", + "value": [ + { + "string": "pqrs", + "raw_string": "pqrs" + } + ] + }, "references": [ { "string": { diff --git a/testdata/d2ir/TestCompile/fields/primary/root.exp.json b/testdata/d2ir/TestCompile/fields/primary/root.exp.json index 13a6aa1ab..920ed0a58 100644 --- a/testdata/d2ir/TestCompile/fields/primary/root.exp.json +++ b/testdata/d2ir/TestCompile/fields/primary/root.exp.json @@ -1,7 +1,15 @@ { "fields": [ { - "name": "x", + "name": { + "range": "TestCompile/fields/primary/root.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + }, "primary": { "value": { "range": "TestCompile/fields/primary/root.d2,0:3:3-0:6:6", @@ -16,7 +24,15 @@ "composite": { "fields": [ { - "name": "pqrs", + "name": { + "range": "TestCompile/fields/primary/root.d2,0:9:9-0:13:13", + "value": [ + { + "string": "pqrs", + "raw_string": "pqrs" + } + ] + }, "references": [ { "string": { diff --git a/testdata/d2ir/TestCompile/fields/quoted.exp.json b/testdata/d2ir/TestCompile/fields/quoted.exp.json new file mode 100644 index 000000000..14e00f923 --- /dev/null +++ b/testdata/d2ir/TestCompile/fields/quoted.exp.json @@ -0,0 +1,898 @@ +{ + "fields": [ + { + "name": { + "range": "TestCompile/fields/quoted.d2,0:0:0-0:8:8", + "value": [ + { + "string": "my_table", + "raw_string": "my_table" + } + ] + }, + "composite": { + "fields": [ + { + "name": { + "range": "TestCompile/fields/quoted.d2,1:2:14-1:7:19", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + }, + "primary": { + "value": { + "range": "TestCompile/fields/quoted.d2,1:9:21-1:18:30", + "value": [ + { + "string": "sql_table", + "raw_string": "sql_table" + } + ] + } + }, + "references": [ + { + "string": { + "range": "TestCompile/fields/quoted.d2,1:2:14-1:7:19", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + }, + "key_path": { + "range": "TestCompile/fields/quoted.d2,1:2:14-1:7:19", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/fields/quoted.d2,1:2:14-1:7:19", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "TestCompile/fields/quoted.d2,1:2:14-1:18:30", + "key": { + "range": "TestCompile/fields/quoted.d2,1:2:14-1:7:19", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/fields/quoted.d2,1:2:14-1:7:19", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/fields/quoted.d2,1:9:21-1:18:30", + "value": [ + { + "string": "sql_table", + "raw_string": "sql_table" + } + ] + } + } + } + }, + "due_to_glob": false, + "due_to_lazy_glob": false + } + ] + }, + { + "name": { + "range": "TestCompile/fields/quoted.d2,2:2:33-2:7:38", + "value": [ + { + "string": "width", + "raw_string": "width" + } + ] + }, + "primary": { + "value": { + "range": "TestCompile/fields/quoted.d2,2:9:40-2:12:43", + "raw": "200", + "value": "200" + } + }, + "references": [ + { + "string": { + "range": "TestCompile/fields/quoted.d2,2:2:33-2:7:38", + "value": [ + { + "string": "width", + "raw_string": "width" + } + ] + }, + "key_path": { + "range": "TestCompile/fields/quoted.d2,2:2:33-2:7:38", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/fields/quoted.d2,2:2:33-2:7:38", + "value": [ + { + "string": "width", + "raw_string": "width" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "TestCompile/fields/quoted.d2,2:2:33-2:12:43", + "key": { + "range": "TestCompile/fields/quoted.d2,2:2:33-2:7:38", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/fields/quoted.d2,2:2:33-2:7:38", + "value": [ + { + "string": "width", + "raw_string": "width" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "TestCompile/fields/quoted.d2,2:9:40-2:12:43", + "raw": "200", + "value": "200" + } + } + } + }, + "due_to_glob": false, + "due_to_lazy_glob": false + } + ] + }, + { + "name": { + "range": "TestCompile/fields/quoted.d2,3:2:46-3:8:52", + "value": [ + { + "string": "height", + "raw_string": "height" + } + ] + }, + "primary": { + "value": { + "range": "TestCompile/fields/quoted.d2,3:10:54-3:13:57", + "raw": "200", + "value": "200" + } + }, + "references": [ + { + "string": { + "range": "TestCompile/fields/quoted.d2,3:2:46-3:8:52", + "value": [ + { + "string": "height", + "raw_string": "height" + } + ] + }, + "key_path": { + "range": "TestCompile/fields/quoted.d2,3:2:46-3:8:52", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/fields/quoted.d2,3:2:46-3:8:52", + "value": [ + { + "string": "height", + "raw_string": "height" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "TestCompile/fields/quoted.d2,3:2:46-3:13:57", + "key": { + "range": "TestCompile/fields/quoted.d2,3:2:46-3:8:52", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/fields/quoted.d2,3:2:46-3:8:52", + "value": [ + { + "string": "height", + "raw_string": "height" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "TestCompile/fields/quoted.d2,3:10:54-3:13:57", + "raw": "200", + "value": "200" + } + } + } + }, + "due_to_glob": false, + "due_to_lazy_glob": false + } + ] + }, + { + "name": { + "range": "TestCompile/fields/quoted.d2,4:2:60-4:9:67", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + }, + "primary": { + "value": { + "range": "TestCompile/fields/quoted.d2,4:11:69-4:17:75", + "value": [ + { + "string": "string", + "raw_string": "string" + } + ] + } + }, + "references": [ + { + "string": { + "range": "TestCompile/fields/quoted.d2,4:2:60-4:9:67", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + }, + "key_path": { + "range": "TestCompile/fields/quoted.d2,4:2:60-4:9:67", + "path": [ + { + "double_quoted_string": { + "range": "TestCompile/fields/quoted.d2,4:2:60-4:9:67", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "TestCompile/fields/quoted.d2,4:2:60-4:17:75", + "key": { + "range": "TestCompile/fields/quoted.d2,4:2:60-4:9:67", + "path": [ + { + "double_quoted_string": { + "range": "TestCompile/fields/quoted.d2,4:2:60-4:9:67", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/fields/quoted.d2,4:11:69-4:17:75", + "value": [ + { + "string": "string", + "raw_string": "string" + } + ] + } + } + } + }, + "due_to_glob": false, + "due_to_lazy_glob": false + } + ] + }, + { + "name": { + "range": "TestCompile/fields/quoted.d2,5:2:78-5:8:84", + "value": [ + { + "string": "icon", + "raw_string": "icon" + } + ] + }, + "primary": { + "value": { + "range": "TestCompile/fields/quoted.d2,5:10:86-5:16:92", + "value": [ + { + "string": "string", + "raw_string": "string" + } + ] + } + }, + "references": [ + { + "string": { + "range": "TestCompile/fields/quoted.d2,5:2:78-5:8:84", + "value": [ + { + "string": "icon", + "raw_string": "icon" + } + ] + }, + "key_path": { + "range": "TestCompile/fields/quoted.d2,5:2:78-5:8:84", + "path": [ + { + "double_quoted_string": { + "range": "TestCompile/fields/quoted.d2,5:2:78-5:8:84", + "value": [ + { + "string": "icon", + "raw_string": "icon" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "TestCompile/fields/quoted.d2,5:2:78-5:16:92", + "key": { + "range": "TestCompile/fields/quoted.d2,5:2:78-5:8:84", + "path": [ + { + "double_quoted_string": { + "range": "TestCompile/fields/quoted.d2,5:2:78-5:8:84", + "value": [ + { + "string": "icon", + "raw_string": "icon" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/fields/quoted.d2,5:10:86-5:16:92", + "value": [ + { + "string": "string", + "raw_string": "string" + } + ] + } + } + } + }, + "due_to_glob": false, + "due_to_lazy_glob": false + } + ] + }, + { + "name": { + "range": "TestCompile/fields/quoted.d2,6:2:95-6:9:102", + "value": [ + { + "string": "width", + "raw_string": "width" + } + ] + }, + "primary": { + "value": { + "range": "TestCompile/fields/quoted.d2,6:11:104-6:14:107", + "value": [ + { + "string": "int", + "raw_string": "int" + } + ] + } + }, + "references": [ + { + "string": { + "range": "TestCompile/fields/quoted.d2,6:2:95-6:9:102", + "value": [ + { + "string": "width", + "raw_string": "width" + } + ] + }, + "key_path": { + "range": "TestCompile/fields/quoted.d2,6:2:95-6:9:102", + "path": [ + { + "double_quoted_string": { + "range": "TestCompile/fields/quoted.d2,6:2:95-6:9:102", + "value": [ + { + "string": "width", + "raw_string": "width" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "TestCompile/fields/quoted.d2,6:2:95-6:14:107", + "key": { + "range": "TestCompile/fields/quoted.d2,6:2:95-6:9:102", + "path": [ + { + "double_quoted_string": { + "range": "TestCompile/fields/quoted.d2,6:2:95-6:9:102", + "value": [ + { + "string": "width", + "raw_string": "width" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/fields/quoted.d2,6:11:104-6:14:107", + "value": [ + { + "string": "int", + "raw_string": "int" + } + ] + } + } + } + }, + "due_to_glob": false, + "due_to_lazy_glob": false + } + ] + }, + { + "name": { + "range": "TestCompile/fields/quoted.d2,7:2:110-7:10:118", + "value": [ + { + "string": "height", + "raw_string": "height" + } + ] + }, + "primary": { + "value": { + "range": "TestCompile/fields/quoted.d2,7:12:120-7:15:123", + "value": [ + { + "string": "int", + "raw_string": "int" + } + ] + } + }, + "references": [ + { + "string": { + "range": "TestCompile/fields/quoted.d2,7:2:110-7:10:118", + "value": [ + { + "string": "height", + "raw_string": "height" + } + ] + }, + "key_path": { + "range": "TestCompile/fields/quoted.d2,7:2:110-7:10:118", + "path": [ + { + "double_quoted_string": { + "range": "TestCompile/fields/quoted.d2,7:2:110-7:10:118", + "value": [ + { + "string": "height", + "raw_string": "height" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "TestCompile/fields/quoted.d2,7:2:110-7:15:123", + "key": { + "range": "TestCompile/fields/quoted.d2,7:2:110-7:10:118", + "path": [ + { + "double_quoted_string": { + "range": "TestCompile/fields/quoted.d2,7:2:110-7:10:118", + "value": [ + { + "string": "height", + "raw_string": "height" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/fields/quoted.d2,7:12:120-7:15:123", + "value": [ + { + "string": "int", + "raw_string": "int" + } + ] + } + } + } + }, + "due_to_glob": false, + "due_to_lazy_glob": false + } + ] + } + ], + "edges": null + }, + "references": [ + { + "string": { + "range": "TestCompile/fields/quoted.d2,0:0:0-0:8:8", + "value": [ + { + "string": "my_table", + "raw_string": "my_table" + } + ] + }, + "key_path": { + "range": "TestCompile/fields/quoted.d2,0:0:0-0:8:8", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/fields/quoted.d2,0:0:0-0:8:8", + "value": [ + { + "string": "my_table", + "raw_string": "my_table" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "TestCompile/fields/quoted.d2,0:0:0-8:1:125", + "key": { + "range": "TestCompile/fields/quoted.d2,0:0:0-0:8:8", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/fields/quoted.d2,0:0:0-0:8:8", + "value": [ + { + "string": "my_table", + "raw_string": "my_table" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "TestCompile/fields/quoted.d2,0:10:10-8:1:125", + "nodes": [ + { + "map_key": { + "range": "TestCompile/fields/quoted.d2,1:2:14-1:18:30", + "key": { + "range": "TestCompile/fields/quoted.d2,1:2:14-1:7:19", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/fields/quoted.d2,1:2:14-1:7:19", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/fields/quoted.d2,1:9:21-1:18:30", + "value": [ + { + "string": "sql_table", + "raw_string": "sql_table" + } + ] + } + } + } + }, + { + "map_key": { + "range": "TestCompile/fields/quoted.d2,2:2:33-2:12:43", + "key": { + "range": "TestCompile/fields/quoted.d2,2:2:33-2:7:38", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/fields/quoted.d2,2:2:33-2:7:38", + "value": [ + { + "string": "width", + "raw_string": "width" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "TestCompile/fields/quoted.d2,2:9:40-2:12:43", + "raw": "200", + "value": "200" + } + } + } + }, + { + "map_key": { + "range": "TestCompile/fields/quoted.d2,3:2:46-3:13:57", + "key": { + "range": "TestCompile/fields/quoted.d2,3:2:46-3:8:52", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/fields/quoted.d2,3:2:46-3:8:52", + "value": [ + { + "string": "height", + "raw_string": "height" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "TestCompile/fields/quoted.d2,3:10:54-3:13:57", + "raw": "200", + "value": "200" + } + } + } + }, + { + "map_key": { + "range": "TestCompile/fields/quoted.d2,4:2:60-4:17:75", + "key": { + "range": "TestCompile/fields/quoted.d2,4:2:60-4:9:67", + "path": [ + { + "double_quoted_string": { + "range": "TestCompile/fields/quoted.d2,4:2:60-4:9:67", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/fields/quoted.d2,4:11:69-4:17:75", + "value": [ + { + "string": "string", + "raw_string": "string" + } + ] + } + } + } + }, + { + "map_key": { + "range": "TestCompile/fields/quoted.d2,5:2:78-5:16:92", + "key": { + "range": "TestCompile/fields/quoted.d2,5:2:78-5:8:84", + "path": [ + { + "double_quoted_string": { + "range": "TestCompile/fields/quoted.d2,5:2:78-5:8:84", + "value": [ + { + "string": "icon", + "raw_string": "icon" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/fields/quoted.d2,5:10:86-5:16:92", + "value": [ + { + "string": "string", + "raw_string": "string" + } + ] + } + } + } + }, + { + "map_key": { + "range": "TestCompile/fields/quoted.d2,6:2:95-6:14:107", + "key": { + "range": "TestCompile/fields/quoted.d2,6:2:95-6:9:102", + "path": [ + { + "double_quoted_string": { + "range": "TestCompile/fields/quoted.d2,6:2:95-6:9:102", + "value": [ + { + "string": "width", + "raw_string": "width" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/fields/quoted.d2,6:11:104-6:14:107", + "value": [ + { + "string": "int", + "raw_string": "int" + } + ] + } + } + } + }, + { + "map_key": { + "range": "TestCompile/fields/quoted.d2,7:2:110-7:15:123", + "key": { + "range": "TestCompile/fields/quoted.d2,7:2:110-7:10:118", + "path": [ + { + "double_quoted_string": { + "range": "TestCompile/fields/quoted.d2,7:2:110-7:10:118", + "value": [ + { + "string": "height", + "raw_string": "height" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/fields/quoted.d2,7:12:120-7:15:123", + "value": [ + { + "string": "int", + "raw_string": "int" + } + ] + } + } + } + } + ] + } + } + } + }, + "due_to_glob": false, + "due_to_lazy_glob": false + } + ] + } + ], + "edges": null +} diff --git a/testdata/d2ir/TestCompile/fields/root.exp.json b/testdata/d2ir/TestCompile/fields/root.exp.json index 619b7fcc4..d099a144f 100644 --- a/testdata/d2ir/TestCompile/fields/root.exp.json +++ b/testdata/d2ir/TestCompile/fields/root.exp.json @@ -1,7 +1,15 @@ { "fields": [ { - "name": "x", + "name": { + "range": "TestCompile/fields/root.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + }, "references": [ { "string": { diff --git a/testdata/d2ir/TestCompile/imports/pattern-value.exp.json b/testdata/d2ir/TestCompile/imports/pattern-value.exp.json index d5f4c5203..8e8653a31 100644 --- a/testdata/d2ir/TestCompile/imports/pattern-value.exp.json +++ b/testdata/d2ir/TestCompile/imports/pattern-value.exp.json @@ -1,11 +1,27 @@ { "fields": [ { - "name": "userWebsite", + "name": { + "range": "index.d2,0:0:0-0:11:11", + "value": [ + { + "string": "userWebsite", + "raw_string": "userWebsite" + } + ] + }, "composite": { "fields": [ { - "name": "shape", + "name": { + "range": "x.d2,0:0:0-0:5:5", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + }, "primary": { "value": { "range": "x.d2,0:7:7-0:13:13", @@ -84,7 +100,15 @@ ] }, { - "name": "label", + "name": { + "range": "x.d2,1:0:14-1:5:19", + "value": [ + { + "string": "label", + "raw_string": "label" + } + ] + }, "primary": { "value": { "range": "x.d2,1:7:21-1:11:25", @@ -222,11 +246,27 @@ ] }, { - "name": "userMobile", + "name": { + "range": "index.d2,1:0:12-1:10:22", + "value": [ + { + "string": "userMobile", + "raw_string": "userMobile" + } + ] + }, "composite": { "fields": [ { - "name": "shape", + "name": { + "range": "x.d2,0:0:0-0:5:5", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + }, "primary": { "value": { "range": "x.d2,0:7:7-0:13:13", @@ -305,7 +345,15 @@ ] }, { - "name": "label", + "name": { + "range": "x.d2,1:0:14-1:5:19", + "value": [ + { + "string": "label", + "raw_string": "label" + } + ] + }, "primary": { "value": { "range": "x.d2,1:7:21-1:11:25", diff --git a/testdata/d2ir/TestCompile/imports/value.exp.json b/testdata/d2ir/TestCompile/imports/value.exp.json index 703c3422a..64186e6af 100644 --- a/testdata/d2ir/TestCompile/imports/value.exp.json +++ b/testdata/d2ir/TestCompile/imports/value.exp.json @@ -1,11 +1,27 @@ { "fields": [ { - "name": "x", + "name": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + }, "composite": { "fields": [ { - "name": "shape", + "name": { + "range": "x.d2,0:0:0-0:5:5", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + }, "primary": { "value": { "range": "x.d2,0:7:7-0:13:13", @@ -84,7 +100,15 @@ ] }, { - "name": "label", + "name": { + "range": "x.d2,1:0:14-1:5:19", + "value": [ + { + "string": "label", + "raw_string": "label" + } + ] + }, "primary": { "value": { "range": "x.d2,1:7:21-1:11:25",