summaryrefslogtreecommitdiff
path: root/src/packrat-parsers.adb
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2021-01-13 18:31:27 +1100
committerJed Barber <jjbarber@y7mail.com>2021-01-13 18:31:27 +1100
commit3fa431a2268a11dec6fd82c8f9b59cc2d0af9a93 (patch)
tree509228a90b6fba0daf7d9fb2598132fe64d361fa /src/packrat-parsers.adb
parent703a09c135d04b37be34d95915c32d70d730894c (diff)
Stamp/Ignore now Stamp/Discard/Ignore
Diffstat (limited to 'src/packrat-parsers.adb')
-rw-r--r--src/packrat-parsers.adb40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/packrat-parsers.adb b/src/packrat-parsers.adb
index e4fa97d..0ddd864 100644
--- a/src/packrat-parsers.adb
+++ b/src/packrat-parsers.adb
@@ -622,6 +622,46 @@ package body Packrat.Parsers is
end Stamp;
+ function Discard
+ (Input : in Traits.Element_Array;
+ Context : in out Parser_Context;
+ Start : in Positive)
+ return Combinator_Result
+ is
+ function Actual
+ (Context : in out Parser_Context)
+ return Combinator_Result
+ is
+ Salt : Combinator_Result := Combo (Input, Context, Start);
+ Processed : Result_Sets.Set;
+ begin
+ if Salt.Status = Failure then
+ declare
+ Error : String := Packrat.Errors.Encode
+ (Traits.Label_Enum'Image (Label), Start);
+ begin
+ if Ada.Strings.Unbounded.Index (Context.Error_String, Error) = 0 then
+ Ada.Strings.Unbounded.Append (Context.Error_String, Error);
+ end if;
+ end;
+ return Salt;
+ end if;
+ for R of Salt.Results loop
+ Processed.Include
+ ((Finish => R.Finish,
+ Value => Elem_Holds.Empty_Holder,
+ Tokens => Tok_Holds.Empty_Holder));
+ end loop;
+ Salt.Results := Processed;
+ return Salt;
+ end Actual;
+ function Memo is new Memoize (To_Key (Start, Discard'Access), Actual);
+ function Curt is new Curtailment (To_Key (Start, Discard'Access), Input, Memo);
+ begin
+ return Curt (Context);
+ end Discard;
+
+
function Ignore
(Input : in Traits.Element_Array;
Context : in out Parser_Context;