def _import(self, receiver, context, m, name): name = name.name if name.value is None else unicode(name.eval(context)) # In case we're importing from inside a module. if context.type == "Module" and receiver is context: m = parse(tokenize("""Importer import("{0:s}")""".format(name))) return m.eval(receiver, context, m) if name == "*": context.attrs.update(receiver.attrs) else: context[name] = receiver[name] return runtime.find("None")
def test_parse_expressions(): source = "foo = method(a, b, return a + b); print(foo(1, 2))" m = Message("foo") m.setnext(Message("=")) args = [Message("a"), Message("b")] args.append(Message("return")) args[-1].setnext(Message("a")) args[-1].setnext(Message("+")) args[-1].setnext(Message("B")) m.setnext(Message("method", args)) m.setnext(Message(";")) m.setnext(Message("print")) args = [Message("1", value="1"), Message("2", value="2")] m.setnext(Message("foo", args)) expected = m actual = parse(lex(source)) assert actual == expected
def parse(s): return parser.parse(lexer.tokenize(s))
def parse(self, receiver, context, m, code): code = str(code.eval(context)) return parse(tokenize(code))
def test_error(): with pytest.raises(MioSyntaxError) as error: parse(lex("f("))
def test_parse_message_with_arguments(source, expected): actual = parse(lex(source)) assert actual == expected
def test_parse_message(source, expected): actual = parse(lex(source)) assert actual == expected