From 9449cf68ccea85a662aa8d4438f26e1634dc285e Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Mon, 30 Jul 2018 06:23:00 +0000 Subject: Make top level wrapper value parsing work --- upb/json/parser.rl | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 81 insertions(+), 5 deletions(-) (limited to 'upb') diff --git a/upb/json/parser.rl b/upb/json/parser.rl index 9ceb2a5..f83af87 100644 --- a/upb/json/parser.rl +++ b/upb/json/parser.rl @@ -1316,6 +1316,10 @@ static bool does_number_wrapper_end(upb_json_parser *p) { return p->top->m != NULL && is_number_wrapper(p->top->m); } +static bool is_number_wrapper_object(upb_json_parser *p) { + return p->top->m != NULL && is_number_wrapper(p->top->m); +} + static bool does_string_wrapper_start(upb_json_parser *p) { return p->top->f != NULL && upb_fielddef_issubmsg(p->top->f) && @@ -1326,6 +1330,10 @@ static bool does_string_wrapper_end(upb_json_parser *p) { return p->top->m != NULL && is_string_wrapper(p->top->m); } +static bool is_string_wrapper_object(upb_json_parser *p) { + return p->top->m != NULL && is_string_wrapper(p->top->m); +} + static bool does_boolean_wrapper_start(upb_json_parser *p) { return p->top->f != NULL && upb_fielddef_issubmsg(p->top->f) && @@ -1336,6 +1344,10 @@ static bool does_boolean_wrapper_end(upb_json_parser *p) { return p->top->m != NULL && is_bool_value(p->top->m); } +static bool is_boolean_wrapper_object(upb_json_parser *p) { + return p->top->m != NULL && is_bool_value(p->top->m); +} + #define CHECK_RETURN_TOP(x) if (!(x)) goto error @@ -1366,10 +1378,10 @@ static bool does_boolean_wrapper_end(upb_json_parser *p) { exponent = /[eE]/ /[+\-]/? /[0-9]/+; number_machine := - ("-"? integer decimal? exponent?) - <: any - >{ fhold; fret; } - ; + ("-"? integer decimal? exponent?) + <: any + >{ fhold; fret; } + ; number = /[0-9\-]/ >{ fhold; fcall number_machine; }; text = @@ -1421,6 +1433,67 @@ static bool does_boolean_wrapper_end(upb_json_parser *p) { >{ end_object(parser); } ; + true_object = + "true" + >{ + CHECK_RETURN_TOP(is_boolean_wrapper_object(parser)); + start_wrapper_object(parser); + } + %{ + CHECK_RETURN_TOP(parser_putbool(parser, true)); + end_wrapper_object(parser); + } + ; + + false_object = + "false" + >{ + CHECK_RETURN_TOP(is_boolean_wrapper_object(parser)); + start_wrapper_object(parser); + } + %{ + CHECK_RETURN_TOP(parser_putbool(parser, false)); + end_wrapper_object(parser); + } + ; + + number_object_machine := + ("-"? integer decimal? exponent?) + >{ + CHECK_RETURN_TOP(is_number_wrapper_object(parser)); + start_wrapper_object(parser); + start_number(parser, p); + } + { + fhold; fcall number_object_machine; + } + ; + + string_object_machine := + (text | unicode_char | escape_char)** + >{ + CHECK_RETURN_TOP(is_string_wrapper_object(parser)); + start_wrapper_object(parser); + CHECK_RETURN_TOP(start_stringval(parser)); + } + '"' + { fhold; fret; } ; - main := ws object ws; + main := + ws + (object | number_object | true_object | false_object | string_object) + ws; }%% %% write data noerror nofinal; -- cgit v1.2.3