# Path: bigrig/parser/node.py
# class Node(object):
#     """
#     Fields are nodes, lists, or simple values.
#     Attributes are for metadata such as source position.
#     Constructor takes fields as positional arguments and attributes as
#     keyword arguments.
#     """
#     __metaclass__ = NodeType
#     fields = ()
#     attributes = ('locator',)
#     abstract = True
#     
#     def __init__(self, *fields, **attributes):
#         if self.abstract:
#             raise ValueError('abstract nodes are not instantiable')
#         if fields:
#             num_fields = len(self.fields)
#             num_args = len(fields)
#             if num_args != num_fields:
#                 classname = self.__class__.__name__
#                 if not self.fields:
#                     raise TypeError('%r takes 0 arguments' %
#                                     classname)
#                 raise TypeError('%r takes 0 or %d argument%s, got %d' % (
#                         classname,
#                         num_fields, num_fields != 1 and 's' or '',
#                         num_fields
#                 ))
#             for name, arg, in izip(self.fields, fields):
#                 setattr(self, name, arg)
#         else:
#             for field in self.fields:
#                 setattr(self, field, None)
#         for attr in self.attributes:
#             setattr(self, attr, attributes.pop(attr, None))
#         if attributes:
#             raise TypeError('unknown attribute %r' % iter(attributes).next())
# 
#     def iter_fields(self):
#         """
#         Yields the name and value of each of this node's fields.
#         """
#         for name in self.fields:
#             yield name, getattr(self, name, None)
# 
#     def iter_children(self):
#         """
#         Iterate over all subtrees of this node.
#         """
#         for field, item in self.iter_fields():
#             if isinstance(item, list):
#                 for n in item:
#                     if isinstance(n, Node):
#                         yield n
#             elif isinstance(item, Node):
#                 yield item


from .node import Node
"""
This module contains classes for walking abstract syntax trees and transforming
them.
"""

class NodeVisitor(object):
    """
    Walks the abstract syntax tree, calling the visitor function for every
    subtree found.
    """
    def __init__(self):
        self._visitor_cache = {}

    def get_visitor(self, node):
        node_class = node.__class__
        visitor = self._visitor_cache.get(node_class)
        if visitor is None:
            method = 'visit_%s' % node_class.__name__
            visitor = getattr(self, method, self.generic_visit)
            self._visitor_cache[node_class] = visitor
        return visitor

    def visit(self, node):
        visitor = self.get_visitor(node)
        return visitor(node)

    def generic_visit(self, node):

# Path: bigrig/parser/node.py
# class Node(object):
#     """
#     Fields are nodes, lists, or simple values.
#     Attributes are for metadata such as source position.
#     Constructor takes fields as positional arguments and attributes as
#     keyword arguments.
#     """
#     __metaclass__ = NodeType
#     fields = ()
#     attributes = ('locator',)
#     abstract = True
#     
#     def __init__(self, *fields, **attributes):
#         if self.abstract:
#             raise ValueError('abstract nodes are not instantiable')
#         if fields:
#             num_fields = len(self.fields)
#             num_args = len(fields)
#             if num_args != num_fields:
#                 classname = self.__class__.__name__
#                 if not self.fields:
#                     raise TypeError('%r takes 0 arguments' %
#                                     classname)
#                 raise TypeError('%r takes 0 or %d argument%s, got %d' % (
#                         classname,
#                         num_fields, num_fields != 1 and 's' or '',
#                         num_fields
#                 ))
#             for name, arg, in izip(self.fields, fields):
#                 setattr(self, name, arg)
#         else:
#             for field in self.fields:
#                 setattr(self, field, None)
#         for attr in self.attributes:
#             setattr(self, attr, attributes.pop(attr, None))
#         if attributes:
#             raise TypeError('unknown attribute %r' % iter(attributes).next())
# 
#     def iter_fields(self):
#         """
#         Yields the name and value of each of this node's fields.
#         """
#         for name in self.fields:
#             yield name, getattr(self, name, None)
# 
#     def iter_children(self):
#         """
#         Iterate over all subtrees of this node.
#         """
#         for field, item in self.iter_fields():
#             if isinstance(item, list):
#                 for n in item:
#                     if isinstance(n, Node):
#                         yield n
#             elif isinstance(item, Node):
#                 yield item


# Path: bigrig/parser/visitor.py
from .node import Node

"""
This module contains classes for walking abstract syntax trees and transforming
them.
"""

class NodeVisitor(object):
    """
    Walks the abstract syntax tree, calling the visitor function for every
    subtree found.
    """
    def __init__(self):
        self._visitor_cache = {}

    def get_visitor(self, node):
        node_class = node.__class__
        visitor = self._visitor_cache.get(node_class)
        if visitor is None:
            method = 'visit_%s' % node_class.__name__
            visitor = getattr(self, method, self.generic_visit)
            self._visitor_cache[node_class] = visitor
        return visitor

    def visit(self, node):
        visitor = self.get_visitor(node)
        return visitor(node)

    def generic_visit(self, node):

        if isinstance(node, Node):