diff --git a/hy/lang/expression.py b/hy/lang/expression.py index 88aa571..417cdef 100644 --- a/hy/lang/expression.py +++ b/hy/lang/expression.py @@ -1,3 +1,12 @@ class HYExpression(list): def __init__(self, nodes): self += nodes + + def get_invocation(self): + fn = self[0] if len(self) > 0 else "" + args = self[1:] if len(self) > 1 else [] + + return { + "function": fn, + "args": args + } diff --git a/tests/lang/__init__.py b/tests/lang/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/lang/test_expression.py b/tests/lang/test_expression.py new file mode 100644 index 0000000..ddf8341 --- /dev/null +++ b/tests/lang/test_expression.py @@ -0,0 +1,24 @@ +from hy.lex.tokenize import tokenize +from hy.lang.expression import HYExpression + +code = """ +(+ 1 1) ; this is a test. +(fn foo bar) ; this is a test. +""" + + +def test_fn_split(): + """Test if we can get a statement something right.""" + one, two = tokenize(code) + assert one.get_invocation() == { + "function": "+", + "args": [ + "1", "1" + ] + } + assert two.get_invocation() == { + "function": "fn", + "args": [ + "foo", "bar" + ] + }