From a80538426fc6df3385e9567064d32b4b45a81669 Mon Sep 17 00:00:00 2001 From: Ryo Nihei Date: Fri, 30 Jul 2021 23:41:24 +0900 Subject: Detect unused-symbol error When there are productions and terminals that are cannot be reached from the start symbol, the compiler reports an error. --- driver/parser_test.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'driver/parser_test.go') diff --git a/driver/parser_test.go b/driver/parser_test.go index 73d8fac..e32e34c 100644 --- a/driver/parser_test.go +++ b/driver/parser_test.go @@ -148,6 +148,46 @@ bar_text: "bar"; ), ), }, + // Production `b` is unused. + { + specSrc: ` +a + : foo + ; +b + : foo; +foo: "foo"; +`, + src: `foo`, + specErr: true, + }, + // Terminal `bar` is unused. + { + specSrc: ` +s + : foo + ; +foo: "foo"; +bar: "bar"; +`, + src: `foo`, + specErr: true, + }, + // Production `b` and terminal `bar` is unused. + { + specSrc: ` +a + : foo + ; +b + : bar + ; +foo: "foo"; +bar: "bar"; +`, + src: `foo`, + specErr: true, + }, { specSrc: ` mode_tran_seq @@ -258,6 +298,9 @@ bar: "bar"; { specSrc: ` s + : foo + ; +foo : "foo" #ast #(s $1...) ; `, -- cgit v1.2.3