Scope the layout quote outside selectors and prove parent-keyed names in their own function
This commit is contained in:
@@ -228,21 +228,31 @@ func (t *table) bindOptions(o tableOptionValues) error {
|
|||||||
if err := t.indexKeys(); err != nil {
|
if err := t.indexKeys(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if err := t.proveNamesInsideParent(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return t.sumWeights()
|
return t.sumWeights()
|
||||||
}
|
}
|
||||||
|
|
||||||
// indexKeys proves every key names one row, and keeps the index a link is proved by;
|
// proveNamesInsideParent proves a name without a key names one row inside its parent.
|
||||||
// without a key, a name names one row inside its parent.
|
func (t *table) proveNamesInsideParent() error {
|
||||||
|
if t.key >= 0 || t.name < 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
inside := make(map[string]int, t.rows())
|
||||||
|
for r := 0; r < t.rows(); r++ {
|
||||||
|
k := t.cell(r, t.parent) + "\t" + t.cell(r, t.name)
|
||||||
|
if first, dup := inside[k]; dup {
|
||||||
|
return fmt.Errorf("%s line %d: name %q repeats line %d inside %s %q; a name selects one row inside its parent", t.file, r+2, t.cell(r, t.name), first+2, t.columns[t.parent], t.cell(r, t.parent))
|
||||||
|
}
|
||||||
|
inside[k] = r
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// indexKeys proves every key names one row, and keeps the index a link is proved by.
|
||||||
func (t *table) indexKeys() error {
|
func (t *table) indexKeys() error {
|
||||||
if t.key < 0 {
|
if t.key < 0 {
|
||||||
inside := make(map[string]int, t.rows())
|
|
||||||
for r := 0; r < t.rows() && t.name >= 0; r++ {
|
|
||||||
k := t.cell(r, t.parent) + "\t" + t.cell(r, t.name)
|
|
||||||
if first, dup := inside[k]; dup {
|
|
||||||
return fmt.Errorf("%s line %d: name %q repeats line %d inside %s %q; a name selects one row inside its parent", t.file, r+2, t.cell(r, t.name), first+2, t.columns[t.parent], t.cell(r, t.parent))
|
|
||||||
}
|
|
||||||
inside[k] = r
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
t.byKey = make(map[string]int, t.rows())
|
t.byKey = make(map[string]int, t.rows())
|
||||||
|
|||||||
+1
-1
@@ -98,7 +98,7 @@ func splitArgs(s string) []string {
|
|||||||
depth, quoted, start := 0, false, 0
|
depth, quoted, start := 0, false, 0
|
||||||
for i := 0; i < len(s); i++ {
|
for i := 0; i < len(s); i++ {
|
||||||
switch c := s[i]; {
|
switch c := s[i]; {
|
||||||
case c == '\'':
|
case c == '\'' && depth == 0:
|
||||||
quoted = !quoted
|
quoted = !quoted
|
||||||
case quoted:
|
case quoted:
|
||||||
case c == '[':
|
case c == '[':
|
||||||
|
|||||||
Reference in New Issue
Block a user