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>
This commit is contained in:
Alexandru Croitor 2019-05-23 10:59:05 +02:00
parent 837f592c5e
commit 80271e8280

View File

@ -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)