qapi: Improve reporting of lexical errors
authorMarkus Armbruster <armbru@redhat.com>
Sat, 14 Sep 2019 15:34:55 +0000 (17:34 +0200)
committerMarkus Armbruster <armbru@redhat.com>
Tue, 24 Sep 2019 12:07:23 +0000 (14:07 +0200)
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>
scripts/qapi/common.py
tests/qapi-schema/bad-type-int.err
tests/qapi-schema/funny-word.err

index 142ab276ffb69df15b5bf28817db0a07faf37caf..b3383b17efe715285dba0a40f2c41d82f1cc060c 100644 (file)
@@ -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()
index 2021fda5d142dacf2fda63bfeae7d01f42655995..9b2c12c1ebe5ecf72630ee917502b7afee8b1dc3 100644 (file)
@@ -1 +1 @@
-tests/qapi-schema/bad-type-int.json:3:13: Stray '1'
+tests/qapi-schema/bad-type-int.json:3:13: Stray '123'
index 18aedb4a99806bd9a7f3aea03be6a79e37f29f0e..af92fe2551c5c760a54903a88100a90b02e5b027 100644 (file)
@@ -1 +1 @@
-tests/qapi-schema/funny-word.json:1:3: Stray 'c'
+tests/qapi-schema/funny-word.json:1:3: Stray 'command'