|
37 | 37 | from functools import partial, wraps |
38 | 38 | from collections import defaultdict |
39 | 39 | from threading import Lock |
| 40 | +from copy import copy |
40 | 41 |
|
41 | 42 | from coconut._pyparsing import ( |
42 | 43 | USE_COMPUTATION_GRAPH, |
43 | 44 | USE_CACHE, |
44 | | - USE_LINE_BY_LINE, |
45 | 45 | ParseBaseException, |
46 | 46 | ParseResults, |
47 | 47 | col as getcol, |
|
108 | 108 | assert_remove_suffix, |
109 | 109 | dictset, |
110 | 110 | noop_ctx, |
| 111 | + create_method, |
111 | 112 | ) |
112 | 113 | from coconut.exceptions import ( |
113 | 114 | CoconutException, |
@@ -484,12 +485,16 @@ def get_cli_args(self): |
484 | 485 | args.append("--no-wrap-types") |
485 | 486 | return args |
486 | 487 |
|
487 | | - def __copy__(self): |
488 | | - """Create a new, blank copy of the compiler.""" |
489 | | - cls, args = self.__reduce__() |
490 | | - return cls(*args) |
491 | | - |
492 | | - copy = __copy__ |
| 488 | + def copy(self, snapshot=False): |
| 489 | + """Create a blank copy of the compiler, or a non-blank copy if snapshot=True.""" |
| 490 | + if snapshot: |
| 491 | + old_reduce, self.__reduce__ = self.__reduce__, create_method(object.__reduce__, self, self.__class__) |
| 492 | + try: |
| 493 | + return copy(self) |
| 494 | + finally: |
| 495 | + self.__reduce__ = old_reduce |
| 496 | + else: |
| 497 | + return copy(self) |
493 | 498 |
|
494 | 499 | def genhash(self, code, package_level=-1): |
495 | 500 | """Generate a hash from code.""" |
@@ -1357,7 +1362,7 @@ def run_final_checks(self, original, keep_state=False): |
1357 | 1362 |
|
1358 | 1363 | def parse_line_by_line(self, init_parser, line_parser, original): |
1359 | 1364 | """Apply init_parser then line_parser repeatedly.""" |
1360 | | - if not USE_LINE_BY_LINE: |
| 1365 | + if not USE_COMPUTATION_GRAPH: |
1361 | 1366 | raise CoconutException("line-by-line parsing not supported", extra="run 'pip install --upgrade cPyparsing' to fix") |
1362 | 1367 | with ComputationNode.using_overrides(): |
1363 | 1368 | ComputationNode.override_original = original |
|
0 commit comments