On Tue, Sep 5, 2017 at 11:42 AM, Markus Armbruster <arm...@redhat.com> wrote: > Marc-André Lureau <marcandre.lur...@redhat.com> writes: > >> The following patch is going to break list entries with #if/#endif, so >> they should have the trailing ',' as suffix. >> >> Signed-off-by: Marc-André Lureau <marcandre.lur...@redhat.com> >> --- >> scripts/qapi-introspect.py | 8 ++++---- >> 1 file changed, 4 insertions(+), 4 deletions(-) >> >> diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py >> index 4c437d60ec..dfb6d2ded4 100644 >> --- a/scripts/qapi-introspect.py >> +++ b/scripts/qapi-introspect.py >> @@ -16,7 +16,7 @@ def to_c_string(s): >> return '"' + s.replace('\\', r'\\').replace('"', r'\"') + '"' >> >> >> -def to_qlit(obj, level=0, first_indent=True): >> +def to_qlit(obj, level=0, first_indent=True, suffix=''): >> >> def indent(level): >> return level * 4 * ' ' >> @@ -29,11 +29,11 @@ def to_qlit(obj, level=0, first_indent=True): >> elif isinstance(obj, str): >> ret += 'QLIT_QSTR(' + to_c_string(obj) + ')' >> elif isinstance(obj, list): >> - elts = [to_qlit(elt, level + 1) >> + elts = [to_qlit(elt, level + 1, suffix=',') >> for elt in obj] >> elts.append(indent(level + 1) + "{}") >> ret += 'QLIT_QLIST(((QLitObject[]) {\n' >> - ret += ',\n'.join(elts) + '\n' >> + ret += '\n'.join(elts) + '\n' >> ret += indent(level) + '}))' >> elif isinstance(obj, dict): >> elts = [] >> @@ -46,7 +46,7 @@ def to_qlit(obj, level=0, first_indent=True): >> ret += indent(level) + '}))' >> else: >> assert False # not implemented >> - return ret >> + return ret + suffix >> >> >> class QAPISchemaGenIntrospectVisitor(QAPISchemaVisitor): > > Hmm. I wonder the appended simpler patch would do.
It works, thanks for the suggestion > > diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py > index 4c437d60ec..73edb55cd5 100644 > --- a/scripts/qapi-introspect.py > +++ b/scripts/qapi-introspect.py > @@ -33,7 +33,7 @@ def to_qlit(obj, level=0, first_indent=True): > for elt in obj] > elts.append(indent(level + 1) + "{}") > ret += 'QLIT_QLIST(((QLitObject[]) {\n' > - ret += ',\n'.join(elts) + '\n' > + ret += '\n'.join(elts) + '\n' > ret += indent(level) + '}))' > elif isinstance(obj, dict): > elts = [] > @@ -46,6 +46,8 @@ def to_qlit(obj, level=0, first_indent=True): > ret += indent(level) + '}))' > else: > assert False # not implemented > + if level > 0: > + ret += ',' > return ret > > > -- Marc-André Lureau