Refuse a calc over digits(0) or a repeat of 0, name an option's wrong kind as JSON does, type the name scope kinds, and compile only from a jsonvalue.Value

This commit is contained in:
2026-10-08 00:02:07 +02:00
committed by Lillem4n
parent ba2ae41ffe
commit 97e72988b1
13 changed files with 106 additions and 55 deletions
+5 -4
View File
@@ -9,6 +9,7 @@ import (
"github.com/larvit/fejkdata/internal/datafiles"
"github.com/larvit/fejkdata/internal/grammar"
"github.com/larvit/fejkdata/internal/invariant"
"github.com/larvit/fejkdata/internal/jsonvalue"
)
// node is a compiled element of the namespace tree: a folder, choice, null,
@@ -89,8 +90,8 @@ func (t *template) startOf(name string) node {
// compile converts parsed JSON — a category or an inline template — into a node tree,
// validating structure up front.
func compile(v any) (node, error) {
n, err := compileItem(v, atTop)
func compile(v jsonvalue.Value) (node, error) {
n, err := compileItem(v.Any(), atTop)
if err != nil {
return nil, err
}
@@ -100,7 +101,7 @@ func compile(v any) (node, error) {
// compileCategory compiles a data file's value, which may be a table over a rows
// file beside it.
func compileCategory(c datafiles.Category) (node, error) {
if m, ok := c.JSON.(map[string]any); ok {
if m, ok := c.JSON.Any().(map[string]any); ok {
if _, isTable := m["rows"]; isTable {
return compileTable(m, c.Folders, c.Name, c.ReadRows)
}
@@ -276,7 +277,7 @@ func readOptions(m map[string]any, pos position) (templateOptions, error) {
}
if sv, ok := m["separator"]; ok {
if o.separator, ok = sv.(string); !ok {
return o, fmt.Errorf("separator must be a string, got %T", sv)
return o, fmt.Errorf("separator must be a string, not %s", jsonKind(sv))
}
}
return o, nil