On Tue, Feb 10, 2026 at 2:06 PM Markus Armbruster <[email protected]> wrote:
>
> Paolo Bonzini <[email protected]> writes:
> >                                                                     Still
> > the difference in error reporting matters, because it gives feedback that
> > is immediately useful, rather than possibly delayed forever.
>
> Reporting parse errors immediately is such a lovely quality of life
> improvement.  May I have that without regressing error recovery?

If it is a regression, of course.

Especially the one for ^L, which needs a testcase. Something like this
should do:

diff --git a/qobject/json-streamer.c b/qobject/json-streamer.c
index f6380684897..287a345b49a 100644
--- a/qobject/json-streamer.c
+++ b/qobject/json-streamer.c
@@ -35,17 +35,25 @@
         parser->brace_count++;
         break;
     case JSON_RCURLY:
-        if (parser->brace_count > 0) {
-            parser->brace_count--;
+        if (parser->brace_count <= 0) {
+            goto end_error_recovery;
         }
+        parser->brace_count--;
         break;
     case JSON_LSQUARE:
         parser->bracket_count++;
         break;
     case JSON_RSQUARE:
-        if (parser->bracket_count > 0) {
-            parser->bracket_count--;
+        if (parser->bracket_count <= 0) {
+            goto end_error_recovery;
         }
+        parser->bracket_count--;
+        break;
+    case JSON_ERROR:
+    end_error_recovery:
+        parser->brace_count = 0;
+        parser->bracket_count = 0;
         break;
     default:
         break;

Thanks,

Paolo


Reply via email to