diff options
author | Eric Blake <eblake@redhat.com> | 2015-05-04 09:05:09 -0600 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2015-05-05 18:39:00 +0200 |
commit | 268a1c5eb10832c2e4476d3fe199ea547dabecb7 (patch) | |
tree | cc67421189cfe00b49e2cbc1b919f9af5f647ce6 /scripts | |
parent | 44bd1276a7dea747c41f250cb71ab65965343a7f (diff) |
qapi: Prepare for catching more semantic parse errors
This patch widens the scope of a try block (with the attending
reindentation required by Python) in preparation for a future
patch adding more instances of QAPIExprError inside the block.
It's easier to separate indentation from semantic changes, so
this patch has no real behavior change.
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/qapi.py | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/scripts/qapi.py b/scripts/qapi.py index 5f0f699994..0c3459bfe2 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -399,6 +399,7 @@ def check_exprs(schema): check_event(expr, info) def parse_schema(input_file): + # First pass: read entire file into memory try: schema = QAPISchema(open(input_file, "r")) except (QAPISchemaError, QAPIExprError), e: @@ -407,24 +408,26 @@ def parse_schema(input_file): exprs = [] - for expr_elem in schema.exprs: - expr = expr_elem['expr'] - if expr.has_key('enum'): - add_enum(expr['enum'], expr.get('data')) - elif expr.has_key('union'): - add_union(expr) - elif expr.has_key('type'): - add_struct(expr) - exprs.append(expr) - - # Try again for hidden UnionKind enum - for expr_elem in schema.exprs: - expr = expr_elem['expr'] - if expr.has_key('union'): - if not discriminator_find_enum_define(expr): - add_enum('%sKind' % expr['union']) - try: + # Next pass: learn the types. + for expr_elem in schema.exprs: + expr = expr_elem['expr'] + if expr.has_key('enum'): + add_enum(expr['enum'], expr.get('data')) + elif expr.has_key('union'): + add_union(expr) + elif expr.has_key('type'): + add_struct(expr) + exprs.append(expr) + + # Try again for hidden UnionKind enum + for expr_elem in schema.exprs: + expr = expr_elem['expr'] + if expr.has_key('union'): + if not discriminator_find_enum_define(expr): + add_enum('%sKind' % expr['union']) + + # Final pass - validate that exprs make sense check_exprs(schema) except QAPIExprError, e: print >>sys.stderr, e |