From: Anthony Liguori <aliguori@us.ibm.com>
To: Markus Armbruster <armbru@redhat.com>, qemu-devel@nongnu.org
Cc: akong@redhat.com, mdroth@linux.vnet.ibm.com
Subject: Re: [Qemu-devel] [PATCH 0/9] Our QAPI parser is a hack, replace it
Date: Fri, 26 Jul 2013 09:41:01 -0500 [thread overview]
Message-ID: <87ppu575aa.fsf@codemonkey.ws> (raw)
In-Reply-To: <1374842387-17146-1-git-send-email-armbru@redhat.com>
Markus Armbruster <armbru@redhat.com> writes:
> If you think I'm exaggerating, check out the list of issues in PATCH
> 3/9.
You are not.
However, I think we can drop the whole thing and just use the JSON
module in Python. The bit below seems to work:
import json.decoder, re
from ordereddict import OrderedDict
WHITESPACE = re.compile(r'(#.*\n|[ \r\t\n]*)*', re.MULTILINE)
def make_object(pairs):
return OrderedDict(pairs)
def qapi_parse(data):
_w = WHITESPACE.match
idx = 0
while idx < len(data):
idx = _w(data, idx).end()
if idx == len(data):
break
decoder = json.decoder.JSONDecoder(object_pairs_hook=make_object)
obj, idx = decoder.raw_decode(data, idx)
yield obj
if __name__ == '__main__':
with open('qapi-schema.json', 'r') as fp:
data = fp.read().replace("'", '"')
exprs = list(qapi_parse(data))
print exprs
Regards,
Anthony Liguori
>
> Markus Armbruster (9):
> tests: QAPI schema parser tests
> tests: Use qapi-schema-test.json as schema parser test
> qapi.py: Restructure lexer and parser
> qapi.py: Decent syntax error reporting
> qapi.py: Reject invalid characters in schema file
> qapi.py: Fix schema parser to check syntax systematically
> qapi.py: Fix diagnosing non-objects at a schema's top-level
> qapi.py: Rename expr_eval to expr in parse_schema()
> qapi.py: Permit comments starting anywhere on the line
>
> configure | 2 +-
> qapi-schema-test.json | 53 ------
> scripts/qapi.py | 225 +++++++++++++++----------
> tests/Makefile | 28 ++-
> tests/qapi-schema/empty.exit | 1 +
> tests/qapi-schema/empty.out | 3 +
> tests/qapi-schema/funny-char.err | 1 +
> tests/qapi-schema/funny-char.exit | 1 +
> tests/qapi-schema/funny-char.json | 2 +
> tests/qapi-schema/indented-expr.exit | 1 +
> tests/qapi-schema/indented-expr.json | 2 +
> tests/qapi-schema/indented-expr.out | 3 +
> tests/qapi-schema/missing-colon.err | 1 +
> tests/qapi-schema/missing-colon.exit | 1 +
> tests/qapi-schema/missing-colon.json | 2 +
> tests/qapi-schema/missing-comma.err | 1 +
> tests/qapi-schema/missing-comma.exit | 1 +
> tests/qapi-schema/missing-comma.json | 2 +
> tests/qapi-schema/non-objects.err | 1 +
> tests/qapi-schema/non-objects.exit | 1 +
> tests/qapi-schema/non-objects.json | 2 +
> tests/qapi-schema/qapi-schema-test.exit | 1 +
> tests/qapi-schema/qapi-schema-test.json | 53 ++++++
> tests/qapi-schema/qapi-schema-test.out | 19 +++
> tests/qapi-schema/quoted-structural-chars.err | 1 +
> tests/qapi-schema/quoted-structural-chars.exit | 1 +
> tests/qapi-schema/quoted-structural-chars.json | 1 +
> tests/qapi-schema/test-qapi.py | 27 +++
> tests/qapi-schema/unclosed-object.err | 1 +
> tests/qapi-schema/unclosed-object.exit | 1 +
> tests/qapi-schema/unclosed-object.json | 1 +
> tests/qapi-schema/unclosed-string.err | 1 +
> tests/qapi-schema/unclosed-string.exit | 1 +
> tests/qapi-schema/unclosed-string.json | 2 +
> 34 files changed, 298 insertions(+), 146 deletions(-)
> delete mode 100644 qapi-schema-test.json
> create mode 100644 tests/qapi-schema/empty.err
> create mode 100644 tests/qapi-schema/empty.exit
> create mode 100644 tests/qapi-schema/empty.json
> create mode 100644 tests/qapi-schema/empty.out
> create mode 100644 tests/qapi-schema/funny-char.err
> create mode 100644 tests/qapi-schema/funny-char.exit
> create mode 100644 tests/qapi-schema/funny-char.json
> create mode 100644 tests/qapi-schema/funny-char.out
> create mode 100644 tests/qapi-schema/indented-expr.err
> create mode 100644 tests/qapi-schema/indented-expr.exit
> create mode 100644 tests/qapi-schema/indented-expr.json
> create mode 100644 tests/qapi-schema/indented-expr.out
> create mode 100644 tests/qapi-schema/missing-colon.err
> create mode 100644 tests/qapi-schema/missing-colon.exit
> create mode 100644 tests/qapi-schema/missing-colon.json
> create mode 100644 tests/qapi-schema/missing-colon.out
> create mode 100644 tests/qapi-schema/missing-comma.err
> create mode 100644 tests/qapi-schema/missing-comma.exit
> create mode 100644 tests/qapi-schema/missing-comma.json
> create mode 100644 tests/qapi-schema/missing-comma.out
> create mode 100644 tests/qapi-schema/non-objects.err
> create mode 100644 tests/qapi-schema/non-objects.exit
> create mode 100644 tests/qapi-schema/non-objects.json
> create mode 100644 tests/qapi-schema/non-objects.out
> create mode 100644 tests/qapi-schema/qapi-schema-test.err
> create mode 100644 tests/qapi-schema/qapi-schema-test.exit
> create mode 100644 tests/qapi-schema/qapi-schema-test.json
> create mode 100644 tests/qapi-schema/qapi-schema-test.out
> create mode 100644 tests/qapi-schema/quoted-structural-chars.err
> create mode 100644 tests/qapi-schema/quoted-structural-chars.exit
> create mode 100644 tests/qapi-schema/quoted-structural-chars.json
> create mode 100644 tests/qapi-schema/quoted-structural-chars.out
> create mode 100644 tests/qapi-schema/test-qapi.py
> create mode 100644 tests/qapi-schema/unclosed-object.err
> create mode 100644 tests/qapi-schema/unclosed-object.exit
> create mode 100644 tests/qapi-schema/unclosed-object.json
> create mode 100644 tests/qapi-schema/unclosed-object.out
> create mode 100644 tests/qapi-schema/unclosed-string.err
> create mode 100644 tests/qapi-schema/unclosed-string.exit
> create mode 100644 tests/qapi-schema/unclosed-string.json
> create mode 100644 tests/qapi-schema/unclosed-string.out
>
> --
> 1.7.11.7
next prev parent reply other threads:[~2013-07-26 14:43 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-26 12:39 [Qemu-devel] [PATCH 0/9] Our QAPI parser is a hack, replace it Markus Armbruster
2013-07-26 12:39 ` [Qemu-devel] [PATCH 1/9] tests: QAPI schema parser tests Markus Armbruster
2013-07-26 12:48 ` Eric Blake
2013-07-26 14:16 ` Markus Armbruster
2013-07-26 14:57 ` Eric Blake
2013-07-26 15:31 ` Markus Armbruster
2013-07-26 12:39 ` [Qemu-devel] [PATCH 2/9] tests: Use qapi-schema-test.json as schema parser test Markus Armbruster
2013-07-26 13:17 ` Eric Blake
2013-07-27 15:34 ` Markus Armbruster
2013-07-26 12:39 ` [Qemu-devel] [PATCH 3/9] qapi.py: Restructure lexer and parser Markus Armbruster
2013-07-26 13:54 ` Eric Blake
2013-07-26 12:39 ` [Qemu-devel] [PATCH 4/9] qapi.py: Decent syntax error reporting Markus Armbruster
2013-07-26 15:30 ` Eric Blake
2013-07-26 19:33 ` Markus Armbruster
2013-07-26 19:48 ` Paolo Bonzini
2013-07-26 19:57 ` Eric Blake
2013-07-26 12:39 ` [Qemu-devel] [PATCH 5/9] qapi.py: Reject invalid characters in schema file Markus Armbruster
2013-07-26 15:32 ` Eric Blake
2013-07-26 12:39 ` [Qemu-devel] [PATCH 6/9] qapi.py: Fix schema parser to check syntax systematically Markus Armbruster
2013-07-26 15:56 ` Eric Blake
2013-07-26 19:35 ` Markus Armbruster
2013-07-26 19:42 ` Eric Blake
2013-07-26 12:39 ` [Qemu-devel] [PATCH 7/9] qapi.py: Fix diagnosing non-objects at a schema's top-level Markus Armbruster
2013-07-26 16:03 ` Eric Blake
2013-07-26 12:39 ` [Qemu-devel] [PATCH 8/9] qapi.py: Rename expr_eval to expr in parse_schema() Markus Armbruster
2013-07-26 16:13 ` Eric Blake
2013-07-26 12:39 ` [Qemu-devel] [PATCH 9/9] qapi.py: Permit comments starting anywhere on the line Markus Armbruster
2013-07-26 16:15 ` Eric Blake
2013-07-26 14:41 ` Anthony Liguori [this message]
2013-07-26 15:36 ` [Qemu-devel] [PATCH 0/9] Our QAPI parser is a hack, replace it Markus Armbruster
2013-07-26 17:47 ` Anthony Liguori
2013-07-26 19:48 ` Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ppu575aa.fsf@codemonkey.ws \
--to=aliguori@us.ibm.com \
--cc=akong@redhat.com \
--cc=armbru@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.