[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [RFC PATCH 19/32] qapi: Accept double-quoted strings
From: |
Marc-André Lureau |
Subject: |
Re: [Qemu-devel] [RFC PATCH 19/32] qapi: Accept double-quoted strings |
Date: |
Wed, 4 Oct 2017 13:58:59 +0200 |
On Mon, Oct 2, 2017 at 5:25 PM, Markus Armbruster <address@hidden> wrote:
> 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 <address@hidden>
What's the motivation to allow both? If we were to switch from single
to double quote only, that would make more sense.
otherwise, patch looks good
> ---
> 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
>
>
--
Marc-André Lureau
- Re: [Qemu-devel] [RFC PATCH 08/32] qapi: Simplify check_name() parameters, (continued)
- [Qemu-devel] [RFC PATCH 10/32] qapi: Don't run generators twice, Markus Armbruster, 2017/10/02
- [Qemu-devel] [RFC PATCH 31/32] qapi/options: QAPIfy --blockdev argument type, Markus Armbruster, 2017/10/02
- [Qemu-devel] [RFC PATCH 05/32] qapi2texi: Provide access to Texinfo markup, Markus Armbruster, 2017/10/02
- [Qemu-devel] [RFC PATCH 21/32] qapi: Define QAPIOptionKind and QAPIOption automatically, Markus Armbruster, 2017/10/02
- [Qemu-devel] [RFC PATCH 23/32] qapi-options: Command line option backend, Markus Armbruster, 2017/10/02
- [Qemu-devel] [RFC PATCH 25/32] qapi-introspect: Include command line options information, Markus Armbruster, 2017/10/02
- [Qemu-devel] [RFC PATCH 20/32] qapi: Frontend for defining command line options, Markus Armbruster, 2017/10/02
- [Qemu-devel] [RFC PATCH 19/32] qapi: Accept double-quoted strings, Markus Armbruster, 2017/10/02
[Qemu-devel] [RFC PATCH 12/32] qapi: Use argparse to parse command line arguments, Markus Armbruster, 2017/10/02
[Qemu-devel] [RFC PATCH 17/32] qapi: Fix simple union lowering with multiple schemas, Markus Armbruster, 2017/10/02
[Qemu-devel] [RFC PATCH 15/32] tests/qapi-schema: Improve simple union coverage, Markus Armbruster, 2017/10/02