# -*- coding: utf-8 -*- from macropy.core.macros import Macros from macropy.core.hquotes import macros, hq, u, unhygienic, ast_literal macros = Macros() # noqa: F811 @macros.expr def log(tree, exact_src, **kw): new_tree = hq[wrap(unhygienic[log_func], u[exact_src(tree)], ast_literal[tree])] return new_tree def wrap(printer, txt, x): printer(txt + " -> " + repr(x)) return x @macros.expose_unhygienic def log_func(txt): print(txt)
from macropy.core.macros import Macros from macropy.core.hquotes import hq, ast, name, ast_repr, ast_literal, Captured, Literal macros = Macros() @macros.expr def q(tree, **kw): return hq(tree, **kw) @macros.block def q(tree, target, **kw): tree = hq(tree, **kw) return [ast.Assign([target], tree)] macros.expose_unhygienic(ast) macros.expose_unhygienic(ast_repr) macros.expose_unhygienic(Captured) macros.expose_unhygienic(Literal)
# -*- coding: utf-8 -*- from macropy.core.macros import Macros macros = Macros() @macros.expr def expand(tree, **kw): return tree
# -*- coding: utf-8 -*- import ast from io import StringIO import tokenize try: from pyxl.codec.tokenizer import pyxl_tokenize from pyxl import html except ImportError as e: raise RuntimeError("External library missing, please install the 'pyxl3'" " package.") from e from macropy.core.macros import Macros macros = Macros() @macros.expr def p(tree, **kw): new_string = tokenize.untokenize(pyxl_tokenize(StringIO('(' + tree.s + ')') .readline)).rstrip().rstrip("\\") new_tree = ast.parse(new_string) return new_tree.body[0].value # expose to the calling module some symbols macros.expose_unhygienic(html, 'html') # these are needed due to bugs in the port to py3, I suppose rawhtml = html.rawhtml macros.expose_unhygienic(rawhtml) unicode = str