Drop the CLI's no-data hint, keep the number underflow rule in grammar/number.go, and name the JSON a template may be
This commit is contained in:
@@ -30,7 +30,7 @@ born {date(1990-01-01,2010-12-31,'2006-01-02')}
|
||||
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,
|
||||
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
|
||||
|
||||
+2
-14
@@ -35,7 +35,7 @@ fejkdata <<'EOF'
|
||||
born {date(1990-01-01,2010-12-31,'2006-01-02')}
|
||||
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
|
||||
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
|
||||
@@ -606,7 +606,7 @@ func run(args []string, stdin io.Reader, stdout, stderr io.Writer) int {
|
||||
return 0
|
||||
}
|
||||
if err := in.write(f, src, stdout); err != nil {
|
||||
return fail(stderr, in.noDataCause(err))
|
||||
return fail(stderr, err)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
@@ -622,18 +622,6 @@ func readStdin(stdin io.Reader) (input, error) {
|
||||
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 {
|
||||
var te inputError
|
||||
if errors.As(err, &te) {
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
@@ -178,10 +177,3 @@ func (p *calcParser) ident() (CalcNode, error) {
|
||||
}
|
||||
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")
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
Reference in New Issue
Block a user