Browse Source

Added visitors & transformers to standalone (Issue #223)

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.6.5
Erez Shinan 6 years ago
parent
commit
53a66132ba
4 changed files with 9 additions and 6 deletions
  1. +2
    -2
      lark/parse_tree_builder.py
  2. +2
    -1
      lark/tools/standalone.py
  3. +1
    -1
      lark/utils.py
  4. +4
    -2
      lark/visitors.py

+ 2
- 2
lark/parse_tree_builder.py View File

@@ -106,7 +106,7 @@ class Callback(object):
pass


def inline_args(func):
def ptb_inline_args(func):
@wraps(func)
def f(children):
return func(*children)
@@ -154,7 +154,7 @@ class ParseTreeBuilder:
assert not getattr(f, 'meta', False), "Meta args not supported for internal transformer"
# XXX InlineTransformer is deprecated!
if getattr(f, 'inline', False) or isinstance(transformer, InlineTransformer):
f = inline_args(f)
f = ptb_inline_args(f)
except AttributeError:
f = partial(self.tree_class, user_callback_name)



+ 2
- 1
lark/tools/standalone.py View File

@@ -56,6 +56,7 @@ EXTRACT_STANDALONE_FILES = [
'utils.py',
'common.py',
'tree.py',
'visitors.py',
'indenter.py',
'lexer.py',
'parse_tree_builder.py',
@@ -161,7 +162,7 @@ class TreeBuilderAtoms:
self.ptb = lark._parse_tree_builder

def print_python(self):
print('class InlineTransformer: pass')
# print('class InlineTransformer: pass')
print('RULES = {')
for i, r in enumerate(self.rules):
rule_ids[r] = i


+ 1
- 1
lark/utils.py View File

@@ -73,6 +73,7 @@ def smart_decorator(f, create_decorator):
return create_decorator(f.__func__.__call__, True)


###}


try:
@@ -93,7 +94,6 @@ except ImportError:
except excs:
pass

###}





+ 4
- 2
lark/visitors.py View File

@@ -1,13 +1,14 @@
from inspect import getmembers, getmro
from functools import wraps

from .utils import smart_decorator
from .tree import Tree

###{standalone
from inspect import getmembers, getmro

class Discard(Exception):
pass


# Transformers

class Transformer:
@@ -250,3 +251,4 @@ def v_args(inline=False, meta=False, tree=False):
return _visitor_args_dec


###}

Loading…
Cancel
Save