diff options
Diffstat (limited to 'Lib/lib2to3/pgen2/grammar.py')
-rw-r--r-- | Lib/lib2to3/pgen2/grammar.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/lib2to3/pgen2/grammar.py b/Lib/lib2to3/pgen2/grammar.py index b7f867f..26caeb4 100644 --- a/Lib/lib2to3/pgen2/grammar.py +++ b/Lib/lib2to3/pgen2/grammar.py @@ -97,6 +97,19 @@ class Grammar(object): f.close() self.__dict__.update(d) + def copy(self): + """ + Copy the grammar. + """ + new = self.__class__() + for dict_attr in ("symbol2number", "number2symbol", "dfas", "keywords", + "tokens", "symbol2label"): + setattr(new, dict_attr, getattr(self, dict_attr).copy()) + new.labels = self.labels[:] + new.states = self.states[:] + new.start = self.start + return new + def report(self): """Dump the grammar tables to standard output, for debugging.""" from pprint import pprint |