From 59974fc740ae0ae78585e4450ffc4a6fc558f16d Mon Sep 17 00:00:00 2001 From: Oliver Lade Date: Tue, 16 Jun 2020 09:36:46 +1000 Subject: [PATCH 1/3] Disambiguate 'unexpected term type' panic messages --- ast/counter.go | 2 +- ast/from_parsernode.go | 2 +- ast/to_parsernode.go | 2 +- cmd/codegen/grammar.go | 2 +- wbnf/cutpoints.go | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ast/counter.go b/ast/counter.go index f5020bf..d4f229b 100644 --- a/ast/counter.go +++ b/ast/counter.go @@ -126,6 +126,6 @@ func (ctrs counters) termCountChildren(term parser.Term, parent counter) { case parser.ExtRef: ctrs.count(string(t), parent) default: - panic(fmt.Errorf("unexpected term type: %v %[1]T", t)) + panic(fmt.Errorf("unexpected term type for counter: %v %[1]T", t)) } } diff --git a/ast/from_parsernode.go b/ast/from_parsernode.go index a939957..569c2d1 100644 --- a/ast/from_parsernode.go +++ b/ast/from_parsernode.go @@ -209,6 +209,6 @@ func (b Branch) fromParserNode(g parser.Grammar, term parser.Term, ctrs counters } } default: - panic(fmt.Errorf("unexpected term type: %v %[1]T", t)) + panic(fmt.Errorf("unexpected term type in parser node: %v %[1]T", t)) } } diff --git a/ast/to_parsernode.go b/ast/to_parsernode.go index 43336fe..17bc0b3 100644 --- a/ast/to_parsernode.go +++ b/ast/to_parsernode.go @@ -180,6 +180,6 @@ func (b Branch) toParserNode(g parser.Grammar, term parser.Term, ctrs counters) case parser.CutPoint: return b.toParserNode(g, t.Term, ctrs) default: - panic(fmt.Errorf("unexpected term type: %v %[1]T", t)) + panic(fmt.Errorf("unexpected term type to parser node: %v %[1]T", t)) } } diff --git a/cmd/codegen/grammar.go b/cmd/codegen/grammar.go index 42067be..248e159 100644 --- a/cmd/codegen/grammar.go +++ b/cmd/codegen/grammar.go @@ -155,7 +155,7 @@ func walkTerm(term parser.Term) GoNode { case parser.ExtRef: node = stringNode("parser.ExtRef(`%s`)", safeString(string(t))) default: - panic(fmt.Errorf("unexpected term type: %v %[1]T", t)) + panic(fmt.Errorf("unexpected term type in walk: %v %[1]T", t)) } return node diff --git a/wbnf/cutpoints.go b/wbnf/cutpoints.go index 69db094..de10c0c 100644 --- a/wbnf/cutpoints.go +++ b/wbnf/cutpoints.go @@ -105,7 +105,7 @@ func findUniqueStrings(g parser.Grammar) frozen.Set { out = out.Merge(forTerm(t.Term), mergeFn) case parser.RE, parser.Rule, parser.ExtRef: // do nothing default: - panic(fmt.Errorf("unexpected term type: %v %[1]T", t)) + panic(fmt.Errorf("unexpected term type for unique string: %v %[1]T", t)) } return out } @@ -166,6 +166,6 @@ func fixTerm(term parser.Term, callback func(t parser.Term) parser.Term) parser. case parser.S, parser.REF, parser.RE, parser.Rule, parser.ExtRef: return callback(term) default: - panic(fmt.Errorf("unexpected term type: %v %[1]T", t)) + panic(fmt.Errorf("unexpected term type for fix: %v %[1]T", t)) } } From 2d8a232db7a36b27bf558104714e684016b39f45 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 16 Jun 2020 09:45:29 +1000 Subject: [PATCH 2/3] Update ast/counter.go Co-authored-by: Marcelo Cantos --- ast/counter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ast/counter.go b/ast/counter.go index d4f229b..0145648 100644 --- a/ast/counter.go +++ b/ast/counter.go @@ -126,6 +126,6 @@ func (ctrs counters) termCountChildren(term parser.Term, parent counter) { case parser.ExtRef: ctrs.count(string(t), parent) default: - panic(fmt.Errorf("unexpected term type for counter: %v %[1]T", t)) + panic(fmt.Errorf("counters.termCountChildren: unexpected term type: %v %[1]T", t)) } } From 4c765993643cc2b11b0af624840f2dac084147e5 Mon Sep 17 00:00:00 2001 From: Oliver Lade Date: Tue, 16 Jun 2020 09:50:22 +1000 Subject: [PATCH 3/3] Prefix error strings with method name --- ast/from_parsernode.go | 2 +- ast/to_parsernode.go | 2 +- cmd/codegen/grammar.go | 2 +- wbnf/cutpoints.go | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ast/from_parsernode.go b/ast/from_parsernode.go index 569c2d1..1f788ab 100644 --- a/ast/from_parsernode.go +++ b/ast/from_parsernode.go @@ -209,6 +209,6 @@ func (b Branch) fromParserNode(g parser.Grammar, term parser.Term, ctrs counters } } default: - panic(fmt.Errorf("unexpected term type in parser node: %v %[1]T", t)) + panic(fmt.Errorf("branch.fromParserNode: unexpected term type: %v %[1]T", t)) } } diff --git a/ast/to_parsernode.go b/ast/to_parsernode.go index 17bc0b3..c368009 100644 --- a/ast/to_parsernode.go +++ b/ast/to_parsernode.go @@ -180,6 +180,6 @@ func (b Branch) toParserNode(g parser.Grammar, term parser.Term, ctrs counters) case parser.CutPoint: return b.toParserNode(g, t.Term, ctrs) default: - panic(fmt.Errorf("unexpected term type to parser node: %v %[1]T", t)) + panic(fmt.Errorf("branch.toParserNode: unexpected term type: %v %[1]T", t)) } } diff --git a/cmd/codegen/grammar.go b/cmd/codegen/grammar.go index 248e159..40b5955 100644 --- a/cmd/codegen/grammar.go +++ b/cmd/codegen/grammar.go @@ -155,7 +155,7 @@ func walkTerm(term parser.Term) GoNode { case parser.ExtRef: node = stringNode("parser.ExtRef(`%s`)", safeString(string(t))) default: - panic(fmt.Errorf("unexpected term type in walk: %v %[1]T", t)) + panic(fmt.Errorf("walkTerm: unexpected term type: %v %[1]T", t)) } return node diff --git a/wbnf/cutpoints.go b/wbnf/cutpoints.go index de10c0c..8ff83b2 100644 --- a/wbnf/cutpoints.go +++ b/wbnf/cutpoints.go @@ -105,7 +105,7 @@ func findUniqueStrings(g parser.Grammar) frozen.Set { out = out.Merge(forTerm(t.Term), mergeFn) case parser.RE, parser.Rule, parser.ExtRef: // do nothing default: - panic(fmt.Errorf("unexpected term type for unique string: %v %[1]T", t)) + panic(fmt.Errorf("findUniqueStrings: unexpected term type: %v %[1]T", t)) } return out } @@ -166,6 +166,6 @@ func fixTerm(term parser.Term, callback func(t parser.Term) parser.Term) parser. case parser.S, parser.REF, parser.RE, parser.Rule, parser.ExtRef: return callback(term) default: - panic(fmt.Errorf("unexpected term type for fix: %v %[1]T", t)) + panic(fmt.Errorf("fixTerm: unexpected term type: %v %[1]T", t)) } }