def main(): #Generate test code os.chdir("test") jsstr = "var testArray = [" filelist = os.listdir('.') for file in filelist: if file.endswith(".py"): compiler.main(file) jsstr = jsstr +"\""+ file[:len(file) - 3]+"\"," jsstr = jsstr[:len(jsstr)-1] + "];" jsfile = open("test.js", "w") jsfile.write(jsstr) jsfile.close() #Generate library code os.chdir("../src/lib") jsstr = "var libArray = [" filelist = os.listdir('.') for file in filelist: if file.endswith(".py"): compiler.main(file) jsstr = jsstr +"\""+ file[:len(file) - 3]+"\"," jsstr = jsstr[:len(jsstr)-1] + "];" jsfile = open("lib.js", "w") jsfile.write(jsstr) jsfile.close()
def main(): """Build the package.""" if os.path.isdir('build'): shutil.rmtree('build') check_platform() compiler.main() copy_files() clean() create_dirsconf() create_control() build_deb()
def mine(resetpdb, importpdb, paperfile): # === IMPORT === if resetpdb: import importer_pubmed as pm pm.resetPDB() return if importpdb: import importer_pubmed as pm pm.importing(pubmed_papers=paperfile) # === COMPILE === compiler.main() # === INFER === inf.main()
def parser_helper(name): """ helper to test parser on files. takes test name (i.e. test1 ect) opens expected output fiel (i.e. testcases/test1.parse.out) calls compiler parser on test file. returns output and expected values (i.e. Accepted, Not Accepted). """ with open(TESTCASE_PATH + name + OUTPUT_SUFFIX, "r") as target: with mock.patch('sys.argv', ['self', TESTCASE_PATH + name + INPUT_SUFFIX]): stdout = sys.stdout = sys.stdout output = "" try: out = StringIO() sys.stdout = out main() output = out.getvalue() finally: sys.stdout = stdout return output, target.read()
sys.path.insert(0, _mimes_path1) _mimes_path2 = os.path.abspath( os.path.join( config.static_root, os.path.pardir, 'objects') ) sys.path.insert(0, _mimes_path2) try: mimesjs = os.path.join( config.static_root, 'mimetypes.js') if not os.path.exists(mimesjs): # mime icons from clean_dups import expand cwd = os.getcwd() os.chdir( _mimes_path1 ) expand() os.chdir(cwd) # mime data (.js + css) import compiler os.chdir( _mimes_path2 ) compiler.main() os.chdir(cwd) open(mimesjs, 'w').write( open( os.path.join(config.static_root, os.path.pardir, 'mimes', 'mimes.js') ).read() ) # cleanup del(sys.path[0], sys.path[1], expand, _mimes_path1, _mimes_path2) del(mimesjs) VIEW_CODE = ''.join( open( os.path.join( 'views', p) ).read() for p in os.listdir('views') if p.endswith('.html') ) INDEX_TEMPLATE = bottle.template( open( os.path.join(config.static_root, 'weye.html') ).read(), VIEWS=VIEW_CODE ) del VIEW_CODE except Exception as e: print("*ERROR* Failed to generate mimes: %r"%e)
from compiler import main if __name__ == "__main__": main()
def main(name): compiler.main(name)
sxml = str(path.parents[0].joinpath( '{}.sxml'.format(stem) )) with open(sxml, 'w') as f: f.write(out) if __name__ == "__main__": filename, srcfile = sys.argv[1], sys.argv[1] path = Path(srcfile) if path.is_dir(): for filename in path.iterdir(): if filename.suffix == '.jack': tokenize_file(str(filename)) for filename in path.iterdir(): if (filename.suffix == '.xml' and filename.stem[-1] == 'T'): parse_file(str(filename)) for filename in path.iterdir(): if (filename.suffix == '.xml' and filename.stem[-1] != 'T'): symbolize_file(str(filename)) else: tokenize_file(str(filename)) txml = path.stem + 'T.xml' parse_file(txml) xml = path.stem + '.xml' symbolize_file(xml) with open(path.stem + '.sxml') as f: txt = f.read() result = compiler.main(txt) print(result)
import compiler if __name__ == "__main__": test_dir = "./tests/" tests = [f for f in listdir(test_dir) if isfile(join(test_dir, f)) and f[-2:] == '.c' and f[:2] != '.#' ] tests_passed = 0 tests_attempted = 0 failed_tests = [] for t in tests: tests_attempted += 1 try: compiler.main(['compiler.py', '-i', 'tests/' + t]) tests_passed += 1 except Exception as e: failed_tests.append(t) # Report results print("=== TEST RESULTS ===") print("Passed " + str(tests_passed) + "/" + str(tests_attempted) + " tests") if (len(failed_tests) > 0): print("Failed tests:") for t in failed_tests: print(" ", t)