예제 #1
0
def evalparser():
    parse = PyClojureParse().build().parse
    scopechain = [GlobalScope()]

    def evalparse(x):
        return evaluate(parse(x), scopechain)

    return evalparse
예제 #2
0
def test_parser():
    parse = PyClojureParse().build().parse
    assert parse("an_atom") == Atom('an_atom')
    assert parse("(simple_list)") == List(Atom('simple_list'))
    assert parse('(two elements)') == List(Atom('two'), Atom('elements'))
    assert (parse("(three element list)") == List(Atom('three'),
                                                  Atom('element'),
                                                  Atom('list')))
    assert parse('666') == 666
    assert (parse('(a (nested (list)))') == List(
        Atom('a'), List(Atom('nested'), List(Atom('list')))))
    assert parse('()') == List()
예제 #3
0
def test_to_string():
    parse = PyClojureParse().build().parse
    assert tostring(parse("nil")) == "nil"
    assert tostring(parse("666")) == "666"
    assert tostring(parse("6.66")) == "6.66"
    assert tostring(parse("666e-2")) == "6.66"
    assert tostring(parse("-666")) == "-666"
    assert tostring(parse("-6.66")) == "-6.66"
    assert tostring(parse("-666e-2")) == "-6.66"
    assert tostring(parse("()")) == "()"
    assert tostring(parse("(a)")) == "(a)"
    assert tostring(parse("(a b)")) == "(a b)"
    assert tostring(parse("(a (b c))")) == "(a (b c))"
    assert tostring(parse("[]")) == "[]"
    assert tostring(parse(":a")) == ":a"
    assert tostring(parse("{}")) == "{}"
    assert tostring(parse("{1 2}")) == "{1 2}"
    assert tostring(parse("{1 2 3 4}")) == "{1 2, 3 4}"
예제 #4
0
except ImportError:
    pass
else:
    import os
    histfile = os.path.join(os.path.expanduser("~"), ".pyclojurehist")
    try:
        readline.read_history_file(histfile)
    except IOError:
        # Pass here as there isn't any history file, so one will be
        # written by atexit
        pass
    import atexit
    atexit.register(readline.write_history_file, histfile)

lexer = PyClojureLex().build()
parser = PyClojureParse().build()

def main():
    global_scope = GlobalScope()
    scopechain = [global_scope]
    while True:
        try:
            txt = raw_input("pyclojure> ")
            if re.search('^\s*$', txt):
                continue
            else:
                print(tostring(evaluate(
                            parser.parse(txt, lexer=lexer), scopechain)))
        except EOFError:
            break
        except KeyboardInterrupt:
예제 #5
0
def test_reader_macros():
    parse = PyClojureParse().build().parse
    assert parse("@a") == parse("(deref a)")
    assert parse("'a") == parse("(quote a)")
    assert parse("(.float 3)") == parse("(float 3)")
    assert parse("'(1 2 3)") == parse("(quote (1 2 3))")