Index: src/natools-s_expressions.adb ================================================================== --- src/natools-s_expressions.adb +++ src/natools-s_expressions.adb @@ -48,6 +48,35 @@ pragma Unreferenced (Discarded); begin Next (Object, Discarded); end Next; + + procedure Close_Current_List (Object : in out Descriptor'Class) is + Level : Natural := 0; + Event : Events.Event := Object.Current_Event; + begin + if Object.Current_Event in Events.Error | Events.End_Of_Input then + return; + end if; + + loop + Object.Next (Event); + + case Event is + when Events.Error | Events.End_Of_Input => + exit; + + when Events.Open_List => + Level := Level + 1; + + when Events.Close_List => + exit when Level = 0; + Level := Level - 1; + + when Events.Add_Atom => + null; + end case; + end loop; + end Close_Current_List; + end Natools.S_Expressions; Index: src/natools-s_expressions.ads ================================================================== --- src/natools-s_expressions.ads +++ src/natools-s_expressions.ads @@ -113,14 +113,21 @@ Event : out Events.Event) is abstract; -- Update Object to reflect the next event in the S-expression procedure Next (Object : in out Descriptor'Class); -- Call Next discarding current event + + procedure Close_Current_List (Object : in out Descriptor'Class); + -- Repeatedly call Next until reaching end-of-input or the Close_List + -- event matching the current list. + -- Note: if current event is Open_List, then this is the designated list + -- while for other events, including Close_List, the designated list + -- contains the current object or the just-closed list. private use type Ada.Streams.Stream_Element; use type Ada.Streams.Stream_Element_Offset; use type Ada.Streams.Stream_Element_Array; use type Events.Event; end Natools.S_Expressions;