diff --git a/lark-stubs/reconstruct.pyi b/lark-stubs/reconstruct.pyi index 8ac6c14..2220c46 100644 --- a/lark-stubs/reconstruct.pyi +++ b/lark-stubs/reconstruct.pyi @@ -30,7 +30,7 @@ class MakeMatchTree: class Reconstructor: - def __init__(self, parser: Lark): + def __init__(self, parser: Lark, term_subs: Dict[str, str] = ...): ... def reconstruct(self, tree: Tree) -> str: diff --git a/lark/reconstruct.py b/lark/reconstruct.py index 1e3adc7..baf1d2c 100644 --- a/lark/reconstruct.py +++ b/lark/reconstruct.py @@ -87,9 +87,16 @@ def best_from_group(seq, group_key, cmp_key): return list(d.values()) class Reconstructor: - def __init__(self, parser, term_subs={}): + """ + A Reconstructor that will, given a full parse Tree, generate source code. + Pass `term_subs`, a dictionary of [Terminal name as str] to [output text as str] + to say what discarded Terminals should be written as. + """ + def __init__(self, parser, term_subs=None): # XXX TODO calling compile twice returns different results! assert parser.options.maybe_placeholders == False + if term_subs is None: + term_subs = {} tokens, rules, _grammar_extra = parser.grammar.compile(parser.options.start) self.write_tokens = WriteTokensTransformer({t.name:t for t in tokens}, term_subs)