Parse and check a format in one call, keeping compileTemplate under the complexity gate

This commit is contained in:
2026-09-24 23:27:25 +02:00
committed by Lillem4n
parent 467cb6fb18
commit 2a7499e93c
2 changed files with 10 additions and 8 deletions
+2 -8
View File
@@ -204,13 +204,10 @@ func jsonKind(v any) string {
}
func compileString(s string) (node, error) {
toks, err := parseFormat(s)
toks, err := parseChecked(s, nil)
if err != nil {
return nil, err
}
if err := checkTokens(toks, nil); err != nil {
return nil, err
}
t := &template{format: s, tokens: toks, repeat: 1, fromString: true}
if err := t.compileRefFree(); err != nil {
return nil, err
@@ -336,13 +333,10 @@ func compileTemplate(m map[string]any, pos position) (node, error) {
if len(fields) == 0 && o.repeat == 1 && !o.weighted && o.datatype == DataTypeString && o.group == "" {
return nil, fmt.Errorf("an object holding only a format is a string; write %q", o.format)
}
toks, err := parseFormat(o.format)
toks, err := parseChecked(o.format, fields)
if err != nil {
return nil, err
}
if err := checkTokens(toks, fields); err != nil {
return nil, err
}
if err := checkNestedDrawGroup(fields, o.group); err != nil {
return nil, err
}