summaryrefslogtreecommitdiff
path: root/src/kompsos-pretty_print.adb
diff options
context:
space:
mode:
Diffstat (limited to 'src/kompsos-pretty_print.adb')
-rw-r--r--src/kompsos-pretty_print.adb142
1 files changed, 142 insertions, 0 deletions
diff --git a/src/kompsos-pretty_print.adb b/src/kompsos-pretty_print.adb
new file mode 100644
index 0000000..d1d89b8
--- /dev/null
+++ b/src/kompsos-pretty_print.adb
@@ -0,0 +1,142 @@
+
+
+-- 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);
+ 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 World)
+ return String
+ is
+ Result : SU.Unbounded_String;
+ begin
+ if Item.Possibles.Is_Empty then
+ return "States: N/A" & Latin.LF;
+ end if;
+ for Index in Integer range Item.Possibles.First_Index .. Item.Possibles.Last_Index loop
+ SU.Append (Result, "State#" & Image (Index) & ":" & Latin.LF);
+ SU.Append (Result, Image (Item.Possibles.Constant_Reference (Index)));
+ end loop;
+ return SU.Slice (Result, 1, SU.Length (Result) - 1);
+ end Image;
+
+
+end Kompsos.Pretty_Print;
+
+