Skip to content

Commit 3313b61

Browse files
elmarcoMarkus Armbruster
authored andcommitted
qapi: add qapi2texi script
As the name suggests, the qapi2texi script converts JSON QAPI description into a texi file suitable for different target formats (info/man/txt/pdf/html...). It parses the following kind of blocks: Free-form: ## # = Section # == Subsection # # Some text foo with *emphasis* # 1. with a list # 2. like that # # And some code: # | $ echo foo # | -> do this # | <- get that # ## Symbol description: ## # @symbol: # # Symbol body ditto ergo sum. Foo bar # baz ding. # # @param1: the frob to frobnicate # @Param2: #optional how hard to frobnicate # # Returns: the frobnicated frob. # If frob isn't frobnicatable, GenericError. # # Since: version # Notes: notes, comments can have # - itemized list # - like this # # Example: # # -> { "execute": "quit" } # <- { "return": {} } # ## That's roughly following the following EBNF grammar: api_comment = "##\n" comment "##\n" comment = freeform_comment | symbol_comment freeform_comment = { "# " text "\n" | "#\n" } symbol_comment = "# @" name ":\n" { member | tag_section | freeform_comment } member = "# @" name ':' [ text ] "\n" freeform_comment tag_section = "# " ( "Returns:", "Since:", "Note:", "Notes:", "Example:", "Examples:" ) [ text ] "\n" freeform_comment text = free text with markup Note that the grammar is ambiguous: a line "# @foo:\n" can be parsed both as freeform_comment and as symbol_comment. The actual parser recognizes symbol_comment. See docs/qapi-code-gen.txt for more details. Deficiencies and limitations: - the generated QMP documentation includes internal types - union type support is lacking - type information is lacking in generated documentation - doc comment error message positions are imprecise, they point to the beginning of the comment. - a few minor issues, all marked TODO/FIXME in the code Signed-off-by: Marc-André Lureau <[email protected]> Message-Id: <[email protected]> Reviewed-by: Markus Armbruster <[email protected]> [test-qapi.py tweaked to avoid trailing empty lines in .out] Signed-off-by: Markus Armbruster <[email protected]>
1 parent 231aaf3 commit 3313b61

File tree

276 files changed

+1925
-127
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

276 files changed

+1925
-127
lines changed

docs/qapi-code-gen.txt

Lines changed: 147 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -44,40 +44,154 @@ Input must be ASCII (although QMP supports full Unicode strings, the
4444
QAPI parser does not). At present, there is no place where a QAPI
4545
schema requires the use of JSON numbers or null.
4646

47+
48+
=== Comments ===
49+
4750
Comments are allowed; anything between an unquoted # and the following
48-
newline is ignored. Although there is not yet a documentation
49-
generator, a form of stylized comments has developed for consistently
50-
documenting details about an expression and when it was added to the
51-
schema. The documentation is delimited between two lines of ##, then
52-
the first line names the expression, an optional overview is provided,
53-
then individual documentation about each member of 'data' is provided,
54-
and finally, a 'Since: x.y.z' tag lists the release that introduced
55-
the expression. Optional members are tagged with the phrase
56-
'#optional', often with their default value; and extensions added
57-
after the expression was first released are also given a '(since
58-
x.y.z)' comment. For example:
59-
60-
##
61-
# @BlockStats:
62-
#
63-
# Statistics of a virtual block device or a block backing device.
64-
#
65-
# @device: #optional If the stats are for a virtual block device, the name
66-
# corresponding to the virtual block device.
67-
#
68-
# @stats: A @BlockDeviceStats for the device.
69-
#
70-
# @parent: #optional This describes the file block device if it has one.
71-
#
72-
# @backing: #optional This describes the backing block device if it has one.
73-
# (Since 2.0)
74-
#
75-
# Since: 0.14.0
76-
##
77-
{ 'struct': 'BlockStats',
78-
'data': {'*device': 'str', 'stats': 'BlockDeviceStats',
79-
'*parent': 'BlockStats',
80-
'*backing': 'BlockStats'} }
51+
newline is ignored.
52+
53+
A multi-line comment that starts and ends with a '##' line is a
54+
documentation comment. These are parsed by the documentation
55+
generator, which recognizes certain markup detailed below.
56+
57+
58+
==== Documentation markup ====
59+
60+
Comment text starting with '=' is a section title:
61+
62+
# = Section title
63+
64+
Double the '=' for a subsection title:
65+
66+
# == Subection title
67+
68+
'|' denotes examples:
69+
70+
# | Text of the example, may span
71+
# | multiple lines
72+
73+
'*' starts an itemized list:
74+
75+
# * First item, may span
76+
# multiple lines
77+
# * Second item
78+
79+
You can also use '-' instead of '*'.
80+
81+
A decimal number followed by '.' starts a numbered list:
82+
83+
# 1. First item, may span
84+
# multiple lines
85+
# 2. Second item
86+
87+
The actual number doesn't matter. You could even use '*' instead of
88+
'2.' for the second item.
89+
90+
Lists can't be nested. Blank lines are currently not supported within
91+
lists.
92+
93+
Additional whitespace between the initial '#' and the comment text is
94+
permitted.
95+
96+
*foo* and _foo_ are for strong and emphasis styles respectively (they
97+
do not work over multiple lines). @foo is used to reference a name in
98+
the schema.
99+
100+
Example:
101+
102+
##
103+
# = Section
104+
# == Subsection
105+
#
106+
# Some text foo with *strong* and _emphasis_
107+
# 1. with a list
108+
# 2. like that
109+
#
110+
# And some code:
111+
# | $ echo foo
112+
# | -> do this
113+
# | <- get that
114+
#
115+
##
116+
117+
118+
==== Expression documentation ====
119+
120+
Each expression that isn't an include directive must be preceded by a
121+
documentation block. Such blocks are called expression documentation
122+
blocks.
123+
124+
The documentation block consists of a first line naming the
125+
expression, an optional overview, a description of each argument (for
126+
commands and events) or member (for structs, unions and alternates),
127+
and optional tagged sections.
128+
129+
FIXME: the parser accepts these things in almost any order.
130+
131+
Optional arguments / members are tagged with the phrase '#optional',
132+
often with their default value; and extensions added after the
133+
expression was first released are also given a '(since x.y.z)'
134+
comment.
135+
136+
A tagged section starts with one of the following words:
137+
"Note:"/"Notes:", "Since:", "Example"/"Examples", "Returns:", "TODO:".
138+
The section ends with the start of a new section.
139+
140+
A 'Since: x.y.z' tagged section lists the release that introduced the
141+
expression.
142+
143+
For example:
144+
145+
##
146+
# @BlockStats:
147+
#
148+
# Statistics of a virtual block device or a block backing device.
149+
#
150+
# @device: #optional If the stats are for a virtual block device, the name
151+
# corresponding to the virtual block device.
152+
#
153+
# @node-name: #optional The node name of the device. (since 2.3)
154+
#
155+
# ... more members ...
156+
#
157+
# Since: 0.14.0
158+
##
159+
{ 'struct': 'BlockStats',
160+
'data': {'*device': 'str', '*node-name': 'str',
161+
... more members ... } }
162+
163+
##
164+
# @query-blockstats:
165+
#
166+
# Query the @BlockStats for all virtual block devices.
167+
#
168+
# @query-nodes: #optional If true, the command will query all the
169+
# block nodes ... explain, explain ... (since 2.3)
170+
#
171+
# Returns: A list of @BlockStats for each virtual block devices.
172+
#
173+
# Since: 0.14.0
174+
#
175+
# Example:
176+
#
177+
# -> { "execute": "query-blockstats" }
178+
# <- {
179+
# ... lots of output ...
180+
# }
181+
#
182+
##
183+
{ 'command': 'query-blockstats',
184+
'data': { '*query-nodes': 'bool' },
185+
'returns': ['BlockStats'] }
186+
187+
==== Free-form documentation ====
188+
189+
A documentation block that isn't an expression documentation block is
190+
a free-form documentation block. These may be used to provide
191+
additional text and structuring content.
192+
193+
194+
=== Schema overview ===
81195

82196
The schema sets up a series of types, as well as commands and events
83197
that will use those types. Forward references are allowed: the parser

0 commit comments

Comments
 (0)