From 393870127fe767a0359182ccf80ee9fb48573f97 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Thu, 3 Dec 2020 15:48:43 +1100 Subject: Main parse functions implemented --- src/packrat-parsers.ads | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'src/packrat-parsers.ads') diff --git a/src/packrat-parsers.ads b/src/packrat-parsers.ads index 7ed2c89..6568238 100644 --- a/src/packrat-parsers.ads +++ b/src/packrat-parsers.ads @@ -7,6 +7,7 @@ with private with + Ada.Containers.Vectors, Ada.Containers.Ordered_Maps, Ada.Containers.Ordered_Sets, Ada.Containers.Indefinite_Holders; @@ -133,6 +134,7 @@ package Packrat.Parsers is return Combinator_Result; generic + Label : in Traits.Label_Enum; with function Combo (Input : in Traits.Element_Array; Context : in out Parser_Context; @@ -367,6 +369,10 @@ private (Left, Right : in Combo_Key) return Boolean; + package Combo_Key_Vectors is new Ada.Containers.Vectors + (Index_Type => Positive, + Element_Type => Combo_Key); + -- This is needed to avoid some issues with using non-anonymous -- access values in a generic subprogram instantiation. function To_Key @@ -411,8 +417,6 @@ 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 @@ -437,6 +441,9 @@ private + package Needs_Sets is new Ada.Containers.Ordered_Sets + (Element_Type => Positive); + package Memotables is new Ada.Containers.Ordered_Maps (Key_Type => Combo_Key, Element_Type => Combinator_Result); @@ -450,9 +457,10 @@ private type Parser_Context is record Result_So_Far : Graphs.Parse_Graph; - Position : Positive := 1; - Offset : Natural := 0; - Status : Result_Status := Success; + Used_Before : Boolean := False; + Global_Start : Positive := 1; + Current_Position : Positive := 1; + Needs_More : Needs_Sets.Set; Pass_Forward : Elem_Holds.Holder; Memotable : Memotables.Map; Leftrectable : Leftrectables.Map; @@ -461,9 +469,10 @@ private Empty_Context : constant Parser_Context := (Result_So_Far => Graphs.Empty_Graph, - Position => 1, - Offset => 0, - Status => Success, + Used_Before => False, + Global_Start => 1, + Current_Position => 1, + Needs_More => Needs_Sets.Empty_Set, Pass_Forward => Elem_Holds.Empty_Holder, Memotable => Memotables.Empty_Map, Leftrectable => Leftrectables.Empty_Map, @@ -555,6 +564,14 @@ private Allow : in Boolean); + + + function Slide + (Input : in Traits.Element_Array; + Position : in Positive) + return Traits.Element_Array; + + end Packrat.Parsers; -- cgit