def test_print_escape_newlines(): assert parse([ tokens.ID('print'), tokens.WS(' '), tokens.ID('butt\\n'), tokens.WS('\n'), ]) == ast.Module(ast.Print(), ast.String(' butt\n'))
def test_print(): assert parse([ tokens.ID('print'), tokens.WS(' '), tokens.ID('butt'), tokens.WS('\n'), ]) == ast.Module(ast.Print(), ast.String(' butt'))
def my_compile(source, filename='<unknown>', mode='exec'): try: from mylang.parse import parse except ImportError: raise ImportError('PLY is not installed') ast_root = parse(source, filename, mode) return compile(ast_root, filename, mode)
def hic(source): llsource = str(compiler(parse(lex(source)))) _, s = mkstemp('.s') interpreter = Popen(('llc', '-o', s), stdin=PIPE) interpreter.communicate(llsource) assert interpreter.returncode == 0, interpreter.returncode clang = Popen(('clang', s)) clang.wait() assert clang.returncode == 0, clang.returncode os.unlink(s)
def test_parse_hello(): assert parse([tokens.ID('hello')]) == ast.Module(ast.Hello())
def test_parse_null(): assert parse([]) == ast.Module()
def test_parse_hello_with_whitespace(): assert parse([tokens.WS('\n\n '), tokens.ID('hello'), tokens.WS('\n\t')]) == ast.Module(ast.Hello())
def hello(source): return interpret(str(compiler(parse(lex(source)))))