The QAPI schema parser has always accepted only single-quoted strings, even though JSON strings are double-quoted. Accept double-quoted strings as well, so you can write strings containing single quotes without backslash escapes.
Signed-off-by: Markus Armbruster <[email protected]> --- docs/devel/qapi-code-gen.txt | 2 +- scripts/qapi.py | 8 +++++--- tests/qapi-schema/qapi-schema-test.json | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index 3186c36460..835c641ea8 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -32,7 +32,7 @@ differences: * No JSON numbers -* Strings use 'single quotes' instead of "double quotes" +* Strings can use 'single quotes' in addition to "double quotes" * The input character set is plain ASCII diff --git a/scripts/qapi.py b/scripts/qapi.py index 477402b7f8..18c8175866 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -382,14 +382,15 @@ class QAPISchemaParser(object): return elif self.tok in '{}:,[]': return - elif self.tok == "'": + elif self.tok == "'" or self.tok == '"': string = '' esc = False while True: ch = self.src[self.cursor] self.cursor += 1 if ch == '\n': - raise QAPIParseError(self, 'Missing terminating "\'"') + raise QAPIParseError( + self, 'Missing terminating %r' % self.tok) if esc: if ch == 'b': string += '\b' @@ -429,8 +430,9 @@ class QAPISchemaParser(object): esc = False elif ch == '\\': esc = True - elif ch == "'": + elif ch == self.tok: self.val = string + self.tok = "'" return else: string += ch diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qapi-schema-test.json index ac8aefc924..c74d5632a5 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -11,7 +11,7 @@ 'guest-sync' ] } } { 'struct': 'TestStruct', - 'data': { 'integer': 'int', 'boolean': 'bool', 'string': 'str' } } + 'data': { 'integer': 'int', 'boolean': 'bool', 'string': "str" } } # for testing enums { 'struct': 'NestedEnumsOne', -- 2.13.6
