summaryrefslogtreecommitdiffstats
path: root/Lib/lib2to3/patcomp.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/lib2to3/patcomp.py')
-rw-r--r--Lib/lib2to3/patcomp.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/Lib/lib2to3/patcomp.py b/Lib/lib2to3/patcomp.py
index 3831622..bb538d5 100644
--- a/Lib/lib2to3/patcomp.py
+++ b/Lib/lib2to3/patcomp.py
@@ -52,14 +52,17 @@ class PatternCompiler(object):
self.pysyms = pygram.python_symbols
self.driver = driver.Driver(self.grammar, convert=pattern_convert)
- def compile_pattern(self, input, debug=False):
+ def compile_pattern(self, input, debug=False, with_tree=False):
"""Compiles a pattern string to a nested pytree.*Pattern object."""
tokens = tokenize_wrapper(input)
try:
root = self.driver.parse_tokens(tokens, debug=debug)
except parse.ParseError as e:
raise PatternSyntaxError(str(e))
- return self.compile_node(root)
+ if with_tree:
+ return self.compile_node(root), root
+ else:
+ return self.compile_node(root)
def compile_node(self, node):
"""Compiles a node, recursively.