clerk/journal/semantic/dump.go (view raw)
| 1 | package semantic |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "io" |
| 6 | "path/filepath" |
| 7 | "sort" |
| 8 | ) |
| 9 | |
| 10 | func fprint(w io.Writer, ctx *Context) { |
| 11 | // Files |
| 12 | fmt.Fprintf(w, "files (%d):\n", len(ctx.Files)) |
| 13 | for i, pf := range ctx.Files { |
| 14 | fmt.Fprintf(w, " %d: %s\n", i, filepath.Base(pf.Path)) |
| 15 | } |
| 16 | |
| 17 | // Commodities |
| 18 | csyms := make([]string, 0, len(ctx.Commodities)) |
| 19 | for sym := range ctx.Commodities { |
| 20 | csyms = append(csyms, sym) |
| 21 | } |
| 22 | sort.Strings(csyms) |
| 23 | |
| 24 | fmt.Fprintf(w, "\ncommodities (%d):\n", len(ctx.Commodities)) |
| 25 | for _, sym := range csyms { |
| 26 | info := ctx.Commodities[sym] |
| 27 | fmt.Fprintf(w, " %s\n", sym) |
| 28 | fmt.Fprintf(w, " directives: %d\n", len(info.Directives)) |
| 29 | for _, cd := range info.Directives { |
| 30 | fmt.Fprintf(w, " commodity %s\n", cd.Commodity) |
| 31 | } |
| 32 | fmt.Fprintf(w, " usages: %d\n", len(info.Usages)) |
| 33 | for _, u := range info.Usages { |
| 34 | fmt.Fprintf(w, " file %d: %s (%q)\n", u.FileIndex, u.Amount.Commodity, u.Amount.Quantity.String()) |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | // Accounts |
| 39 | anames := make([]string, 0, len(ctx.Accounts)) |
| 40 | for name := range ctx.Accounts { |
| 41 | anames = append(anames, name) |
| 42 | } |
| 43 | sort.Strings(anames) |
| 44 | |
| 45 | fmt.Fprintf(w, "\naccounts (%d):\n", len(ctx.Accounts)) |
| 46 | for _, name := range anames { |
| 47 | info := ctx.Accounts[name] |
| 48 | fmt.Fprintf(w, " %s\n", name) |
| 49 | fmt.Fprintf(w, " directives: %d\n", len(info.Directives)) |
| 50 | for _, d := range info.Directives { |
| 51 | fmt.Fprintf(w, " account %s\n", d.Account.String()) |
| 52 | } |
| 53 | fmt.Fprintf(w, " usages: %d\n", len(info.Usages)) |
| 54 | for _, u := range info.Usages { |
| 55 | fmt.Fprintf(w, " file %d: %s\n", u.FileIndex, u.Posting.Account.String()) |
| 56 | } |
| 57 | } |
| 58 | } |