Permalink
Browse files

fixing up the tests

  • Loading branch information...
1 parent 67b803b commit abf63fca122feed262e925b262cea27d31c50018 Paul Tagliamonte committed Mar 8, 2013
Showing with 32 additions and 10 deletions.
  1. +1 −1 hy/importer.py
  2. +21 −2 hy/macros.py
  3. +0 −1 hy/models/expression.py
  4. +6 −1 hy/models/list.py
  5. +4 −5 tests/macros/test_macro_processor.py
View
@@ -4,7 +4,7 @@
from hy.macros import process
from hy.compiler import hy_compile
-import hy.core.bootstrap # language bits.
+import hy.core.bootstrap # NOQA
import imp
View
@@ -20,7 +20,6 @@
from hy.models.expression import HyExpression
from hy.models.list import HyList
-from hy.models import HyObject
_hy_macros = {}
@@ -32,6 +31,26 @@ def _(fn):
return _
-
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
@@ -25,4 +25,3 @@ class HyExpression(HyList):
"""
Hy S-Expression. Basically just a list.
"""
- pass
View
@@ -25,4 +25,9 @@ class HyList(HyObject, 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.lex import tokenize
from hy.models.expression import HyExpression
from hy.models.string import HyString
@@ -15,22 +16,20 @@ def tmac(tree):
def test_preprocessor_simple():
""" Test basic macro expantion """
- obj = process(HyExpression(["test", "one", "two"]))
+ obj = process(tokenize('(test "one" "two")')[0])
assert obj == HyList(["one", "two"])
assert type(obj) == HyList
def test_preprocessor_expression():
""" Test inner macro expantion """
- obj = process(HyExpression([HySymbol("test"),
- HyExpression([HySymbol("test"),
- HyString("one"),
- HyString("two")])]))
+ obj = process(tokenize('(test (test "one" "two"))')[0])
assert type(obj) == HyList
assert type(obj[0]) == HyList
assert obj[0] == HyList([HyString("one"), HyString("two")])
obj = HyList([HyString("one"), HyString("two")])
+ obj = tokenize('(shill ["one" "two"])')[0][1]
assert obj == process(obj)

0 comments on commit abf63fc

Please sign in to comment.