Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fixing up the tests

  • Loading branch information...
commit abf63fca122feed262e925b262cea27d31c50018 1 parent 67b803b
Paul Tagliamonte authored
2  hy/importer.py
@@ -4,7 +4,7 @@
4 4 from hy.macros import process
5 5 from hy.compiler import hy_compile
6 6
7   -import hy.core.bootstrap # language bits.
  7 +import hy.core.bootstrap # NOQA
8 8
9 9
10 10 import imp
23 hy/macros.py
@@ -20,7 +20,6 @@
20 20
21 21 from hy.models.expression import HyExpression
22 22 from hy.models.list import HyList
23   -from hy.models import HyObject
24 23
25 24 _hy_macros = {}
26 25
@@ -32,6 +31,26 @@ def _(fn):
32 31 return _
33 32
34 33
35   -
36 34 def process(tree):
  35 + if isinstance(tree, HyExpression):
  36 + fn = tree[0]
  37 + ntree = HyExpression([fn] + [process(x) for x in tree[1:]])
  38 +
  39 + if fn in _hy_macros:
  40 + m = _hy_macros[fn]
  41 + obj = m(ntree)
  42 + obj.replace(tree)
  43 + return obj
  44 +
  45 + ntree.replace(tree)
  46 + return ntree
  47 +
  48 + if isinstance(tree, HyList):
  49 + obj = HyList([process(x) for x in tree])
  50 + obj.replace(tree)
  51 + return obj
  52 +
  53 + if isinstance(tree, list):
  54 + return [process(x) for x in tree]
  55 +
37 56 return tree
1  hy/models/expression.py
@@ -25,4 +25,3 @@ class HyExpression(HyList):
25 25 """
26 26 Hy S-Expression. Basically just a list.
27 27 """
28   - pass
7 hy/models/list.py
@@ -25,4 +25,9 @@ class HyList(HyObject, list):
25 25 """
26 26 Hy List. Basically just a list.
27 27 """
28   - pass
  28 +
  29 + def replace(self, other):
  30 + for x in self:
  31 + x.replace(other)
  32 +
  33 + HyObject.replace(self, other)
9 tests/macros/test_macro_processor.py
... ... @@ -1,5 +1,6 @@
1 1
2 2 from hy.macros import macro, process
  3 +from hy.lex import tokenize
3 4
4 5 from hy.models.expression import HyExpression
5 6 from hy.models.string import HyString
@@ -15,17 +16,14 @@ def tmac(tree):
15 16
16 17 def test_preprocessor_simple():
17 18 """ Test basic macro expantion """
18   - obj = process(HyExpression(["test", "one", "two"]))
  19 + obj = process(tokenize('(test "one" "two")')[0])
19 20 assert obj == HyList(["one", "two"])
20 21 assert type(obj) == HyList
21 22
22 23
23 24 def test_preprocessor_expression():
24 25 """ Test inner macro expantion """
25   - obj = process(HyExpression([HySymbol("test"),
26   - HyExpression([HySymbol("test"),
27   - HyString("one"),
28   - HyString("two")])]))
  26 + obj = process(tokenize('(test (test "one" "two"))')[0])
29 27
30 28 assert type(obj) == HyList
31 29 assert type(obj[0]) == HyList
@@ -33,4 +31,5 @@ def test_preprocessor_expression():
33 31 assert obj[0] == HyList([HyString("one"), HyString("two")])
34 32
35 33 obj = HyList([HyString("one"), HyString("two")])
  34 + obj = tokenize('(shill ["one" "two"])')[0][1]
36 35 assert obj == process(obj)

0 comments on commit abf63fc

Please sign in to comment.
Something went wrong with that request. Please try again.