def load_class(ww): r'''Imports and initializes the Python class for a defining word. ''' mod = helpers.import_module("%s.%s" % (ww.package_name, ww.name)) new_subclass = getattr(mod, ww.name) new_subclass.init_class(ww) return new_subclass
def create_parsers(top): r'''Creates a parser in each package. Returns {package_name: parser module} Also does load_word on all of the defining words. ''' global Rules, Token_dict Rules = [] Token_dict = {} package_parsers = {} syntax_file = os.path.join(os.path.dirname(__file__), 'SYNTAX') with crud.db_transaction(): for p in top.packages: for ww in p.get_words(): load_word(ww) #print "Rules", Rules #print "Token_dict", Token_dict # compile new parser for this package: with open(os.path.join(p.package_dir, 'parser.py'), 'w') \ as output_file: genparser.genparser(syntax_file, '\n'.join(Rules), Token_dict, output_file) # import needed modules from the package: package_parsers[p.package_name] = \ helpers.import_module(p.package_name + '.parser') return package_parsers
def __init__(self): self.package_name = BUILT_IN self.package_dir = \ os.path.split(helpers.import_module(self.package_name).__file__)[0] self.load_words()