2013-03-03 22:26:17 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2013-03-15 02:03:33 +01:00
|
|
|
import hy
|
2013-03-07 04:09:13 +01:00
|
|
|
import sys
|
2013-03-15 02:03:33 +01:00
|
|
|
|
2013-03-15 17:38:44 +01:00
|
|
|
|
2013-03-15 02:03:33 +01:00
|
|
|
if len(sys.argv) > 1:
|
|
|
|
from hy.importer import import_file_to_module
|
2013-03-15 18:00:28 +01:00
|
|
|
sys.argv.pop(0)
|
|
|
|
import_file_to_module("__main__", sys.argv[0])
|
2013-03-15 02:03:33 +01:00
|
|
|
sys.exit(0) # right?
|
|
|
|
|
|
|
|
|
2013-03-14 22:36:38 +01:00
|
|
|
import ast
|
|
|
|
import code
|
|
|
|
import readline
|
2013-03-15 00:44:33 +01:00
|
|
|
|
2013-03-14 22:36:38 +01:00
|
|
|
from hy.lex.states import Idle, LexException
|
|
|
|
from hy.lex.machine import Machine
|
|
|
|
from hy.compiler import hy_compile
|
|
|
|
from hy.core import process
|
2013-03-07 04:09:13 +01:00
|
|
|
|
2013-03-15 17:38:44 +01:00
|
|
|
|
2013-03-14 22:36:38 +01:00
|
|
|
_machine = Machine(Idle, 1, 0)
|
|
|
|
|
|
|
|
|
|
|
|
class HyREPL(code.InteractiveConsole):
|
|
|
|
def runsource(self, source, filename='<input>', symbol='single'):
|
|
|
|
global _machine
|
|
|
|
|
|
|
|
try:
|
|
|
|
_machine.process(source + "\n")
|
|
|
|
except LexException as e:
|
|
|
|
_machine = Machine(Idle, 1, 0)
|
|
|
|
self.showsyntaxerror(filename)
|
|
|
|
return False
|
|
|
|
|
|
|
|
if type(_machine.state) != Idle:
|
|
|
|
_machine = Machine(Idle, 1, 0)
|
|
|
|
return True
|
|
|
|
|
|
|
|
tokens = process(_machine.nodes)
|
|
|
|
|
|
|
|
_machine = Machine(Idle, 1, 0)
|
|
|
|
_ast = hy_compile(tokens, root=ast.Interactive)
|
|
|
|
code = compile(_ast, filename, symbol)
|
|
|
|
|
|
|
|
self.runcode(code)
|
|
|
|
return False
|
|
|
|
|
2013-03-15 17:38:44 +01:00
|
|
|
|
2013-03-14 22:36:38 +01:00
|
|
|
sys.ps1 = "=> "
|
|
|
|
sys.ps2 = "... "
|
|
|
|
|
2013-03-15 17:38:44 +01:00
|
|
|
|
2013-03-14 22:36:38 +01:00
|
|
|
hr = HyREPL()
|
2013-03-15 00:44:33 +01:00
|
|
|
hr.interact("{appname} {version}".format(
|
|
|
|
appname=hy.__appname__,
|
|
|
|
version=hy.__version__
|
|
|
|
))
|