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
3 changed files with 13 additions and 15 deletions
Showing only changes of commit 199cb577c5 - Show all commits
+7 -7
View File
@@ -99,12 +99,12 @@ func ParseFormat(format string) ([]Token, error) {
return nil return nil
} }
flush() flush()
if ref, name, binds := CutOutside(u.body, AsWord); binds && IndexOutside(u.body, '(') < 0 { if ref, name, binds := cutOutside(u.body, AsWord); binds && indexOutside(u.body, '(') < 0 {
toks = append(toks, Token{Kind: NameBind, Body: u.body, BoundRef: ref, Bound: name}) toks = append(toks, Token{Kind: NameBind, Body: u.body, BoundRef: ref, Bound: name})
return nil return nil
} }
if IndexOutside(u.body, '(') < 0 { if indexOutside(u.body, '(') < 0 {
toks = append(toks, Token{Kind: NameRead, Body: u.body, Arms: SplitOutside(u.body, '|')}) toks = append(toks, Token{Kind: NameRead, Body: u.body, Arms: splitOutside(u.body, '|')})
return nil return nil
} }
name, args, ok := FuncCall(u.body) name, args, ok := FuncCall(u.body)
@@ -124,16 +124,16 @@ func ParseFormat(format string) ([]Token, error) {
// FuncCall splits a "{token}" body shaped name(args) into its parts; ok is false // FuncCall splits a "{token}" body shaped name(args) into its parts; ok is false
// for a name-read body. A '(' without a trailing ')' yields ok=false. // for a name-read body. A '(' without a trailing ')' yields ok=false.
func FuncCall(body string) (name string, args []string, ok bool) { func FuncCall(body string) (name string, args []string, ok bool) {
lp := IndexOutside(body, '(') lp := indexOutside(body, '(')
if lp < 0 || !strings.HasSuffix(body, ")") { if lp < 0 || !strings.HasSuffix(body, ")") {
return "", nil, false return "", nil, false
} }
return body[:lp], SplitArgs(body[lp+1 : len(body)-1]), true return body[:lp], splitArgs(body[lp+1 : len(body)-1]), true
} }
// SplitArgs parses a function arg list: comma-separated outside a selector or a // splitArgs parses a function arg list: comma-separated outside a selector or a
// quoted layout, trimmed; empty -> none. // quoted layout, trimmed; empty -> none.
func SplitArgs(s string) []string { func splitArgs(s string) []string {
if strings.TrimSpace(s) == "" { if strings.TrimSpace(s) == "" {
return nil return nil
} }
-2
View File
@@ -16,8 +16,6 @@ var reservedList = strings.Join(strings.Split(reservedInName, ""), " ")
// CheckName rejects a name the dot path, {token} and JSON grammars cannot spell, or a struct // CheckName rejects a name the dot path, {token} and JSON grammars cannot spell, or a struct
// tag cannot read. // tag cannot read.
// Both a category or folder and a field go through it, so there is one answer to
// what a name may contain.
func CheckName(name string) error { func CheckName(name string) error {
if name == "" { if name == "" {
return fmt.Errorf("%q is empty, which is not a path segment, so List never offers it", name) return fmt.Errorf("%q is empty, which is not a path segment, so List never offers it", name)
+6 -6
View File
@@ -82,8 +82,8 @@ func checkClose(path string, i, open int) error {
return nil return nil
} }
// IndexOutside is the first c in s outside a [selector], or -1. // indexOutside is the first c in s outside a [selector], or -1.
func IndexOutside(s string, c byte) int { func indexOutside(s string, c byte) int {
depth := 0 depth := 0
for i := 0; i < len(s); i++ { for i := 0; i < len(s); i++ {
switch { switch {
@@ -98,8 +98,8 @@ func IndexOutside(s string, c byte) int {
return -1 return -1
} }
// CutOutside cuts s around the first sep outside a [selector]. // cutOutside cuts s around the first sep outside a [selector].
func CutOutside(s, sep string) (before, after string, found bool) { func cutOutside(s, sep string) (before, after string, found bool) {
depth := 0 depth := 0
for i := 0; i < len(s); i++ { for i := 0; i < len(s); i++ {
switch { switch {
@@ -114,10 +114,10 @@ func CutOutside(s, sep string) (before, after string, found bool) {
return s, "", false return s, "", false
} }
func SplitOutside(s string, c byte) []string { func splitOutside(s string, c byte) []string {
var parts []string var parts []string
for { for {
i := IndexOutside(s, c) i := indexOutside(s, c)
if i < 0 { if i < 0 {
return append(parts, s) return append(parts, s)
} }