summary refs log tree commit diff stats
path: root/tools/grammar_nanny.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tools/grammar_nanny.nim')
-rw-r--r--tools/grammar_nanny.nim15
1 files changed, 11 insertions, 4 deletions
diff --git a/tools/grammar_nanny.nim b/tools/grammar_nanny.nim
index d07c2bf8c..cbdc51efc 100644
--- a/tools/grammar_nanny.nim
+++ b/tools/grammar_nanny.nim
@@ -3,8 +3,11 @@
 
 import std / [strutils, sets]
 
+when defined(nimPreviewSlimSystem):
+  import std/syncio
+
 import ".." / compiler / [
-  llstream, ast, lexer, options, msgs, idents,
+  llstream, lexer, options, msgs, idents,
   lineinfos, pathutils]
 
 proc checkGrammarFileImpl(cache: IdentCache, config: ConfigRef) =
@@ -13,12 +16,12 @@ proc checkGrammarFileImpl(cache: IdentCache, config: ConfigRef) =
   var stream = llStreamOpen(data)
   var declaredSyms = initHashSet[string]()
   var usedSyms = initHashSet[string]()
+  usedSyms.incl "module" # 'module' is the start rule.
   if stream != nil:
     declaredSyms.incl "section" # special case for 'section(RULE)' in the grammar
     var
-      L: TLexer
-      tok: TToken
-    initToken(tok)
+      L: Lexer
+      tok: Token
     openLexer(L, f, stream, cache, config)
     # load the first token:
     rawGetTok(L, tok)
@@ -35,6 +38,10 @@ proc checkGrammarFileImpl(cache: IdentCache, config: ConfigRef) =
           usedSyms.incl word
       else:
         rawGetTok(L, tok)
+    for u in declaredSyms:
+      if u notin usedSyms:
+        echo "Unused non-terminal: ", u
+
     for u in usedSyms:
       if u notin declaredSyms:
         echo "Undeclared non-terminal: ", u