Пример #1
0
def include_impl(args, executer, local_dict, require=False, once=False):
    # print "include impl : args:%r, executer:%r, local_dict:%r, require:%r, once:%r"%(args, executer, local_dict, require, once)
    lf_key = '~!loaded_files'
    path = executer.get_val(args[0])
    if lf_key not in executer.globals:
        # print " --> Creating executer.globals[%r]"%lf_key
        executer.globals[lf_key] = {}
    print "\n\n%s\n" % ("Including file %s" % path)
    if once and path in executer.globals[lf_key]:
        # print " -once-> file is already included"
        pass
    else:
        import os.path
        if os.path.exists(path):
            # print " --> including file %r"%path
            import compiler
            executer.globals[lf_key][path] = True
            executer.visit(compiler.compile_file(path), local_dict)
        elif require:
            raise errors.ExecuteError("required file %s not found!" % path)
Пример #2
0
def include_impl(args, executer, local_dict, require=False, once=False):
    # print "include impl : args:%r, executer:%r, local_dict:%r, require:%r, once:%r"%(args, executer, local_dict, require, once)
    lf_key = "~!loaded_files"
    path = executer.get_val(args[0])
    if lf_key not in executer.globals:
        # print " --> Creating executer.globals[%r]"%lf_key
        executer.globals[lf_key] = {}
    print "\n\n%s\n" % ("Including file %s" % path)
    if once and path in executer.globals[lf_key]:
        # print " -once-> file is already included"
        pass
    else:
        import os.path

        if os.path.exists(path):
            # print " --> including file %r"%path
            import compiler

            executer.globals[lf_key][path] = True
            executer.visit(compiler.compile_file(path), local_dict)
        elif require:
            raise errors.ExecuteError("required file %s not found!" % path)
Пример #3
0
			else:
				if len(phpargv) == 0:
					phpfile = arg
				phpargv.append(arg)
				
	init_scope = {
		'$argv' : phparray.PHPArray(*enumerate(phpargv)),
		'$argc' : len(phpargv)
	}
	
	if phpfile:
		if action == 'run':
			php_executer = executer.execute_file(phpfile, init_scope)
			if show_globals:
				print "[ended]\n-- globals --"
				for i in executer.globals.dict:
					print "%-14s  ->  %r"%(i, executer.globals[i])
		elif action == 'compile':
			code_tree = compiler.compile_file(phpfile)
			print "[ended compilation]\n-- code tree --"
			print code_tree.prepr()
		elif action == 'parse':
			tokens = parser.parse_file(phpfile)
			print "[ended parsing]\n-- tokens --"
			print '\n'.join([repr(x) for x in tokens])
		
	else :
		print "# No file to %s!"%action
		print USAGE
		
Пример #4
0
                    print "Unknown option %s" % arg
            else:
                if len(phpargv) == 0:
                    phpfile = arg
                phpargv.append(arg)

    init_scope = {
        '$argv': phparray.PHPArray(*enumerate(phpargv)),
        '$argc': len(phpargv)
    }

    if phpfile:
        if action == 'run':
            php_executer = executer.execute_file(phpfile, init_scope)
            if show_globals:
                print "[ended]\n-- globals --"
                for i in executer.globals.dict:
                    print "%-14s  ->  %r" % (i, executer.globals[i])
        elif action == 'compile':
            code_tree = compiler.compile_file(phpfile)
            print "[ended compilation]\n-- code tree --"
            print code_tree.prepr()
        elif action == 'parse':
            tokens = parser.parse_file(phpfile)
            print "[ended parsing]\n-- tokens --"
            print '\n'.join([repr(x) for x in tokens])

    else:
        print "# No file to %s!" % action
        print USAGE