Paolo Bonzini <[email protected]> writes: > In order to avoid stashing all the tokens corresponding to a JSON value, > embed the parsing stack and state machine in JSONParser. This is more > efficient and allows for more prompt error recovery; it also does not > make the code substantially larger than the current recursive descent > parser, though the state machine is probably a bit harder to follow. > > The stack consists of QLists and QDicts corresponding to open > brackets and braces, plus optionally a QString with the current > key on top of each QDict. > > After each value is parsed, it is added to the top array or dictionary > or, if the stack is empty, json_parser_feed returns the complete > QObject. > > For now, json-streamer.c keeps tracking the tokens up until braces > and brackets are balanced, and then shoves the whole queue of tokens > into the push parser. The only logic change is that JSON_END_OF_INPUT > always triggers the emptying of the queue; the parser takes notice and > checks that there is nothing on the stack. Not using brace_count > and bracket_count for this is the first step towards improved separation > of concerns between json-parser.c and json-streamer.c. > > Signed-off-by: Paolo Bonzini <[email protected]>
[...] > diff --git a/qobject/json-parser-int.h b/qobject/json-parser-int.h > index 8c01f236276..1f435cb8eb2 100644 > --- a/qobject/json-parser-int.h > +++ b/qobject/json-parser-int.h > @@ -49,6 +49,9 @@ void json_message_process_token(JSONLexer *lexer, GString > *input, > > /* json-parser.c */ > JSONToken *json_token(JSONTokenType type, int x, int y, GString *tokstr); > -QObject *json_parser_parse(GQueue *tokens, va_list *ap, Error **errp); > +void json_parser_init(JSONParserContext *ctxt, va_list *ap); > +void json_parser_reset(JSONParserContext *ctxt); > +QObject *json_parser_feed(JSONParserContext *ctxt, const JSONToken *token, > Error **errp); checkpatch WARNING: line over 80 characters. It's just a warning, but the line is *really* easy to break. > +void json_parser_destroy(JSONParserContext *ctxt); > > #endif [...]
