diff options
author | Dominik Holland <dominik.holland@qt.io> | 2021-07-02 14:50:17 +0200 |
---|---|---|
committer | Dominik Holland <dominik.holland@googlemail.com> | 2021-07-05 16:14:13 +0200 |
commit | c27fa2a4fee7c94a7b862516c5cb290faf9ff55b (patch) | |
tree | dcb5f79beed57392657889715049a529339b0f91 | |
parent | f36526196517d31a11f4ef667fb73d9a4e61de05 (diff) | |
download | qtivi-qface-c27fa2a4fee7c94a7b862516c5cb290faf9ff55b.tar.gz |
Improve error reporting in qface files
Only report the errors once using our own ErrorHandler.
Also fix a bug which prevented the error message to be shown.
-rw-r--r-- | qface/generator.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/qface/generator.py b/qface/generator.py index e260ed4..47cfd82 100644 --- a/qface/generator.py +++ b/qface/generator.py @@ -62,7 +62,7 @@ class ReportingErrorListener(ErrorListener.ErrorListener): self.document = document def syntaxError(self, recognizer, offendingSymbol, line, column, msg, e): - msg = '{0}:{1}:{2} {2}'.format(self.document, line, column, msg) + msg = '{0}:{1}:{2} {3}'.format(self.document, line, column, msg) click.secho(msg, fg='red') raise ValueError(msg) @@ -301,6 +301,9 @@ class FileSystem(object): click.secho('{0}: error: file not found'.format(document), fg='red', err=True) error = True except ValueError as e: + # The error is already printed in the ErrorHandler in this case + error = True + except Exception as e: click.secho('Error parsing document {0}'.format(document), fg='red', err=True) error = True if error and FileSystem.strict: @@ -332,6 +335,7 @@ class FileSystem(object): lexer = TLexer(stream) stream = CommonTokenStream(lexer) parser = TParser(stream) + parser.removeErrorListeners() parser.addErrorListener(ReportingErrorListener(document)) tree = parser.documentSymbol() walker = ParseTreeWalker() |