diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-08-10 13:27:36 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-08-10 13:27:36 +0200 |
commit | 37747e7a968420ad384a341a2895d55ac327cc5c (patch) | |
tree | 61f456c442f51904c13b2f3450ed1df423515a28 | |
parent | c1b13e2d3700222adf8e440cb1fa1673a9904170 (diff) |
Add the Invalid and Unknown constants
-rw-r--r-- | cmd/mfmt/main.go | 10 | ||||
-rw-r--r-- | mintages/parser.go | 7 |
2 files changed, 11 insertions, 6 deletions
diff --git a/cmd/mfmt/main.go b/cmd/mfmt/main.go index 5c189ea..2c9b239 100644 --- a/cmd/mfmt/main.go +++ b/cmd/mfmt/main.go @@ -133,9 +133,9 @@ func formatSection(out io.Writer, rows []mintages.Row) { } func formatInt(n int) string { - if n < -1 { - panic("mintage count is negative and not -1") - } else if n == -1 { + if n <= mintages.Invalid { + panic(fmt.Sprintf("invalid input %d", n)) + } else if n == mintages.Unknown { return "?" } @@ -158,9 +158,9 @@ func formatInt(n int) string { func intlen(v int) int { switch { - case v < -1: + case v <= mintages.Invalid: panic("mintage count is negative and not -1") - case v == 0, v == -1: + case v == 0, v == mintages.Unknown: return 1 default: n := 0 diff --git a/mintages/parser.go b/mintages/parser.go index e5a3efc..7b782b3 100644 --- a/mintages/parser.go +++ b/mintages/parser.go @@ -9,6 +9,11 @@ import ( "unicode" ) +const ( + Unknown = -1 // Unknown mintage + Invalid = -2 // All mintages <= than this are invalid +) + type SyntaxError struct { expected, got string file string @@ -148,7 +153,7 @@ func Parse(reader io.Reader, file string) (Data, error) { for i, tok := range tokens { if tok == "?" { - row.Cols[i] = -1 + row.Cols[i] = Unknown } else { row.Cols[i] = atoiWithDots(tok) } |