#NEWLINE# def main( argv = None ) : #NEWLINE# #INDENT# import doctest #NEWLINE# doctest . testmod ( sys . modules [ '__main__' ] ) #NEWLINE# doctest . testmod ( parsetree ) #NEWLINE# import argparse #NEWLINE# parser = argparse . ArgumentParser ( description = 'Generate python parser code from grammar description file.' ) #NEWLINE# parser . add_argument ( 'grammar_path' , help = 'Path to grammar description file (input).' ) #NEWLINE# parser . add_argument ( 'parser_path' , nargs = '?' , help = 'Path to output file to be generated. Input path, but with .py will be used, if omitted. "-" or "/dev/stdout" (on some systems) can be used to output generated code to stdout.' ) #NEWLINE# parser . add_argument ( '-i' , '--context-insensitive-scanner' , action = 'store_true' , help = 'Scan all tokens (see docs).' ) #NEWLINE# parser . add_argument ( '-t' , '--indent-with-tabs' , action = 'store_true' , help = 'Use tabs instead of four spaces for indentation in generated code.' ) #NEWLINE# parser . add_argument ( '--dump' , action = 'store_true' , help = 'Dump out grammar information.' ) #NEWLINE# optz = parser . parse_args ( ( argv if ( argv is not None ) else sys . argv [ 1 : ] ) ) #NEWLINE# parser_flags = dict ( ) #NEWLINE# for k in ( 'dump' , 'context_insensitive_scanner' ) : #NEWLINE# #INDENT# if getattr ( optz , k , False ) : #NEWLINE# #INDENT# parser_flags [ k ] = True #NEWLINE# #UNINDENT# #UNINDENT# if optz . indent_with_tabs : #NEWLINE# #INDENT# parsetree . INDENT = '\t' #NEWLINE# #UNINDENT# outputfile = optz . parser_path #NEWLINE# if ( outputfile == '-' ) : #NEWLINE# #INDENT# outputfile = sys . stdout #NEWLINE# #UNINDENT# sys . exit ( generate ( parser . grammar_path , outputfile , ** parser_flags ) )