Martin Vejnár committed f5a88b2

Added --print-states option to limecc.

Comments (0)

Files changed (2)

     from lrparser import extract_second
     return p.parse(lime_lexer(input), extract_value=extract_second)
-def make_lime_parser(g):
+def make_lime_parser(g, **kw):
     from lrparser import Parser
-    p = Parser(g)
+    p = Parser(g, **kw)
     from fa import make_dfa_from_literal, union_fa, minimize_enfa
     from regex_parser import (regex_parser, make_enfa_from_regex)
         g = parse_lime_grammar(input)
         from lrparser import InvalidGrammarError
-        p = make_lime_parser(g)
+        p = make_lime_parser(g, keep_states=options.print_states)
+        if options.print_states:
+            for i, state in enumerate(p.states):
+                print "0x%x(%d):" % (i, i)
+                print state
         from lime_cpp import lime_cpp
         open(options.output, 'w').write(lime_cpp(p))
     opts = OptionParser(
         usage='usage: %prog [options] filename)')
     opts.add_option('-o', '--output', help='The file to store the generated parser/lexer to')
+    opts.add_option('--print-states', action="store_true", dest="print_states", default=False, help='The file to store the generated parser/lexer to')
     (options, args) = opts.parse_args()
     if len(args) != 1: