summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2020-11-12 19:21:01 +1100
committerJed Barber <jjbarber@y7mail.com>2020-11-12 19:21:01 +1100
commit2e075ca317211553a19d7c8706a9d66fabcc9d8d (patch)
tree91152873ed72be772c94a772924c4794d9764cea
parent84696069475bfa7732326dee94a2c8a852ece827 (diff)
Parse_Graph debug strings fixed
-rw-r--r--src/packrat-parse_graphs.adb75
-rw-r--r--src/packrat-parse_graphs.ads3
-rw-r--r--test/rat_tests-parse_graphs.adb2
3 files changed, 56 insertions, 24 deletions
diff --git a/src/packrat-parse_graphs.adb b/src/packrat-parse_graphs.adb
index eed2eee..b0e5554 100644
--- a/src/packrat-parse_graphs.adb
+++ b/src/packrat-parse_graphs.adb
@@ -2,7 +2,7 @@
with
- -- Ada.Strings.Fixed,
+ Ada.Strings.Fixed,
Ada.Characters.Latin_1;
@@ -210,46 +210,74 @@ package body Packrat.Parse_Graphs is
function Debug_String
- (Container : in Parse_Graph)
+ (Container : in Parse_Graph;
+ Cutoff : in Positive := 4)
return String
is
- Mapping : Enum_Node_Maps.Map;
+ function Generate_Map
+ (Container : in Parse_Graph)
+ return Enum_Node_Maps.Map
+ is
+ Result : Enum_Node_Maps.Map;
+ Current : Label_Enum;
+ begin
+ for Node of Container.Internal_Graph.Nodes loop
+ Current := Gen_Tokens.Label (Container.Internal_Graph.Label (Node));
+ if not Result.Contains (Current) then
+ Result.Insert (Current, Node_Vectors.Empty_Vector);
+ end if;
+ Result.Reference (Current).Append (Node);
+ end loop;
+ return Result;
+ end Generate_Map;
+
+ function Image
+ (Input : in Label_Enum)
+ return String
+ is
+ Raw : String := Label_Enum'Image (Input);
+ begin
+ if Raw'Length <= Cutoff then
+ return Raw;
+ else
+ return Ada.Strings.Fixed.Head (Raw, Cutoff);
+ end if;
+ end Image;
+
+ function Image
+ (Input : in Integer)
+ return String is
+ begin
+ return Ada.Strings.Fixed.Trim (Integer'Image (Input), Ada.Strings.Left);
+ end Image;
+
+ Mapping : Enum_Node_Maps.Map := Generate_Map (Container);
Current : Gen_Tokens.Token;
Result : SU.Unbounded_String;
begin
- for Node of Container.Internal_Graph.Nodes loop
- declare
- Current : Label_Enum :=
- Gen_Tokens.Label (Container.Internal_Graph.Label (Node));
- begin
- if not Mapping.Contains (Current) then
- Mapping.Insert (Current, Node_Vectors.Empty_Vector);
- end if;
- Mapping.Reference (Current).Append (Node);
- end;
- end loop;
for Iter in Mapping.Iterate loop
- SU.Append (Result, Label_Enum'Image (Enum_Node_Maps.Key (Iter)) & Latin.HT);
+ SU.Append (Result, Image (Enum_Node_Maps.Key (Iter)) & Latin.HT);
for Node of Enum_Node_Maps.Element (Iter) loop
Current := Container.Internal_Graph.Label (Node);
- SU.Append (Result, Positive'Image (Gen_Tokens.Start (Current)) & " ->" & Latin.HT);
+ SU.Append (Result, Image (Gen_Tokens.Start (Current)) & " ->" & Latin.HT);
for Fin of In_Finishes (Container, Node) loop
- SU.Append (Result, Finish_Type'Image (Fin) & " ->" & Latin.HT);
+ SU.Append (Result, Image (Fin) & " ->" & Latin.HT);
declare
Groupings : Token_Group_Array := Container.Subgroups ((Current, Fin));
begin
if Groupings'Length = 0 then
- SU.Append (Result, "Leaf");
+ SU.Append (Result, "Leaf" & Latin.LF);
+ SU.Append (Result, SU."*" (3, Latin.HT));
else
for Grouping of Groupings loop
for Fin_Token of Elements (Grouping) loop
SU.Append (Result, "Subnode " &
- Label_Enum'Image (Gen_Tokens.Label (Fin_Token.Token)) &
- " (" & Positive'Image (Gen_Tokens.Start (Fin_Token.Token)) &
- "," & Finish_Type'Image (Fin_Token.Finish) & "), ");
+ Image (Gen_Tokens.Label (Fin_Token.Token)) &
+ " (" & Image (Gen_Tokens.Start (Fin_Token.Token)) &
+ "," & Image (Fin_Token.Finish) & "), ");
end loop;
SU.Delete (Result, SU.Length (Result) - 1, SU.Length (Result));
- SU.Append (Result, Latin.HT);
+ SU.Append (Result, Latin.LF);
SU.Append (Result, SU."*" (3, Latin.HT));
end loop;
end if;
@@ -258,9 +286,10 @@ package body Packrat.Parse_Graphs is
end loop;
SU.Delete (Result, SU.Length (Result), SU.Length (Result));
end loop;
- -- what delete goes here?
+ SU.Delete (Result, SU.Length (Result), SU.Length (Result));
SU.Append (Result, Latin.LF);
end loop;
+ SU.Delete (Result, SU.Length (Result) - 1, SU.Length (Result));
return SU.To_String (Result);
end Debug_String;
diff --git a/src/packrat-parse_graphs.ads b/src/packrat-parse_graphs.ads
index de5e4e9..291a467 100644
--- a/src/packrat-parse_graphs.ads
+++ b/src/packrat-parse_graphs.ads
@@ -104,7 +104,8 @@ package Packrat.Parse_Graphs is
function Debug_String
- (Container : in Parse_Graph)
+ (Container : in Parse_Graph;
+ Cutoff : in Positive := 4)
return String;
diff --git a/test/rat_tests-parse_graphs.adb b/test/rat_tests-parse_graphs.adb
index 701fbfc..e445f1b 100644
--- a/test/rat_tests-parse_graphs.adb
+++ b/test/rat_tests-parse_graphs.adb
@@ -476,6 +476,8 @@ begin
Paper_Graph.Connect ((Sen_1, 11),
((Sen_1, 8), (PP_8, 11)));
+ Paper_Graph.Set_Root (Sen_1, (5, 8, 11));
+
end Rat_Tests.Parse_Graphs;