From d5df1b33144f92b6070e957db293e36b27e14439 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Tue, 1 Dec 2020 16:04:17 +1100 Subject: Curtailing parser combinators implemented --- src/packrat-parsers.ads | 99 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 86 insertions(+), 13 deletions(-) (limited to 'src/packrat-parsers.ads') diff --git a/src/packrat-parsers.ads b/src/packrat-parsers.ads index 55cb12a..a5716f2 100644 --- a/src/packrat-parsers.ads +++ b/src/packrat-parsers.ads @@ -205,6 +205,18 @@ package Packrat.Parsers is Start : in Positive) return Combinator_Result; + generic + with function Param + (Input : in Traits.Element_Array; + Context : in out Parser_Context; + Start : in Positive) + return Combinator_Result; + function Optional + (Input : in Traits.Element_Array; + Context : in out Parser_Context; + Start : in Positive) + return Combinator_Result; + @@ -295,6 +307,18 @@ package Packrat.Parsers is Start : in Positive) return Combinator_Result; + generic + with function Combo + (Input : in Traits.Element_Array; + Context : in out Parser_Context; + Start : in Positive) + return Combinator_Result; + function Not_Empty + (Input : in Traits.Element_Array; + Context : in out Parser_Context; + Start : in Positive) + return Combinator_Result; + private @@ -358,9 +382,9 @@ private type Combo_Result_Part is record - Finish : Natural; - Value : Elem_Holds.Holder; - Tokens : Tok_Holds.Holder; + Finish : Natural := 0; + Value : Elem_Holds.Holder := Elem_Holds.Empty_Holder; + Tokens : Tok_Holds.Holder := Tok_Holds.Empty_Holder; end record; function "<" @@ -386,10 +410,19 @@ private -- If there's anything in the Curtails, then Results should be empty -- and vice versa... union? + + -- need to add an error string to percolate upwards for exceptions + + -- need to add a record of the total length of input available when + -- result was computed, to allow for knowing when to recompute + -- optional_more/need_more results + + -- actually no, just not putting optional/needmore results in the + -- memotable will work fine, but how to figure out how much to pass forward? type Combinator_Result is record - Results : Result_Sets.Set; - Curtails : Curtail_Maps.Map; - Status : Result_Status; + Results : Result_Sets.Set := Result_Sets.Empty_Set; + Curtails : Curtail_Maps.Map := Curtail_Maps.Empty_Map; + Status : Result_Status := Failure; end record; type Component_Result is record @@ -458,17 +491,17 @@ private procedure Inc_Leftrec - (Key : in Combo_Key; - Context : in out Parser_Context); + (Key : in Combo_Key; + Leftrecs : in out Leftrectables.Map); procedure Dec_Leftrec - (Key : in Combo_Key; - Context : in out Parser_Context); + (Key : in Combo_Key; + Leftrecs : in out Leftrectables.Map); function Exceeds_Curtail - (Key : in Combo_Key; - Context : in Parser_Context; - Input : in Traits.Element_Array) + (Key : in Combo_Key; + Leftrecs : in Leftrectables.Map; + Input : in Traits.Element_Array) return Boolean; generic @@ -482,6 +515,46 @@ private return Combinator_Result; + + + procedure Merge + (Target : in out Curtail_Maps.Map; + Add : in Curtail_Maps.Map); + + function Merge + (Left, Right : in Curtail_Maps.Map) + return Curtail_Maps.Map; + + -- Should only be used to merge results obtained from + -- the same input location. + procedure Merge + (Target : in out Combinator_Result; + Add : in Combinator_Result); + + function Merge + (Left, Right : in Combinator_Result) + return Combinator_Result; + + generic + with function Next + (Input : in Traits.Element_Array; + Context : in out Parser_Context; + Start : in Positive) + return Combinator_Result; + function Continue + (From : in Combinator_Result; + Input : in Traits.Element_Array; + Context : in out Parser_Context) + return Combinator_Result; + + + + + procedure Complete_Status + (Result : in out Combinator_Result; + Allow : in Boolean); + + end Packrat.Parsers; -- cgit