hy repl things
This commit is contained in:
parent
6acde1761b
commit
0558dadf69
32
bin/hy
32
bin/hy
@ -1,8 +1,9 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import hy
|
import hy
|
||||||
import os
|
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
@ -12,15 +13,20 @@ if len(sys.argv) > 1:
|
|||||||
sys.exit(0) # right?
|
sys.exit(0) # right?
|
||||||
|
|
||||||
|
|
||||||
import ast
|
|
||||||
import code
|
|
||||||
import readline
|
import readline
|
||||||
|
import code
|
||||||
|
import ast
|
||||||
|
|
||||||
from hy.lex.states import Idle, LexException
|
from hy.lex.states import Idle, LexException
|
||||||
from hy.lex.machine import Machine
|
from hy.lex.machine import Machine
|
||||||
from hy.compiler import hy_compile
|
from hy.compiler import hy_compile
|
||||||
from hy.core import process
|
from hy.core import process
|
||||||
|
|
||||||
|
from hy.macros import macro
|
||||||
|
from hy.models.expression import HyExpression
|
||||||
|
from hy.models.string import HyString
|
||||||
|
from hy.models.symbol import HySymbol
|
||||||
|
|
||||||
|
|
||||||
_machine = Machine(Idle, 1, 0)
|
_machine = Machine(Idle, 1, 0)
|
||||||
|
|
||||||
@ -56,11 +62,31 @@ sys.ps2 = "... "
|
|||||||
history = os.path.expanduser("~/.hy-history")
|
history = os.path.expanduser("~/.hy-history")
|
||||||
readline.parse_and_bind("set blink-matching-paren on")
|
readline.parse_and_bind("set blink-matching-paren on")
|
||||||
|
|
||||||
|
|
||||||
|
@macro("koan")
|
||||||
|
def koan_macro(tree):
|
||||||
|
return HyExpression([HySymbol('print'),
|
||||||
|
HyString("""
|
||||||
|
Ummon asked the head monk, "What sutra are you lecturing on?"
|
||||||
|
"The Nirvana Sutra."
|
||||||
|
"The Nirvana Sutra has the Four Virtues, hasn't it?"
|
||||||
|
"It has."
|
||||||
|
Ummon asked, picking up a cup, "How many virtues has this?"
|
||||||
|
"None at all, " said the monk.
|
||||||
|
"But ancient people said it had, didn't they?" said Ummon.
|
||||||
|
"Whatdo you think of what they said?"
|
||||||
|
Ummon struck the cup and asked, "You understand?"
|
||||||
|
"No," said the monk.
|
||||||
|
"Then," said Ummon, "You'd better go on with your lectures on the sutra."
|
||||||
|
""")])
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
readline.read_history_file(history)
|
readline.read_history_file(history)
|
||||||
except IOError:
|
except IOError:
|
||||||
open(history, 'wa').close()
|
open(history, 'wa').close()
|
||||||
|
|
||||||
|
|
||||||
hr = HyREPL()
|
hr = HyREPL()
|
||||||
hr.interact("{appname} {version}".format(
|
hr.interact("{appname} {version}".format(
|
||||||
appname=hy.__appname__,
|
appname=hy.__appname__,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user