def __init__(self, filename, path, importFiles=[], root=None): Grammar.__init__(self) Declaration.__init__(self) self.importFiles = importFiles self._rootref = root self._filename = filename self._path = path if 'KOOCPATH' not in environ: self.diagnostic.notify(error.Severity.ERROR, "please do 'export KOOCPATH=/home/$USER/rendu/kooc/.conf'") raise self.diagnostic factory = Declaration() res = factory.parse_file(environ["KOOCPATH"] + '/builtins_class.kp') self._classTemplate = deepcopy(res.body) res = factory.parse_file(environ["KOOCPATH"] + '/builtins_implem.kp') self._implemTemplate = deepcopy(res.body)
#!/usr/bin/python3 # -*- coding: utf-8 -*- import mangling import sys if not (len(sys.argv) is 2): print('./test.py "filename"') exit(1) from cnorm.parsing.declaration import Declaration from cnorm.passes import to_c cparse = Declaration() ast = cparse.parse_file(sys.argv[1]) for index, decl in enumerate(ast.body): cString = decl.to_c() print(cString, end='') print(decl) mangled = "" try: mangled = mangling.mangle(decl, mangling.OriginIsModule, 'DUMMY_MODUL_NAME')._name print(mangled) unmangled = mangling.unmangle(mangled) print(unmangled) print(unmangled.decl.to_c()) except Exception as e: print(str(e)) if index < len(ast.body) - 1: print('')
parser.add_argument( "-d", "--dump", dest="dump", help="show AST nodes as vars", action='store_true' ) parser.add_argument( "-p", "--parse", dest="parse", help="only parsing", action='store_true' ) args = parser.parse_args() for f in args.filenames: if f != '-' and os.path.exists(f): cparse = Declaration() ast = cparse.parse_file(f) if args.dump: print(vars(ast)) if args.yml: print(ast.to_yml()) if ast: if not args.parse: print(ast.to_c()) else: print("something goes wrong")