diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-05-23 10:59:05 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-05-23 14:17:34 +0000 |
commit | 80271e82807b4ac51d158398d08554925b9fcdd5 (patch) | |
tree | acc0eb3a951c8b200c99fa781f367646358e1122 /util | |
parent | 837f592c5e98d8d06854421cadb6a4fd2c0a7a3d (diff) |
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 <tobias.hunger@qt.io>
Diffstat (limited to 'util')
-rwxr-xr-x | util/cmake/pro2cmake.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py index 3f9b4ccb53..ea68b57a19 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) |