procedure Output_JSON_Message (Error_Id : Error_Msg_Id) is
+ function Is_Continuation (E : Error_Msg_Id) return Boolean;
+ -- Return True if E is a continuation message.
+
procedure Write_JSON_Escaped_String (Str : String_Ptr);
-- Write each character of Str, taking care of preceding each quote and
-- backslash with a backslash. Note that this escaping differs from what
-- Span.Last are different from Span.Ptr, they will be printed as JSON
-- locations under the names "start" and "finish".
+ -----------------------
+ -- Is_Continuation --
+ -----------------------
+
+ function Is_Continuation (E : Error_Msg_Id) return Boolean is
+ begin
+ return E <= Last_Error_Msg and then Errors.Table (E).Msg_Cont;
+ end Is_Continuation;
+
-------------------------------
-- Write_JSON_Escaped_String --
-------------------------------
E : Error_Msg_Id := Error_Id;
+ Print_Continuations : constant Boolean := not Is_Continuation (E);
+ -- Do not print continuations messages as children of the current
+ -- message if the current message is a continuation message.
+
-- Start of processing for Output_JSON_Message
begin
Write_Str ("],""message"":""");
Write_JSON_Escaped_String (Errors.Table (E).Text);
-
- -- Print message continuations if present
+ Write_Str ("""");
E := E + 1;
- while E <= Last_Error_Msg and then Errors.Table (E).Msg_Cont loop
- Write_Str (", ");
- Write_JSON_Escaped_String (Errors.Table (E).Text);
+ if Print_Continuations and then Is_Continuation (E) then
+
+ Write_Str (",""children"": [");
+ Output_JSON_Message (E);
E := E + 1;
- end loop;
- Write_Str ("""}");
+ while Is_Continuation (E) loop
+ Write_Str (", ");
+ Output_JSON_Message (E);
+ E := E + 1;
+ end loop;
+
+ Write_Str ("]");
+
+ end if;
+
+ Write_Str ("}");
end Output_JSON_Message;
---------------------