From 80271e82807b4ac51d158398d08554925b9fcdd5 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Thu, 23 May 2019 10:59:05 +0200 Subject: [PATCH] Improve qmake parser debug output in pro2cmake Override the default debug actions to be decorated with proper indentation for easier reading. The setup only has to be done once, and not on each QMakeParser creation. Change-Id: If5f965b462c782c654ee8ebfdd33570e8f94b084 Reviewed-by: Tobias Hunger --- util/cmake/pro2cmake.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py index 3f9b4ccb530..ea68b57a197 100755 --- a/util/cmake/pro2cmake.py +++ b/util/cmake/pro2cmake.py @@ -683,6 +683,33 @@ class QmakeParser: def __init__(self, *, debug: bool = False) -> None: self._Grammar = self._generate_grammar(debug) + @staticmethod + def set_up_py_parsing_nicer_debug_output(): + indent = -1 + + def increase_indent(fn): + def wrapper_function(*args): + nonlocal indent + indent += 1 + print("> " * indent, end="") + return fn(*args) + + return wrapper_function + + def decrease_indent(fn): + def wrapper_function(*args): + nonlocal indent + print("> " * indent, end="") + indent -= 1 + return fn(*args) + + return wrapper_function + + pp._defaultStartDebugAction = increase_indent(pp._defaultStartDebugAction) + pp._defaultSuccessDebugAction = decrease_indent(pp._defaultSuccessDebugAction) + pp._defaultExceptionDebugAction = decrease_indent(pp._defaultExceptionDebugAction) + + def _generate_grammar(self, debug: bool): # Define grammar: pp.ParserElement.setDefaultWhitespaceChars(' \t') @@ -829,6 +856,9 @@ class QmakeParser: return result +QmakeParser.set_up_py_parsing_nicer_debug_output() + + def parseProFile(file: str, *, debug=False): parser = QmakeParser(debug=debug) return parser.parseFile(file)