|
|
@@ -2,6 +2,7 @@ from functools import wraps |
|
|
|
|
|
|
|
from .utils import smart_decorator |
|
|
|
from .tree import Tree |
|
|
|
from .exceptions import VisitError, GrammarError |
|
|
|
|
|
|
|
###{standalone |
|
|
|
from inspect import getmembers, getmro |
|
|
@@ -28,16 +29,21 @@ class Transformer: |
|
|
|
except AttributeError: |
|
|
|
return self.__default__(tree.data, children, tree.meta) |
|
|
|
else: |
|
|
|
if getattr(f, 'meta', False): |
|
|
|
return f(children, tree.meta) |
|
|
|
elif getattr(f, 'inline', False): |
|
|
|
return f(*children) |
|
|
|
elif getattr(f, 'whole_tree', False): |
|
|
|
if new_children is not None: |
|
|
|
raise NotImplementedError("Doesn't work with the base Transformer class") |
|
|
|
return f(tree) |
|
|
|
else: |
|
|
|
return f(children) |
|
|
|
try: |
|
|
|
if getattr(f, 'meta', False): |
|
|
|
return f(children, tree.meta) |
|
|
|
elif getattr(f, 'inline', False): |
|
|
|
return f(*children) |
|
|
|
elif getattr(f, 'whole_tree', False): |
|
|
|
if new_children is not None: |
|
|
|
raise NotImplementedError("Doesn't work with the base Transformer class") |
|
|
|
return f(tree) |
|
|
|
else: |
|
|
|
return f(children) |
|
|
|
except GrammarError: |
|
|
|
raise |
|
|
|
except Exception as e: |
|
|
|
raise VisitError('Error trying to process rule "%s":\n\n%s' % (tree.data, e)) |
|
|
|
|
|
|
|
def _transform_children(self, children): |
|
|
|
for c in children: |
|
|
|