Received: from eggs.gnu.org ([2001:4830:134:3::10]:50634) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c0DGn-0005Sh-4Z for qemu-devel@nongnu.org; Fri, 28 Oct 2016 15:56:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c0DGi-0005fG-Kz for qemu-devel@nongnu.org; Fri, 28 Oct 2016 15:56:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34976) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c0DGi-0005er-CO for qemu-devel@nongnu.org; Fri, 28 Oct 2016 15:56:48 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 537C054E1B for ; Fri, 28 Oct 2016 19:56:47 +0000 (UTC) References: <20160925181836.18293-1-marcandre.lureau@redhat.com> <20160925181836.18293-2-marcandre.lureau@redhat.com> <87zilowhi3.fsf@dusky.pond.sub.org> From: Eric Blake Message-ID: <3189c762-e683-8eff-3665-db0d2b97808d@redhat.com> Date: Fri, 28 Oct 2016 14:56:45 -0500 MIME-Version: 1.0 In-Reply-To: <87zilowhi3.fsf@dusky.pond.sub.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="auN7kLvnKqFQTxwrRFPxqTllP44hLMWkh" Subject: Re: [Qemu-devel] [PATCH v2 01/11] qapi: add qapi2texi script List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster , =?UTF-8?Q?Marc-Andr=c3=a9_Lureau?= Cc: qemu-devel@nongnu.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --auN7kLvnKqFQTxwrRFPxqTllP44hLMWkh From: Eric Blake To: Markus Armbruster , =?UTF-8?Q?Marc-Andr=c3=a9_Lureau?= Cc: qemu-devel@nongnu.org Message-ID: <3189c762-e683-8eff-3665-db0d2b97808d@redhat.com> Subject: Re: [Qemu-devel] [PATCH v2 01/11] qapi: add qapi2texi script References: <20160925181836.18293-1-marcandre.lureau@redhat.com> <20160925181836.18293-2-marcandre.lureau@redhat.com> <87zilowhi3.fsf@dusky.pond.sub.org> In-Reply-To: <87zilowhi3.fsf@dusky.pond.sub.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 10/28/2016 11:44 AM, Markus Armbruster wrote: > Marc-Andr=C3=A9 Lureau writes: >=20 >> As the name suggests, the qapi2texi script converts JSON QAPI >> description into a standalone texi file suitable for different target >> formats. >> >> It parses the following kind of blocks with some little variations: >> >> ## >> # =3D Section >> # =3D=3D Subsection >> # >> # Some text foo with *emphasis* >> # 1. with a list >> # 2. like that >> # >> # And some code: >> # | $ echo foo >> # | <- do this >> # | -> get that Backwards. Pre-patch, qmp-commands.txt states: > Also, the following notation is used to denote data flow: >=20 > -> data issued by the Client > <- Server data response so you want -> do this <- get that >> # >> ## How much effort is it to get rid of the "little variations" and flag documentation that does not match consistent patterns? A tighter parser that requires specific format, but also diagnoses where comments don't meet that format, is probably going to be easier to maintain in the long run (fewer special cases) even if it is more painful up front (more tweaks to bring things into a consistent layout). >> >> ## >> # @symbol >> # >> # Symbol body ditto ergo sum. Foo bar >> # baz ding. >> # >> # @arg: foo >> # @arg: #optional foo >> # >> # Returns: returns bla bla >> # >> # Or bla blah >> # >> # Since: version >> # Notes: notes, comments can have >> # - itemized list >> # - like this >> # >> # and continue... >> # >> # Example: >> # >> # <- { "execute": "quit" } >> # -> { "return": {} } Again, backwards. >> # >> ## >> >> Thanks to the json declaration, it's able to give extra information >> about the type of arguments and return value expected. >> >> Signed-off-by: Marc-Andr=C3=A9 Lureau >> --- >> scripts/qapi.py | 100 +++++++++++++++- >> scripts/qapi2texi.py | 314 ++++++++++++++++++++++++++++++++++++++++= +++++++++ >> docs/qapi-code-gen.txt | 44 +++++-- >> 3 files changed, 446 insertions(+), 12 deletions(-) >> create mode 100755 scripts/qapi2texi.py >=20 > My review will be easier to follow if you skip ahead qapi-code-gen.txt,= > then go to class QAPISchemaParser, then come back here. Commenting on just a few points: >> + if key.startswith("@"): >> + key =3D key[1:].rstrip(':') >=20 > Treats the colon as optional. I understand you're trying to be > unintrusive, but since we're parsing comments already, we can make the > parser do double duty and enforce consistent comment formatting. But > this isn't the place to discuss the format we want, review of > qapi-code-gen.txt is. Makes sense - since we are writing a parser, we can make it be strict and pick one approved format, rather than allowing two separate formats; the parser will point out what needs to be fixed, and we actually make those fixes then rearrange the series so the fixes come first. >=20 > Taken together: >=20 > * The QAPI parser is hacked to accumulate and exfiltrate some comments > to the QAPIDoc parser. I haven't closely looked at the code yet, just the review comments at this point. During the QAPI parse of the .json file, are we passing the entire ##...## comment (of which there should be at most one per top-level element of the .json file), and then letting QAPIDoc further parse that comment block? Or are you trying to combine both levels of parsing into the same parser object? > General remarks: >=20 > * I feel the only way to keep the API documentation in order as we > develop is to have the parser reject malformed API comments. Agreed. Forcing docs to be well-written up front will pay benefits in ease of maintenance and uniformity of style (it's a lot easier to copy-and-paste a working style if that is the only style to copy from), once we have converted existing documentation to be well-formed. >=20 > * The only way to create a robust and maintainable parser is to specify= > the language *first* and *rigorously*. >=20 > * Stacking parsers is not a good idea. Figuring out one parser's > accepted language is hard enough. We do have the nice aspect that there is (should be) at most one ##...## comment body per QAPI (pseudo-JSON) object, so the QAPI parse just needs to find that comment block and associate it with everything else it parsed. Further parsing the documentation comment into sections for output, as well as double-checking sanity aspects (such as no missing or extra parameters) may require more coordination between the parsed QAPI object and the code that parses the comments. >> +++ b/docs/qapi-code-gen.txt >> @@ -45,16 +45,13 @@ QAPI parser does not). At present, there is no pl= ace where a QAPI >> schema requires the use of JSON numbers or null. >> =20 >> Comments are allowed; anything between an unquoted # and the followin= g >> -newline is ignored. Although there is not yet a documentation >> -generator, a form of stylized comments has developed for consistently= >> -documenting details about an expression and when it was added to the >> -schema. The documentation is delimited between two lines of ##, then= >> -the first line names the expression, an optional overview is provided= , >> -then individual documentation about each member of 'data' is provided= , >> -and finally, a 'Since: x.y.z' tag lists the release that introduced >> -the expression. Optional members are tagged with the phrase >> -'#optional', often with their default value; and extensions added >> -after the expression was first released are also given a '(since >> +newline is ignored. The documentation is delimited between two lines= >> +of ##, then the first line names the expression, an optional overview= >> +is provided, then individual documentation about each member of 'data= ' >> +is provided, and finally, a 'Since: x.y.z' tag lists the release that= >> +introduced the expression. Optional members are tagged with the >> +phrase '#optional', often with their default value; and extensions >> +added after the expression was first released are also given a '(sinc= e >> x.y.z)' comment. For example: Okay, so you ARE requiring the grammar to pull out all lines between two ## markers, as well as looking for specific features to delineate sections with the lines. This text doesn't mention Return or Example, so maybe it's worth further spelling it out, something like: api_comment ::=3D double_hash expr_name [overviews] [members] \ [return] since [note] [examples] double_hash along with semantic constraints. For example, expr_name ::=3D name ':', with the constraint that name matches the JSON description; members would be a list of productions matching the JSON description, where each member ::=3D '@' name ':' [#optional] freeform [member_since]. >> =20 >> ## >> @@ -73,12 +70,39 @@ x.y.z)' comment. For example: >> # (Since 2.0) >> # >> # Since: 0.14.0 >> + # >> + # Notes: You can also make a list: >> + # - with items >> + # - like this >> + # >> + # Example: >> + # >> + # <- { "execute": ... } >> + # -> { "return": ... } Again, backwards (looks like copy and paste between the qapi-code-gen.txt and the commit message). >> + # >> ## >> { 'struct': 'BlockStats', >> 'data': {'*device': 'str', 'stats': 'BlockDeviceStats', >> '*parent': 'BlockStats', >> '*backing': 'BlockStats'} } >> =20 >> +It's also possible to create documentation sections, such as: >> + >> + ## >> + # =3D Section >> + # =3D=3D Subsection >> + # >> + # Some text foo with *emphasis* >> + # 1. with a list >> + # 2. like that >> + # >> + # And some code: >> + # | $ echo foo >> + # | <- do this >> + # | -> get that >> + # >> + ## >> + >> The schema sets up a series of types, as well as commands and events >> that will use those types. Forward references are allowed: the parse= r >> scans in two passes, where the first pass learns all type names, and >=20 > This may be good enough to guide users, but it's not rigorous enough to= > actually implement a parser. The API doc language needs to be specifie= d > as a grammar. If not here, then elsewhere. I agree with the sentiment - a tighter description on exactly what is valid vs. required, and where some of the validity is semantics based (the comments must match the JSON description), can help us write a parser that enforces those rules. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --auN7kLvnKqFQTxwrRFPxqTllP44hLMWkh Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJYE61+AAoJEKeha0olJ0NqvrQH/jfhIK4TuoWB6Jc/5b/rIQfC ONYzf+g5K8tnjTuajvupeP0Ghd5vJIh4jFe2myIwmym55EqFr52nJV1Wnq2skKQh WF2RsrvQLCK6Gka23vFvRZxjEjQaeFZn6m1ldBKjcLV64tw8s1DO4RzMHIXx1ry9 5EUVC771FaNsXpUofoCb/PYZgD7NoLzRxwP4Q0VrL8L3IPJmKYJbJueURX0+HPI+ RyaTf9XrIvlLnP490rEewSgLMWRF1jYQDQcIMLEx/91IXXPlcRQ+rtEo9RI2ULUH S44+m9ikWSddNoZiqJX5YTeiD1xkHv9lFkJPbLE7B63WQF3XP5lPzfhGuifSFS0= =qmYq -----END PGP SIGNATURE----- --auN7kLvnKqFQTxwrRFPxqTllP44hLMWkh--