-- Programmed by Jedidiah Barber -- Licensed under the Sunset License v1.0 -- See license.txt for further details with Ada.Characters.Latin_1, Ada.Strings.Fixed; package body Kompsos.Pretty_Print is package Latin renames Ada.Characters.Latin_1; package Str renames Ada.Strings; function Image (Item : in Integer) return String is begin return Str.Fixed.Trim (Integer'Image (Item), Str.Left); end Image; function Image (Item : in ID_Number) return String is begin return Str.Fixed.Trim (ID_Number'Image (Item), Str.Left); end Image; function Image (Item : in Variable) return String is begin return "Var#" & Image (Item.Ident) & (if SU.Length (Item.Name) /= 0 then "/" & SU.To_String (Item.Name) else ""); end Image; function Image (Item : in Term) return String is function Bare (Item : in Term) return String is begin case Item.Actual.Kind is when Atom_Term => return Element_Image (Item.Actual.Value); when Var_Term => return Image (Item.Actual.Refer); when Pair_Term => if Item.Actual.Right.Actual = null then return Image (Item.Actual.Left); elsif Item.Actual.Right.Actual.Kind /= Pair_Term then return Image (Item.Actual.Left) & " . " & Bare (Item.Actual.Right); else return Image (Item.Actual.Left) & " " & Bare (Item.Actual.Right); end if; end case; end Bare; begin if Item.Actual = null then return "()"; elsif Item.Actual.Kind = Pair_Term then return "(" & Bare (Item) & ")"; else return Bare (Item); end if; end Image; function Image (Item : in State) return String is Result : SU.Unbounded_String; My_Var : Variable; begin SU.Append (Result, Latin.HT & "Variables:"); if Item.LVars.Is_Empty then SU.Append (Result, " N/A" & Latin.LF); else SU.Append (Result, Latin.LF); for Iter in Item.LVars.Iterate loop My_Var := (Ident => Name_Maps.Key (Iter), Name => Name_Maps.Element (Iter)); SU.Append (Result, Latin.HT & Latin.HT & Image (My_Var) & Latin.LF); end loop; end if; SU.Append (Result, Latin.HT & "Substitution:"); if Item.Subst.Is_Empty then SU.Append (Result, " N/A" & Latin.LF); else SU.Append (Result, Latin.LF); for Iter in Item.Subst.Iterate loop SU.Append (Result, Latin.HT & Latin.HT & Image (Binding_Maps.Key (Iter)) & " => " & Image (Binding_Maps.Element (Iter)) & Latin.LF); end loop; end if; return -Result; end Image; function Image (Item : in Mu_World'Class) return String is Result : SU.Unbounded_String; Scratch : Mu_World'Class := Item; Counter : Positive := 1; begin if not Scratch.Has_State (Counter) then return "States: N/A" & Latin.LF; end if; loop SU.Append (Result, "State#" & Image (Counter) & ":" & Latin.LF); SU.Append (Result, Image (Scratch.Possibles.Constant_Reference (Counter))); Counter := Counter + 1; exit when not Scratch.Has_State (Counter); end loop; return SU.Slice (Result, 1, SU.Length (Result) - 1); end Image; end Kompsos.Pretty_Print;