Beispiel #1
0
def parse(input, interpreter=None, ctx=None, out=None, words=None):
	"""\
		Read non-blocking input, run through the tokenizer, pass to the
		parser.
		"""
	if ctx is None: ctx=Context
	if ctx is Context or "filename" not in ctx:
		ctx = ctx(filename=(input if isinstance(input,six.string_types) else u"‹stdin›"))
	if out is not None:
		ctx.out = out
	else:
		ctx.out = sys.stdout
		if "words" not in ctx:
			if words is None: words = global_words(ctx)
			ctx.words = words

	if interpreter is None:
		from moat.interpreter import Interpreter
		interpreter = Interpreter
	if isinstance(interpreter,type):
		interpreter = interpreter(ctx)

	if isinstance(input,six.string_types):
		input = open(input,"rU",encoding='utf-8')

	parser = Parser(interpreter=interpreter, input=input, ctx=ctx)
	parser.run()
Beispiel #2
0
def parse(input, interpreter=None, ctx=None, out=None, words=None):
    """\
		Read non-blocking input, run through the tokenizer, pass to the
		parser.
		"""
    if ctx is None: ctx = Context
    if ctx is Context or "filename" not in ctx:
        ctx = ctx(filename=(
            input if isinstance(input, six.string_types) else u"‹stdin›"))
    if out is not None:
        ctx.out = out
    else:
        ctx.out = sys.stdout
        if "words" not in ctx:
            if words is None: words = global_words(ctx)
            ctx.words = words

    if interpreter is None:
        from moat.interpreter import Interpreter
        interpreter = Interpreter
    if isinstance(interpreter, type):
        interpreter = interpreter(ctx)

    if isinstance(input, six.string_types):
        input = open(input, "rU", encoding='utf-8')

    parser = Parser(interpreter=interpreter, input=input, ctx=ctx)
    parser.run()
Beispiel #3
0
	def __init__(self, ctx=None):
		super(Interpreter,self).__init__(ctx)
		if "words" not in ctx:
			from moat.statement import global_words
			self.ctx = ctx(words=global_words(ctx=ctx))
		else:
			self.ctx = ctx
Beispiel #4
0
 def on_connect(self):
     global conn_seq
     conn_seq += 1
     self.name = self.dest + ("n" + str(conn_seq), )
     self.ctx = Context()
     self.ctx.out = Reporter(self)
     self.ctx.words = global_words(self.ctx)
     self.workers = set()
     simple_event("rpc", "connect", *self.name)
     Collected.__init__(self)
Beispiel #5
0
	def on_connect(self):
		global conn_seq
		conn_seq += 1
		self.name = self.dest + ("n"+str(conn_seq),)
		self.ctx = Context()
		self.ctx.out = Reporter(self)
		self.ctx.words = global_words(self.ctx)
		self.workers = set()
		simple_event("rpc","connect",*self.name)
		Collected.__init__(self)
Beispiel #6
0
    def _command(self, args=(), sub=(), **kwargs):
        ctx = Context(**kwargs)
        ctx.out = Reporter()
        ctx.words = global_words()  # self.ctx)

        try:
            if sub:
                cmd = CommandProcessor(parent=self, ctx=ctx)
                proc = cmd.complex_statement(args)
                for s in sub:
                    proc.simple_statement(s)
                proc.done()
                cmd.run()
            else:
                CommandProcessor(parent=self, ctx=ctx).simple_statement(args)
        except Exception as e:
            fix_exception(e)
            process_failure(e)
            reraise(e)
        return ctx.out.data
Beispiel #7
0
	def _command(self, args=(), sub=(),**kwargs):
		ctx = Context(**kwargs)
		ctx.out = Reporter()
		ctx.words = global_words() # self.ctx)

		try:
			if sub:
				cmd = CommandProcessor(parent=self,ctx=ctx)
				proc = cmd.complex_statement(args)
				for s in sub:
					proc.simple_statement(s)
				proc.done()
				cmd.run()
			else:
				CommandProcessor(parent=self,ctx=ctx).simple_statement(args)
		except Exception as e:
			fix_exception(e)
			process_failure(e)
			reraise(e)
		return ctx.out.data