def __new__(metaclass, name, bases, namespace):
        def unvisit(name):
            """Remove any leading "visit_" from a method name."""
            return name[6:] if name.startswith('visit_') else name

        methods = [v for k, v in namespace.iteritems() if
                   hasattr(v, '_rule') and isfunction(v)]
        if methods:
            from parsimonious.grammar import Grammar  # circular import dodge

            methods.sort(key=(lambda x: x.func_code.co_firstlineno)
                             if version_info[0] < 3 else
                             (lambda x: x.__code__.co_firstlineno))
            # Possible enhancement: once we get the Grammar extensibility story
            # solidified, we can have @rules *add* to the default grammar
            # rather than pave over it.
            namespace['grammar'] = Grammar(
                '\n'.join('{name} = {expr}'.format(name=unvisit(m.__name__),
                                                   expr=m._rule)
                          for m in methods))
        return super(RuleDecoratorMeta,
                     metaclass).__new__(metaclass, name, bases, namespace)
dataset/ETHPy150Open erikrose/parsimonious/parsimonious/nodes.py/RuleDecoratorMeta.__new__/original