aboutsummaryrefslogtreecommitdiff
path: root/grammar/test_helper_test.go
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2021-08-09 01:51:41 +0900
committerRyo Nihei <nihei.dev@gmail.com>2021-08-15 20:43:02 +0900
commit00f8b091a9f1eb3ed0348900784be07c326c0dc1 (patch)
tree5bec55d7fd4c49f01e06a76c50c9949f7f11ca32 /grammar/test_helper_test.go
parentUpdate CHANGELOG (diff)
downloadurubu-00f8b091a9f1eb3ed0348900784be07c326c0dc1.tar.gz
urubu-00f8b091a9f1eb3ed0348900784be07c326c0dc1.tar.xz
Support LALR(1) class
Diffstat (limited to 'grammar/test_helper_test.go')
-rw-r--r--grammar/test_helper_test.go16
1 files changed, 14 insertions, 2 deletions
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
+}