summaryrefslogtreecommitdiff
path: root/test/packrat-parsers-debug.adb
diff options
context:
space:
mode:
Diffstat (limited to 'test/packrat-parsers-debug.adb')
-rw-r--r--test/packrat-parsers-debug.adb122
1 files changed, 122 insertions, 0 deletions
diff --git a/test/packrat-parsers-debug.adb b/test/packrat-parsers-debug.adb
new file mode 100644
index 0000000..744166a
--- /dev/null
+++ b/test/packrat-parsers-debug.adb
@@ -0,0 +1,122 @@
+
+
+with
+
+ Ada.Characters.Latin_1,
+ Ada.Strings.Unbounded;
+
+
+package body Packrat.Parsers.Debug is
+
+
+ package Latin renames Ada.Characters.Latin_1;
+ package SU renames Ada.Strings.Unbounded;
+
+
+
+
+
+ function Parts
+ (This : in Combinator_Result)
+ return Result_Part_Array
+ is
+ Arr : Result_Part_Array (1 .. Integer (This.Results.Length));
+ Index : Positive := 1;
+ begin
+ for R of This.Results loop
+ Arr (Index) := Result_Part (R);
+ Index := Index + 1;
+ end loop;
+ return Arr;
+ end Parts;
+
+
+ function Curtails
+ (This : in Combinator_Result)
+ return Curtail_Map is
+ begin
+ return (This.Curtails with null record);
+ end Curtails;
+
+
+ function Status
+ (This : in Combinator_Result)
+ return Result_Status is
+ begin
+ return This.Status;
+ end Status;
+
+
+
+
+
+ function Finish
+ (Part : in Result_Part)
+ return Traits.Tokens.Finish_Type is
+ begin
+ return Part.Finish;
+ end Finish;
+
+ function Value
+ (Part : in Result_Part)
+ return Traits.Element_Array is
+ begin
+ if Part.Value.Is_Empty then
+ return Arr : Traits.Element_Array (1 .. 0);
+ else
+ return Part.Value.Element;
+ end if;
+ end Value;
+
+ function Tokens
+ (Part : in Result_Part)
+ return Traits.Tokens.Finished_Token_Array is
+ begin
+ if Part.Tokens.Is_Empty then
+ return Arr : Traits.Tokens.Finished_Token_Array (1 .. 0);
+ else
+ return Part.Tokens.Element;
+ end if;
+ end Tokens;
+
+
+
+
+
+ function Is_Empty
+ (Curt : in Curtail_Map)
+ return Boolean is
+ begin
+ return Packrat.Parsers.Curtail_Maps.Map (Curt).Is_Empty;
+ end Is_Empty;
+
+
+
+
+
+ function Debug_String
+ (This : in Combinator_Result)
+ return String
+ is
+ Str : SU.Unbounded_String;
+ Index : Integer := 1;
+ begin
+ for Part of Parts (This) loop
+ SU.Append (Str, "Part" & Integer'Image (Index) & ":" & Latin.LF);
+ SU.Append (Str, Latin.HT & "Fin:" &
+ Traits.Tokens.Finish_Type'Image (Finish (Part)) & Latin.LF);
+ SU.Append (Str, Latin.HT & "Val:" & Integer'Image (Value (Part)'Length) & Latin.LF);
+ SU.Append (Str, Latin.HT & "Tok:" & Latin.LF);
+ for Tok of Tokens (Part) loop
+ SU.Append (Str, Latin.HT & Latin.HT & Traits.Tokens.Debug_String (Tok) & Latin.LF);
+ end loop;
+ Index := Index + 1;
+ end loop;
+ SU.Append (Str, Latin.HT & "Status: " & Result_Status'Image (Status (This)) & Latin.LF);
+ return -Str;
+ end Debug_String;
+
+
+end Packrat.Parsers.Debug;
+
+