diff --git a/lark-stubs/reconstruct.pyi b/lark-stubs/reconstruct.pyi index 9826428..a8d39e3 100644 --- a/lark-stubs/reconstruct.pyi +++ b/lark-stubs/reconstruct.pyi @@ -34,5 +34,6 @@ class Reconstructor: def __init__(self, parser: Lark, term_subs: Dict[str, Callable[[Symbol], str]] = ...): ... - def reconstruct(self, tree: Tree, postproc: Callable[[Iterable[str]], Iterable[str]]) -> str: + def reconstruct(self, tree: Tree, postproc: Callable[[Iterable[str]], Iterable[str]]=None, + insert_spaces: bool = True) -> str: ... diff --git a/lark/reconstruct.py b/lark/reconstruct.py index 2efc0ae..ab2fb38 100644 --- a/lark/reconstruct.py +++ b/lark/reconstruct.py @@ -87,14 +87,14 @@ class Reconstructor(TreeMatcher): else: yield item - def reconstruct(self, tree, postproc=None): + def reconstruct(self, tree, postproc=None, insert_spaces=True): x = self._reconstruct(tree) if postproc: x = postproc(x) y = [] prev_item = '' for item in x: - if prev_item and item and is_id_continue(prev_item[-1]) and is_id_continue(item[0]): + if insert_spaces and prev_item and item and is_id_continue(prev_item[-1]) and is_id_continue(item[0]): y.append(' ') y.append(item) prev_item = item