From 7ecb7c78c17990b151c4e63d7f8422d302663d3d Mon Sep 17 00:00:00 2001
From: Sander Mathijs van Veen <smvv@kompiler.org>
Date: Mon, 27 Feb 2012 16:15:48 +0100
Subject: [PATCH] Print modifications done by hook_read_after() only once.
---
src/parser.py | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/src/parser.py b/src/parser.py
index 8c771d6..5653b42 100644
--- a/src/parser.py
+++ b/src/parser.py
@@ -175,6 +175,9 @@ class Parser(BisonParser):
# match: ab | abc | abcd (where left = "a")
return '*'.join([left] + list(right))
+ if self.verbose: # pragma: nocover
+ data_before = data
+
# Iteratively replace all matches.
while True:
data_after = re.sub(pattern, preprocess_data, data)
@@ -182,13 +185,13 @@ class Parser(BisonParser):
if data == data_after:
break
- if self.verbose: # pragma: nocover
- print 'hook_read_after() modified the input data:'
- print 'before:', data.replace('\n', '\\n')
- print 'after :', data_after.replace('\n', '\\n')
-
data = data_after
+ if self.verbose and data_before != data_after: # pragma: nocover
+ print 'hook_read_after() modified the input data:'
+ print 'before:', repr(data_before)
+ print 'after :', repr(data_after)
+
return data
def hook_handler(self, target, option, names, values, retval):
--
GitLab