示例#1
0
文件: module.py 项目: prologic/mio
    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")
示例#2
0
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
示例#3
0
def parse(s):
    return parser.parse(lexer.tokenize(s))
示例#4
0
文件: parser.py 项目: prologic/mio
 def parse(self, receiver, context, m, code):
     code = str(code.eval(context))
     return parse(tokenize(code))
示例#5
0
def test_error():
    with pytest.raises(MioSyntaxError) as error:
        parse(lex("f("))
示例#6
0
def test_parse_message_with_arguments(source, expected):
    actual = parse(lex(source))
    assert actual == expected
示例#7
0
def test_parse_message(source, expected):
    actual = parse(lex(source))
    assert actual == expected