@@ -123,34 +123,27 @@ WARN_UNUSED really_inline error_code structural_parser::parse(T &builder) noexce
123123 {
124124 const uint8_t *value = advance ();
125125 switch (*value) {
126- case ' {' : {
127- if (empty_object (builder)) { goto document_end; }
128- SIMDJSON_TRY ( start_object (builder) );
129- goto object_begin;
130- }
131- case ' [' : {
132- if (empty_array (builder)) { goto document_end; }
133- SIMDJSON_TRY ( start_array (builder) );
134- // Make sure the outer array is closed before continuing; otherwise, there are ways we could get
135- // into memory corruption. See https://github.com/simdjson/simdjson/issues/906
136- if (!STREAMING) {
137- if (buf[dom_parser.structural_indexes [dom_parser.n_structural_indexes - 1 ]] != ' ]' ) {
138- return TAPE_ERROR;
126+ case ' {' : {
127+ if (empty_object (builder)) { goto document_end; }
128+ SIMDJSON_TRY ( start_object (builder) );
129+ goto object_begin;
130+ }
131+ case ' [' : {
132+ if (empty_array (builder)) { goto document_end; }
133+ SIMDJSON_TRY ( start_array (builder) );
134+ // Make sure the outer array is closed before continuing; otherwise, there are ways we could get
135+ // into memory corruption. See https://github.com/simdjson/simdjson/issues/906
136+ if (!STREAMING) {
137+ if (buf[dom_parser.structural_indexes [dom_parser.n_structural_indexes - 1 ]] != ' ]' ) {
138+ return TAPE_ERROR;
139+ }
139140 }
141+ goto array_begin;
142+ }
143+ default : {
144+ SIMDJSON_TRY ( builder.parse_root_primitive (*this , value) );
145+ goto document_end;
140146 }
141- goto array_begin;
142- }
143- case ' "' : SIMDJSON_TRY ( builder.parse_string (*this , value) ); goto document_end;
144- case ' t' : SIMDJSON_TRY ( builder.parse_root_true_atom (*this , value) ); goto document_end;
145- case ' f' : SIMDJSON_TRY ( builder.parse_root_false_atom (*this , value) ); goto document_end;
146- case ' n' : SIMDJSON_TRY ( builder.parse_root_null_atom (*this , value) ); goto document_end;
147- case ' -' :
148- case ' 0' : case ' 1' : case ' 2' : case ' 3' : case ' 4' :
149- case ' 5' : case ' 6' : case ' 7' : case ' 8' : case ' 9' :
150- SIMDJSON_TRY ( builder.parse_root_number (*this , value) ); goto document_end;
151- default :
152- log_error (" Document starts with a non-value character" );
153- return TAPE_ERROR;
154147 }
155148 }
156149
@@ -182,17 +175,9 @@ object_field: {
182175 SIMDJSON_TRY ( start_array (builder) );
183176 goto array_begin;
184177 }
185- case ' "' : SIMDJSON_TRY ( builder.parse_string (*this , value) ); break ;
186- case ' t' : SIMDJSON_TRY ( builder.parse_true_atom (*this , value) ); break ;
187- case ' f' : SIMDJSON_TRY ( builder.parse_false_atom (*this , value) ); break ;
188- case ' n' : SIMDJSON_TRY ( builder.parse_null_atom (*this , value) ); break ;
189- case ' -' :
190- case ' 0' : case ' 1' : case ' 2' : case ' 3' : case ' 4' :
191- case ' 5' : case ' 6' : case ' 7' : case ' 8' : case ' 9' :
192- SIMDJSON_TRY ( builder.parse_number (*this , value) ); break ;
193- default :
194- log_error (" Non-value found when value was expected!" );
195- return TAPE_ERROR;
178+ default : {
179+ SIMDJSON_TRY ( builder.parse_primitive (*this , value) );
180+ }
196181 }
197182} // object_field:
198183
@@ -241,17 +226,9 @@ array_value: {
241226 SIMDJSON_TRY ( start_array (builder) );
242227 goto array_begin;
243228 }
244- case ' "' : SIMDJSON_TRY ( builder.parse_string (*this , value) ); break ;
245- case ' t' : SIMDJSON_TRY ( builder.parse_true_atom (*this , value) ); break ;
246- case ' f' : SIMDJSON_TRY ( builder.parse_false_atom (*this , value) ); break ;
247- case ' n' : SIMDJSON_TRY ( builder.parse_null_atom (*this , value) ); break ;
248- case ' -' :
249- case ' 0' : case ' 1' : case ' 2' : case ' 3' : case ' 4' :
250- case ' 5' : case ' 6' : case ' 7' : case ' 8' : case ' 9' :
251- SIMDJSON_TRY ( builder.parse_number (*this , value) ); break ;
252- default :
253- log_error (" Non-value found when value was expected!" );
254- return TAPE_ERROR;
229+ default : {
230+ SIMDJSON_TRY ( builder.parse_primitive (*this , value) );
231+ }
255232 }
256233} // array_value:
257234
0 commit comments