From 00f8b091a9f1eb3ed0348900784be07c326c0dc1 Mon Sep 17 00:00:00 2001 From: Ryo Nihei Date: Mon, 9 Aug 2021 01:51:41 +0900 Subject: Support LALR(1) class --- grammar/test_helper_test.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'grammar/test_helper_test.go') diff --git a/grammar/test_helper_test.go b/grammar/test_helper_test.go index 8f5c372..cf9da2b 100644 --- a/grammar/test_helper_test.go +++ b/grammar/test_helper_test.go @@ -35,10 +35,10 @@ func newTestProductionGenerator(t *testing.T, genSym testSymbolGenerator) testPr } } -type testLR0ItemGenerator func(lhs string, dot int, rhs ...string) *lr0Item +type testLR0ItemGenerator func(lhs string, dot int, rhs ...string) *lrItem func newTestLR0ItemGenerator(t *testing.T, genProd testProductionGenerator) testLR0ItemGenerator { - return func(lhs string, dot int, rhs ...string) *lr0Item { + return func(lhs string, dot int, rhs ...string) *lrItem { t.Helper() prod := genProd(lhs, rhs...) @@ -50,3 +50,15 @@ func newTestLR0ItemGenerator(t *testing.T, genProd testProductionGenerator) test return item } } + +func withLookAhead(item *lrItem, lookAhead ...symbol) *lrItem { + if item.lookAhead.symbols == nil { + item.lookAhead.symbols = map[symbol]struct{}{} + } + + for _, a := range lookAhead { + item.lookAhead.symbols[a] = struct{}{} + } + + return item +} -- cgit v1.2.3