summaryrefslogtreecommitdiff
path: root/src/packrat-parsers.ads
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2020-11-29 21:10:36 +1100
committerJed Barber <jjbarber@y7mail.com>2020-11-29 21:10:36 +1100
commit4c4a3b44a93c526aab44f1d1b3100e347b233acb (patch)
treecb5be5d34a07abe03e0261a6f0098f67226daa58 /src/packrat-parsers.ads
parent81c4526fa275a256bfefe0f8a7cd638369ea1252 (diff)
Non-curtailing parser combinators implemented
Diffstat (limited to 'src/packrat-parsers.ads')
-rw-r--r--src/packrat-parsers.ads89
1 files changed, 70 insertions, 19 deletions
diff --git a/src/packrat-parsers.ads b/src/packrat-parsers.ads
index 8a0f39c..55cb12a 100644
--- a/src/packrat-parsers.ads
+++ b/src/packrat-parsers.ads
@@ -289,17 +289,7 @@ package Packrat.Parsers is
- generic
- EOL_Item : in Traits.Element_Type;
- function Line_End
- (Input : in Traits.Element_Array;
- Context : in out Parser_Context;
- Start : in Positive)
- return Combinator_Result;
-
- generic
- EOF_Item : in Traits.Element_Type;
- function Input_End
+ function Empty
(Input : in Traits.Element_Array;
Context : in out Parser_Context;
Start : in Positive)
@@ -325,20 +315,20 @@ private
-- for a given combinator/position
- package Elem_Array_Holders is new Ada.Containers.Indefinite_Holders
+ package Elem_Holds is new Ada.Containers.Indefinite_Holders
(Element_Type => Traits.Element_Array,
"=" => Traits."=");
- package Token_Array_Holders is new Ada.Containers.Indefinite_Holders
+ package Tok_Holds is new Ada.Containers.Indefinite_Holders
(Element_Type => Traits.Tokens.Token_Array,
"=" => Traits.Tokens."=");
function "<"
- (Left, Right : in Elem_Array_Holders.Holder)
+ (Left, Right : in Elem_Holds.Holder)
return Boolean;
function "<"
- (Left, Right : in Token_Array_Holders.Holder)
+ (Left, Right : in Tok_Holds.Holder)
return Boolean;
@@ -353,13 +343,24 @@ private
(Left, Right : in Combo_Key)
return Boolean;
+ -- This is needed to avoid some issues with using non-anonymous
+ -- access values in a generic subprogram instantiation.
+ function To_Key
+ (Start : in Positive;
+ Func : access function
+ (Input : in Traits.Element_Array;
+ Context : in out Parser_Context;
+ Start : in Positive)
+ return Combinator_Result)
+ return Combo_Key;
+
type Combo_Result_Part is record
Finish : Natural;
- Value : Elem_Array_Holders.Holder;
- Tokens : Token_Array_Holders.Holder;
+ Value : Elem_Holds.Holder;
+ Tokens : Tok_Holds.Holder;
end record;
function "<"
@@ -395,6 +396,11 @@ private
Status : Result_Status;
end record;
+ Empty_Fail : constant Combinator_Result :=
+ (Results => Result_Sets.Empty_Set,
+ Curtails => Curtail_Maps.Empty_Map,
+ Status => Failure);
+
@@ -414,7 +420,7 @@ private
Position : Positive := 1;
Offset : Natural := 0;
Status : Result_Status := Success;
- Pass_Forward : Elem_Array_Holders.Holder;
+ Pass_Forward : Elem_Holds.Holder;
Memotable : Memotables.Map;
Leftrectable : Leftrectables.Map;
Allow_Incomplete : Boolean := True;
@@ -425,12 +431,57 @@ private
Position => 1,
Offset => 0,
Status => Success,
- Pass_Forward => Elem_Array_Holders.Empty_Holder,
+ Pass_Forward => Elem_Holds.Empty_Holder,
Memotable => Memotables.Empty_Map,
Leftrectable => Leftrectables.Empty_Map,
Allow_Incomplete => True);
+
+
+ function Reusable
+ (Result : in Combinator_Result;
+ Position : in Positive;
+ Leftrecs : in Leftrectables.Map)
+ return Boolean;
+
+ generic
+ My_Key : in Combo_Key;
+ with function Actual
+ (Context : in out Parser_Context)
+ return Combinator_Result;
+ function Memoize
+ (Context : in out Parser_Context)
+ return Combinator_Result;
+
+
+
+
+ procedure Inc_Leftrec
+ (Key : in Combo_Key;
+ Context : in out Parser_Context);
+
+ procedure Dec_Leftrec
+ (Key : in Combo_Key;
+ Context : in out Parser_Context);
+
+ function Exceeds_Curtail
+ (Key : in Combo_Key;
+ Context : in Parser_Context;
+ Input : in Traits.Element_Array)
+ return Boolean;
+
+ generic
+ My_Key : in Combo_Key;
+ Input : in Traits.Element_Array;
+ with function Actual
+ (Context : in out Parser_Context)
+ return Combinator_Result;
+ function Curtailment
+ (Context : in out Parser_Context)
+ return Combinator_Result;
+
+
end Packrat.Parsers;