diff --git a/lark/exceptions.py b/lark/exceptions.py index ceca493..ceb71b0 100644 --- a/lark/exceptions.py +++ b/lark/exceptions.py @@ -1,5 +1,6 @@ from .utils import STRING_TYPE +###{standalone class LarkError(Exception): pass @@ -85,4 +86,4 @@ class UnexpectedToken(ParseError, UnexpectedInput): super(UnexpectedToken, self).__init__(message) - +###} diff --git a/lark/tools/standalone.py b/lark/tools/standalone.py index 6f3600d..cdde733 100644 --- a/lark/tools/standalone.py +++ b/lark/tools/standalone.py @@ -52,6 +52,7 @@ _larkdir = path.join(_dir, path.pardir) EXTRACT_STANDALONE_FILES = [ 'tools/standalone.py', + 'exceptions.py', 'utils.py', 'common.py', 'tree.py', @@ -160,6 +161,7 @@ class TreeBuilderAtoms: self.ptb = lark._parse_tree_builder def print_python(self): + print('class InlineTransformer: pass') print('RULES = {') for i, r in enumerate(self.rules): rule_ids[r] = i diff --git a/lark/tree.py b/lark/tree.py index 5a29c0f..719ac81 100644 --- a/lark/tree.py +++ b/lark/tree.py @@ -5,10 +5,10 @@ except ImportError: from copy import deepcopy +###{standalone class Meta: pass -###{standalone class Tree(object): def __init__(self, data, children, meta=None): self.data = data @@ -42,14 +42,6 @@ class Tree(object): def pretty(self, indent_str=' '): return ''.join(self._pretty(0, indent_str)) -###} - - def expand_kids_by_index(self, *indices): - "Expand (inline) children at the given indices" - for i in sorted(indices, reverse=True): # reverse so that changing tail won't affect indices - kid = self.children[i] - self.children[i:i+1] = kid.children - def __eq__(self, other): try: return self.data == other.data and self.children == other.children @@ -61,6 +53,13 @@ class Tree(object): def __hash__(self): return hash((self.data, tuple(self.children))) +###} + + def expand_kids_by_index(self, *indices): + "Expand (inline) children at the given indices" + for i in sorted(indices, reverse=True): # reverse so that changing tail won't affect indices + kid = self.children[i] + self.children[i:i+1] = kid.children def find_pred(self, pred): "Find all nodes where pred(tree) == True" diff --git a/lark/utils.py b/lark/utils.py index c86a66d..6a7fdb5 100644 --- a/lark/utils.py +++ b/lark/utils.py @@ -42,12 +42,12 @@ def bfs(initial, expand): +###{standalone try: STRING_TYPE = basestring except NameError: # Python 3 STRING_TYPE = str -###{standalone import types from functools import wraps, partial