fixing up the tests
This commit is contained in:
parent
67b803b99a
commit
abf63fca12
@ -4,7 +4,7 @@ from hy.lex import tokenize
|
|||||||
from hy.macros import process
|
from hy.macros import process
|
||||||
from hy.compiler import hy_compile
|
from hy.compiler import hy_compile
|
||||||
|
|
||||||
import hy.core.bootstrap # language bits.
|
import hy.core.bootstrap # NOQA
|
||||||
|
|
||||||
|
|
||||||
import imp
|
import imp
|
||||||
|
23
hy/macros.py
23
hy/macros.py
@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
from hy.models.expression import HyExpression
|
from hy.models.expression import HyExpression
|
||||||
from hy.models.list import HyList
|
from hy.models.list import HyList
|
||||||
from hy.models import HyObject
|
|
||||||
|
|
||||||
_hy_macros = {}
|
_hy_macros = {}
|
||||||
|
|
||||||
@ -32,6 +31,26 @@ def macro(name):
|
|||||||
return _
|
return _
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def process(tree):
|
def process(tree):
|
||||||
|
if isinstance(tree, HyExpression):
|
||||||
|
fn = tree[0]
|
||||||
|
ntree = HyExpression([fn] + [process(x) for x in tree[1:]])
|
||||||
|
|
||||||
|
if fn in _hy_macros:
|
||||||
|
m = _hy_macros[fn]
|
||||||
|
obj = m(ntree)
|
||||||
|
obj.replace(tree)
|
||||||
|
return obj
|
||||||
|
|
||||||
|
ntree.replace(tree)
|
||||||
|
return ntree
|
||||||
|
|
||||||
|
if isinstance(tree, HyList):
|
||||||
|
obj = HyList([process(x) for x in tree])
|
||||||
|
obj.replace(tree)
|
||||||
|
return obj
|
||||||
|
|
||||||
|
if isinstance(tree, list):
|
||||||
|
return [process(x) for x in tree]
|
||||||
|
|
||||||
return tree
|
return tree
|
||||||
|
@ -25,4 +25,3 @@ class HyExpression(HyList):
|
|||||||
"""
|
"""
|
||||||
Hy S-Expression. Basically just a list.
|
Hy S-Expression. Basically just a list.
|
||||||
"""
|
"""
|
||||||
pass
|
|
||||||
|
@ -25,4 +25,9 @@ class HyList(HyObject, list):
|
|||||||
"""
|
"""
|
||||||
Hy List. Basically just a list.
|
Hy List. Basically just a list.
|
||||||
"""
|
"""
|
||||||
pass
|
|
||||||
|
def replace(self, other):
|
||||||
|
for x in self:
|
||||||
|
x.replace(other)
|
||||||
|
|
||||||
|
HyObject.replace(self, other)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
from hy.macros import macro, process
|
from hy.macros import macro, process
|
||||||
|
from hy.lex import tokenize
|
||||||
|
|
||||||
from hy.models.expression import HyExpression
|
from hy.models.expression import HyExpression
|
||||||
from hy.models.string import HyString
|
from hy.models.string import HyString
|
||||||
@ -15,17 +16,14 @@ def tmac(tree):
|
|||||||
|
|
||||||
def test_preprocessor_simple():
|
def test_preprocessor_simple():
|
||||||
""" Test basic macro expantion """
|
""" Test basic macro expantion """
|
||||||
obj = process(HyExpression(["test", "one", "two"]))
|
obj = process(tokenize('(test "one" "two")')[0])
|
||||||
assert obj == HyList(["one", "two"])
|
assert obj == HyList(["one", "two"])
|
||||||
assert type(obj) == HyList
|
assert type(obj) == HyList
|
||||||
|
|
||||||
|
|
||||||
def test_preprocessor_expression():
|
def test_preprocessor_expression():
|
||||||
""" Test inner macro expantion """
|
""" Test inner macro expantion """
|
||||||
obj = process(HyExpression([HySymbol("test"),
|
obj = process(tokenize('(test (test "one" "two"))')[0])
|
||||||
HyExpression([HySymbol("test"),
|
|
||||||
HyString("one"),
|
|
||||||
HyString("two")])]))
|
|
||||||
|
|
||||||
assert type(obj) == HyList
|
assert type(obj) == HyList
|
||||||
assert type(obj[0]) == HyList
|
assert type(obj[0]) == HyList
|
||||||
@ -33,4 +31,5 @@ def test_preprocessor_expression():
|
|||||||
assert obj[0] == HyList([HyString("one"), HyString("two")])
|
assert obj[0] == HyList([HyString("one"), HyString("two")])
|
||||||
|
|
||||||
obj = HyList([HyString("one"), HyString("two")])
|
obj = HyList([HyString("one"), HyString("two")])
|
||||||
|
obj = tokenize('(shill ["one" "two"])')[0][1]
|
||||||
assert obj == process(obj)
|
assert obj == process(obj)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user