Struct-filling: FakeStruct fills fake-tagged fields as a record, each field's Go type its datatype, and IsTemplate owns the path-or-template shape rule
Tests / vet + fmt + tests (pull_request) Successful in 1m0s
Tests / vet + fmt + tests (pull_request) Successful in 1m0s
This commit is contained in:
+20
-13
@@ -67,19 +67,7 @@ func datatypeOf(m map[string]any, pos position) (DataType, error) {
|
||||
// columnDatatype is the datatype a column's items declare. They must agree, since a
|
||||
// column holds one; a column only ever null is a string.
|
||||
func columnDatatype(n node) (DataType, error) {
|
||||
var items []*template
|
||||
var collect func(node)
|
||||
collect = func(n node) {
|
||||
switch n := n.(type) {
|
||||
case *choice:
|
||||
for _, it := range n.items {
|
||||
collect(it)
|
||||
}
|
||||
case *template:
|
||||
items = append(items, n)
|
||||
}
|
||||
}
|
||||
collect(n)
|
||||
items, _ := columnItems(n)
|
||||
if len(items) == 0 {
|
||||
return DataTypeString, nil
|
||||
}
|
||||
@@ -91,6 +79,25 @@ func columnDatatype(n node) (DataType, error) {
|
||||
return items[0].datatype, nil
|
||||
}
|
||||
|
||||
// columnItems is a column's template items, its choices unwrapped, and whether one is null.
|
||||
func columnItems(n node) (items []*template, nullable bool) {
|
||||
var collect func(node)
|
||||
collect = func(n node) {
|
||||
switch n := n.(type) {
|
||||
case *choice:
|
||||
for _, it := range n.items {
|
||||
collect(it)
|
||||
}
|
||||
case *template:
|
||||
items = append(items, n)
|
||||
case *null:
|
||||
nullable = true
|
||||
}
|
||||
}
|
||||
collect(n)
|
||||
return items, nullable
|
||||
}
|
||||
|
||||
// disagreement names the fix for two items of one column declaring different datatypes.
|
||||
func disagreement(a, b *template) error {
|
||||
typed, bare := a, b
|
||||
|
||||
Reference in New Issue
Block a user