How to use the hy.models.expression.HyExpression function in hy

To help you get started, we’ve selected a few hy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hylang / hy / tests / lex / test_lex.py View on Github external
def test_lex_expression_integer():
    """ Make sure expressions can produce integers """
    objs = tokenize("(foo 2)")
    assert objs == [HyExpression([HySymbol("foo"), HyInteger(2)])]
github hylang / hy / tests / lex / test_lex.py View on Github external
def test_lex_expression_symbols():
    """ Make sure that expressions produce symbols """
    objs = tokenize("(foo bar)")
    assert objs == [HyExpression([HySymbol("foo"), HySymbol("bar")])]
github hylang / hy / hy / mangle.py View on Github external
def _mangle(self, tree):
        # Things that force a scope push to go into:
        #
        #  - Functions
        #  - If
        scopable = ["fn", "if"]
        scoped = False

        self.push_stack(tree)

        if isinstance(tree, HyExpression):
            what = tree[0]
            if what in scopable:
                self.push_scope(tree)
                scoped = True

        if isinstance(tree, list):
            for i, element in enumerate(tree):
                nel = self.visit(element)
                if nel:
                    tree[i] = nel
                    self.tree_changed()

                self._mangle(element)

        if scoped:
            self.pop_scope()
github hylang / hy / hy / core / bootstrap.py View on Github external
def cond_macro(*tree):
    it = iter(tree)
    test, branch = next(it)

    root = HyExpression([HySymbol("if"), test, branch])
    ret = root
    for (test, branch) in it:
        n = HyExpression([HySymbol("if"), test, branch])
        ret.append(n)
        ret = n

    return root
github hylang / hy / hy / contrib / meth.py View on Github external
def router(tree, rkwargs=None):
    tree = HyExpression(tree)
    name = tree.pop(0)
    path = tree.pop(0)
    tree.insert(0, HySymbol("fn"))
    tree = HyExpression([HySymbol("def"), name, tree])

    route = HyExpression([HySymbol(".route"), HySymbol("app"), path])

    if rkwargs:
        route = HyExpression([HySymbol("kwapply"), route,
                              HyDict({HyString("methods"): rkwargs})])

    return HyExpression([HySymbol("with_decorator"), route, tree])
github hylang / hy / hy / contrib / meth.py View on Github external
def router(tree, rkwargs=None):
    tree = HyExpression(tree)
    name = tree.pop(0)
    path = tree.pop(0)
    tree.insert(0, HySymbol("fn"))
    tree = HyExpression([HySymbol("def"), name, tree])

    route = HyExpression([HySymbol(".route"), HySymbol("app"), path])

    if rkwargs:
        route = HyExpression([HySymbol("kwapply"), route,
                              HyDict({HyString("methods"): rkwargs})])

    return HyExpression([HySymbol("with_decorator"), route, tree])
github hylang / hy / hy / core / bootstrap.py View on Github external
def when_macro(test, *body):
    return HyExpression([
        HySymbol('if'),
        test,
        HyExpression([HySymbol("do")] + list(body)),
    ])
github hylang / hy / hy / core / bootstrap.py View on Github external
def first_macro(lst):
    return HyExpression([HySymbol('get'),
                         lst,
                         HyInteger(0)])
github hylang / hy / hy / core / bootstrap.py View on Github external
def cond_macro(*tree):
    it = iter(tree)
    test, branch = next(it)

    root = HyExpression([HySymbol("if"), test, branch])
    ret = root
    for (test, branch) in it:
        n = HyExpression([HySymbol("if"), test, branch])
        ret.append(n)
        ret = n

    return root
github hylang / hy / hy / core / bootstrap.py View on Github external
#     ...

    tree = HyExpression(tree).replace(tree[0])

    it = iter(tree.pop(0))
    blocks = list(zip(it, it))  # List for Python 3.x degenerating.

    key, val = blocks.pop(0)
    ret = HyExpression([HySymbol("foreach"),
                        HyList([key, val])])
    root = ret
    ret.replace(tree)

    for key, val in blocks:
        # x, [1, 2, 3,  4]
        nret = HyExpression([HySymbol("foreach"),
                             HyList([key, val])])
        nret.replace(key)
        ret.append(nret)
        ret = nret

    [ret.append(x) for x in tree]  # we really need ~@
    return root