Rename "Element" to "Block"
The term "element" is already used for an item from a collection in cty, so we'll use "block" to talk about the nested blocks in a zcl config to reduce confusion.
This commit is contained in:
parent
eca76d650c
commit
87677ae03a
@ -9,21 +9,21 @@ type File struct {
|
|||||||
Body Body
|
Body Body
|
||||||
}
|
}
|
||||||
|
|
||||||
// Element represents a nested block within a Body.
|
// Block represents a nested block within a Body.
|
||||||
type Element struct {
|
type Block struct {
|
||||||
Type string
|
Type string
|
||||||
Labels []string
|
Labels []string
|
||||||
Body Body
|
Body Body
|
||||||
|
|
||||||
DefRange Range // Range that can be considered the "definition" for seeking in an editor
|
DefRange Range // Range that can be considered the "definition" for seeking in an editor
|
||||||
TypeRange Range // Range for the element type declaration specifically.
|
TypeRange Range // Range for the block type declaration specifically.
|
||||||
LabelRanges []Range // Ranges for the label values specifically.
|
LabelRanges []Range // Ranges for the label values specifically.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Elements is a sequence of Element.
|
// Blocks is a sequence of Block.
|
||||||
type Elements []*Element
|
type Blocks []*Block
|
||||||
|
|
||||||
// Body is a container for attributes and elements. It serves as the primary
|
// Body is a container for attributes and blocks. It serves as the primary
|
||||||
// unit of heirarchical structure within configuration.
|
// unit of heirarchical structure within configuration.
|
||||||
//
|
//
|
||||||
// The content of a body cannot be meaningfully intepreted without a schema,
|
// The content of a body cannot be meaningfully intepreted without a schema,
|
||||||
@ -38,7 +38,7 @@ type Body interface {
|
|||||||
Content(schema *BodySchema) (*BodyContent, Diagnostics)
|
Content(schema *BodySchema) (*BodyContent, Diagnostics)
|
||||||
|
|
||||||
// PartialContent is like Content except that it permits the configuration
|
// PartialContent is like Content except that it permits the configuration
|
||||||
// to contain additional elements or attributes not specified in the
|
// to contain additional blocks or attributes not specified in the
|
||||||
// schema. If any are present, the returned Body is non-nil and contains
|
// schema. If any are present, the returned Body is non-nil and contains
|
||||||
// the remaining items from the body that were not selected by the schema.
|
// the remaining items from the body that were not selected by the schema.
|
||||||
PartialContent(schema *BodySchema) (*BodyContent, Body, Diagnostics)
|
PartialContent(schema *BodySchema) (*BodyContent, Body, Diagnostics)
|
||||||
@ -47,7 +47,7 @@ type Body interface {
|
|||||||
// BodyContent is the result of applying a BodySchema to a Body.
|
// BodyContent is the result of applying a BodySchema to a Body.
|
||||||
type BodyContent struct {
|
type BodyContent struct {
|
||||||
Attributes map[string]Attribute
|
Attributes map[string]Attribute
|
||||||
Elements Elements
|
Blocks Blocks
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attribute represents an attribute from within a body.
|
// Attribute represents an attribute from within a body.
|
||||||
@ -67,11 +67,11 @@ type Expression interface {
|
|||||||
// TODO: evaluation of non-literal expressions
|
// TODO: evaluation of non-literal expressions
|
||||||
}
|
}
|
||||||
|
|
||||||
// OfType filters the receiving element sequence by element type name,
|
// OfType filters the receiving block sequence by block type name,
|
||||||
// returning a new element sequence including only the elements of the
|
// returning a new block sequence including only the blocks of the
|
||||||
// requested type.
|
// requested type.
|
||||||
func (els Elements) OfType(typeName string) Elements {
|
func (els Blocks) OfType(typeName string) Blocks {
|
||||||
ret := make(Elements, 0)
|
ret := make(Blocks, 0)
|
||||||
for _, el := range els {
|
for _, el := range els {
|
||||||
if el.Type == typeName {
|
if el.Type == typeName {
|
||||||
ret = append(ret, el)
|
ret = append(ret, el)
|
||||||
@ -80,14 +80,14 @@ func (els Elements) OfType(typeName string) Elements {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
// ByType transforms the receiving elements sequence into a map from type
|
// ByType transforms the receiving block sequence into a map from type
|
||||||
// name to element sequences of only that type.
|
// name to block sequences of only that type.
|
||||||
func (els Elements) ByType() map[string]Elements {
|
func (els Blocks) ByType() map[string]Blocks {
|
||||||
ret := make(map[string]Elements)
|
ret := make(map[string]Blocks)
|
||||||
for _, el := range els {
|
for _, el := range els {
|
||||||
ty := el.Type
|
ty := el.Type
|
||||||
if ret[ty] == nil {
|
if ret[ty] == nil {
|
||||||
ret[ty] = make(Elements, 0, 1)
|
ret[ty] = make(Blocks, 0, 1)
|
||||||
}
|
}
|
||||||
ret[ty] = append(ret[ty], el)
|
ret[ty] = append(ret[ty], el)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user