diff options
author | Markus Armbruster <armbru@redhat.com> | 2019-09-14 17:34:55 +0200 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2019-09-24 14:07:23 +0200 |
commit | 14c32795024c815316337b019bdf88d76b429af8 (patch) | |
tree | 95f3589c5ec7e15622843f3cdf588176743a3ba3 | |
parent | 9f5e6b088a2d0b2b51e1cdf7c86f23f22d9ad493 (diff) | |
download | qemu-14c32795024c815316337b019bdf88d76b429af8.zip qemu-14c32795024c815316337b019bdf88d76b429af8.tar.gz qemu-14c32795024c815316337b019bdf88d76b429af8.tar.bz2 |
qapi: Improve reporting of lexical errors
Show text up to next structural character, whitespace, or quote
character instead of just the first character.
Forgotten quotes now get reported like "Stray 'command'" instead of
"Stray 'c'".
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20190914153506.2151-9-armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
-rw-r--r-- | scripts/qapi/common.py | 6 | ||||
-rw-r--r-- | tests/qapi-schema/bad-type-int.err | 2 | ||||
-rw-r--r-- | tests/qapi-schema/funny-word.err | 2 |
3 files changed, 7 insertions, 3 deletions
diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 142ab27..b3383b1 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -559,7 +559,11 @@ class QAPISchemaParser(object): self.line += 1 self.line_pos = self.cursor elif not self.tok.isspace(): - raise QAPIParseError(self, "Stray '%s'" % self.tok) + # Show up to next structural, whitespace or quote + # character + match = re.match('[^[\\]{}:,\\s\'"]+', + self.src[self.cursor-1:]) + raise QAPIParseError(self, "Stray '%s'" % match.group(0)) def get_members(self): expr = OrderedDict() diff --git a/tests/qapi-schema/bad-type-int.err b/tests/qapi-schema/bad-type-int.err index 2021fda..9b2c12c 100644 --- a/tests/qapi-schema/bad-type-int.err +++ b/tests/qapi-schema/bad-type-int.err @@ -1 +1 @@ -tests/qapi-schema/bad-type-int.json:3:13: Stray '1' +tests/qapi-schema/bad-type-int.json:3:13: Stray '123' diff --git a/tests/qapi-schema/funny-word.err b/tests/qapi-schema/funny-word.err index 18aedb4..af92fe2 100644 --- a/tests/qapi-schema/funny-word.err +++ b/tests/qapi-schema/funny-word.err @@ -1 +1 @@ -tests/qapi-schema/funny-word.json:1:3: Stray 'c' +tests/qapi-schema/funny-word.json:1:3: Stray 'command' |