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
4 changed files with 13 additions and 23 deletions
Showing only changes of commit 9baa77c752 - Show all commits
+1 -1
View File
@@ -30,7 +30,7 @@ born {date(1990-01-01,2010-12-31,'2006-01-02')}
EOF EOF
``` ```
fejkdata renders the template on its stdin: a format string, or any JSON value. Its `{…}` tokens reach the data by reference from the root, fejkdata renders the template on its stdin: a format string, or a JSON object, array, string or `null`. Its `{…}` tokens reach the data by reference from the root,
`{/sv_SE.person.last}`, so shipped and `--data-path` categories are alike available, `{/sv_SE.person.last}`, so shipped and `--data-path` categories are alike available,
and everything outside them prints as written. A reference names a category, or a field and everything outside them prints as written. A reference names a category, or a field
inside one: each dot segment descends one level — folders, then the category (a JSON inside one: each dot segment descends one level — folders, then the category (a JSON
+2 -14
View File
@@ -35,7 +35,7 @@ fejkdata <<'EOF'
born {date(1990-01-01,2010-12-31,'2006-01-02')} born {date(1990-01-01,2010-12-31,'2006-01-02')}
EOF EOF
A template is a format string, or any JSON value. Its {…} tokens A template is a format string, or a JSON object, array, string or null. Its {…} tokens
reach the data by reference from the root, {/sv_SE.person.last}, whether the data reach the data by reference from the root, {/sv_SE.person.last}, whether the data
is shipped or layered with --data-path. A reference names a category or a dotted is shipped or layered with --data-path. A reference names a category or a dotted
path into one ({/sv_SE.person.last}), a table's row by key or name path into one ({/sv_SE.person.last}), a table's row by key or name
@@ -606,7 +606,7 @@ func run(args []string, stdin io.Reader, stdout, stderr io.Writer) int {
return 0 return 0
} }
if err := in.write(f, src, stdout); err != nil { if err := in.write(f, src, stdout); err != nil {
return fail(stderr, in.noDataCause(err)) return fail(stderr, err)
} }
return 0 return 0
} }
@@ -622,18 +622,6 @@ func readStdin(stdin io.Reader) (input, error) {
return parseInput(string(raw)), nil return parseInput(string(raw)), nil
} }
// noDataCause adds the flags that left the generator without data to an error saying none is
// loaded.
func (in invocation) noDataCause(err error) error {
if !in.noShipped || len(in.dirs) > 0 || !strings.HasSuffix(err.Error(), "no data is loaded") {
return err
}
if te, isInput := err.(inputError); isInput {
return inputError{fmt.Errorf("%w: --no-shipped-data and no --data-path", te.error)}
}
return fmt.Errorf("%w: --no-shipped-data and no --data-path", err)
}
func fail(stderr io.Writer, err error) int { func fail(stderr io.Writer, err error) int {
var te inputError var te inputError
if errors.As(err, &te) { if errors.As(err, &te) {
-8
View File
@@ -4,7 +4,6 @@ import (
"fmt" "fmt"
"slices" "slices"
"strconv" "strconv"
"strings"
"unicode" "unicode"
) )
@@ -178,10 +177,3 @@ func (p *calcParser) ident() (CalcNode, error) {
} }
return CalcVar{name, at}, nil return CalcVar{name, at}, nil
} }
// Underflows reports a number written as text that reads as f = 0 though a digit before its
// exponent is not 0, as 1e-400 does: no float64 holds the number written.
func Underflows(text string, f float64) bool {
mantissa, _, _ := strings.Cut(strings.ToLower(text), "e")
return f == 0 && strings.ContainsAny(mantissa, "123456789")
}
+10
View File
@@ -0,0 +1,10 @@
package grammar
import "strings"
// Underflows reports a number written as text that reads as f = 0 though a digit before its
// exponent is not 0, as 1e-400 does: no float64 holds the number written.
func Underflows(text string, f float64) bool {
mantissa, _, _ := strings.Cut(strings.ToLower(text), "e")
return f == 0 && strings.ContainsAny(mantissa, "123456789")
}