Make great documentation goal 1.2, and plan the README's reorganisation and the nested-template gaps #33

Open
lilleman wants to merge 966 commits from worktree-todo-relative-dates-exact-counts into main
2 changed files with 10 additions and 8 deletions
Showing only changes of commit 2a7499e93c - Show all commits
+2 -8
View File
@@ -204,13 +204,10 @@ func jsonKind(v any) string {
} }
func compileString(s string) (node, error) { func compileString(s string) (node, error) {
toks, err := parseFormat(s) toks, err := parseChecked(s, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if err := checkTokens(toks, nil); err != nil {
return nil, err
}
t := &template{format: s, tokens: toks, repeat: 1, fromString: true} t := &template{format: s, tokens: toks, repeat: 1, fromString: true}
if err := t.compileRefFree(); err != nil { if err := t.compileRefFree(); err != nil {
return nil, err 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 == "" { 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) 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 { if err != nil {
return nil, err return nil, err
} }
if err := checkTokens(toks, fields); err != nil {
return nil, err
}
if err := checkNestedDrawGroup(fields, o.group); err != nil { if err := checkNestedDrawGroup(fields, o.group); err != nil {
return nil, err return nil, err
} }
+8
View File
@@ -185,6 +185,14 @@ func checkFunc(tok formatToken, fields map[string]node) error {
return nil return nil
} }
func parseChecked(format string, fields map[string]node) ([]formatToken, error) {
toks, err := parseFormat(format)
if err != nil {
return nil, err
}
return toks, checkTokens(toks, fields)
}
// checkTokens proves every parsed token names an existing field or a known function, // checkTokens proves every parsed token names an existing field or a known function,
// so a typo'd or dangling reference is a New-time error. // so a typo'd or dangling reference is a New-time error.
func checkTokens(toks []formatToken, fields map[string]node) error { func checkTokens(toks []formatToken, fields map[string]node) error {