From 8834bc154280e443aeac618eb433e365d82253c6 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Sat, 12 Dec 2020 17:12:21 +1100 Subject: Duplicate subgroup bug fixed, finally --- src/packrat-parse_graphs.adb | 30 +++++++++++++++++++++++------- src/packrat-parse_graphs.ads | 6 ++++++ src/packrat-parsers.adb | 1 + 3 files changed, 30 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/packrat-parse_graphs.adb b/src/packrat-parse_graphs.adb index 434c0a0..49ca752 100644 --- a/src/packrat-parse_graphs.adb +++ b/src/packrat-parse_graphs.adb @@ -288,21 +288,34 @@ package body Packrat.Parse_Graphs is function Contains (Container : in Parse_Graph; Grouping : in Token_Group) + return Boolean is + begin + return Container.Contains (Grouping.Parent, Elements (Grouping)); + end Contains; + + + function Contains + (Container : in Parse_Graph; + Parent : in Traits.Tokens.Finished_Token_Type; + Subtokens : in Traits.Tokens.Finished_Token_Array) return Boolean is Groups : Group_ID_Vectors.Vector; Next_ID : Group_ID_Type; Parent_Node : Node_ID_Type; begin - if not Container.Contains (Grouping.Parent) then + if not Container.Contains (Parent.Token) then return False; end if; - for Fin_Token of Elements (Grouping) loop - if not Container.Contains (Fin_Token) then + for Fin_Token of Subtokens loop + if not Container.Contains (Fin_Token.Token) then return False; end if; end loop; - Parent_Node := Container.Label_Map.Element (Grouping.Parent.Token); + if not Valid_Starts_Finishes (Parent, Subtokens) then + return False; + end if; + Parent_Node := Container.Label_Map.Element (Parent.Token); for Edge of Container.Internal_Graph.Outbound (Parent_Node) loop Next_ID := Container.Internal_Graph.Label (Edge).Group_ID; if not Groups.Contains (Next_ID) then @@ -310,12 +323,12 @@ package body Packrat.Parse_Graphs is end if; end loop; return (for some ID of Groups => - (for all Sub of Elements (Grouping) => + (for all Sub of Subtokens => (for some Edge of Container.Internal_Graph.Between (Parent_Node, Container.Label_Map.Element (Sub.Token)) => Container.Internal_Graph.Label (Edge) = - (Group_ID => ID, - Group_Finish => Finish (Grouping), + (Group_ID => ID, + Group_Finish => Parent.Finish, Subnode_Finish => Sub.Finish)))); end Contains; @@ -540,6 +553,9 @@ package body Packrat.Parse_Graphs is New_Edge : Base.Edge_Type; New_Label : Edge_Label_Type; begin + if Container.Contains (Parent, Subtokens) then + return; + end if; Container.Include (Parent.Token); for Sub of Subtokens loop Container.Include (Sub.Token); diff --git a/src/packrat-parse_graphs.ads b/src/packrat-parse_graphs.ads index 7d14652..e13bfc7 100644 --- a/src/packrat-parse_graphs.ads +++ b/src/packrat-parse_graphs.ads @@ -83,6 +83,12 @@ package Packrat.Parse_Graphs is Grouping : in Token_Group) return Boolean; + function Contains + (Container : in Parse_Graph; + Parent : in Traits.Tokens.Finished_Token_Type; + Subtokens : in Traits.Tokens.Finished_Token_Array) + return Boolean; + function Reachable (Container : in Parse_Graph; Position : in Traits.Tokens.Finished_Token_Type) diff --git a/src/packrat-parsers.adb b/src/packrat-parsers.adb index 63dcb00..eba9e20 100644 --- a/src/packrat-parsers.adb +++ b/src/packrat-parsers.adb @@ -563,6 +563,7 @@ package body Packrat.Parsers is Ada.Strings.Unbounded.Append (Context.Error_String, Packrat.Errors.Encode (Traits.Label_Enum'Image (Label), Start)); + return Salt; else Context.Error_String := +""; end if; -- cgit