from iast.python.python34 import (parse as _parse, extract_tree, make_pattern,
                                  Templater, pyToStruct, structToPy,
                                  MacroProcessor, ContextSetter, literal_eval,
                                  py_nodes as python_nodes)

from incoq.util.misc import flood_namespace, new_namespace

from . import iast_common
from .iast_common import ExtractMixin
from .unparse import Unparser

P = new_namespace(python_nodes)

# Flood the module namespace with Python nodes and iAST exports.
flood_namespace(globals(), python_nodes)
flood_namespace(globals(), iast_common)


class CommentUnparser(Unparser):
    """Unparser that turns a special COMMENT construct into
    an actual lexical comment in the emitted source code.
    
    The recognized pattern has the form:
    
        Expr(Call(Name('COMMENT', Load()),
                  [Str(<TEXT>)],
                  [], None, None))
    """

    # Dependency injection: Make the unparser use our Struct AST nodes.
                                  pyToStruct, structToPy,
                                  MacroProcessor, ContextSetter,
                                  literal_eval,
                                  py_nodes as python_nodes)

from incoq.util.misc import flood_namespace, new_namespace

from . import iast_common
from .iast_common import ExtractMixin
from .unparse import Unparser

P = new_namespace(python_nodes)


# Flood the module namespace with Python nodes and iAST exports.
flood_namespace(globals(), python_nodes)
flood_namespace(globals(), iast_common)


class CommentUnparser(Unparser):
    
    """Unparser that turns a special COMMENT construct into
    an actual lexical comment in the emitted source code.
    
    The recognized pattern has the form:
    
        Expr(Call(Name('COMMENT', Load()),
                  [Str(<TEXT>)],
                  [], None, None))
    """
    
Exemple #3
0
# filtering by context.
asdl_info = ASDLImporter().run(incast_asdl)
ident_fields = {}
for node, (fields, _base) in asdl_info.items():
    for fn, ft, _fq in fields:
        if ft == 'identifier':
            ident_fields.setdefault(node, []).append(fn)


# Patch the auto-generated node classes.
def mask_init(self, m):
    if not all(c == 'b' or c == 'u' for c in m):
        raise ValueError('Bad mask string: ' + repr(m))
    self.m = m
incast_nodes['mask'].__init__ = mask_init


# As it happens, the implementation of iAST's literal_eval() can be
# reused for IncAST.
literal_eval = _literal_eval

def frozen_literal_eval(tree):
    value = literal_eval(tree)
    value = freeze(value)
    return value


# Flood the module namespace with node definitions and iAST exports.
flood_namespace(globals(), incast_nodes)
flood_namespace(globals(), iast_common)