summaryrefslogtreecommitdiff
path: root/src
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
parent703a09c135d04b37be34d95915c32d70d730894c (diff)
Stamp/Ignore now Stamp/Discard/Ignore
Diffstat (limited to 'src')
-rw-r--r--src/packrat-lexers.adb4
-rw-r--r--src/packrat-lexers.ads2
-rw-r--r--src/packrat-parsers.adb40
-rw-r--r--src/packrat-parsers.ads13
4 files changed, 56 insertions, 3 deletions
diff --git a/src/packrat-lexers.adb b/src/packrat-lexers.adb
index 3a51e1a..bf5d109 100644
--- a/src/packrat-lexers.adb
+++ b/src/packrat-lexers.adb
@@ -363,7 +363,7 @@ package body Packrat.Lexers is
end Stamp;
- function Ignore
+ function Discard
(Input : in Traits.Element_Array;
Context : in out Lexer_Context)
return Component_Result
@@ -402,7 +402,7 @@ package body Packrat.Lexers is
Context.Error_Labels.Clear;
return Component_Success;
- end Ignore;
+ end Discard;
diff --git a/src/packrat-lexers.ads b/src/packrat-lexers.ads
index 9fd61e2..ac0ba2b 100644
--- a/src/packrat-lexers.ads
+++ b/src/packrat-lexers.ads
@@ -143,7 +143,7 @@ package Packrat.Lexers is
(Input : in Traits.Element_Array;
Start : in Positive)
return Combinator_Result;
- function Ignore
+ function Discard
(Input : in Traits.Element_Array;
Context : in out Lexer_Context)
return Component_Result;
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;
diff --git a/src/packrat-parsers.ads b/src/packrat-parsers.ads
index e11d623..1e058dc 100644
--- a/src/packrat-parsers.ads
+++ b/src/packrat-parsers.ads
@@ -116,6 +116,19 @@ 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;
+ Start : in Positive)
+ return Combinator_Result;
+ function Discard
+ (Input : in Traits.Element_Array;
+ Context : in out Parser_Context;
+ Start : in Positive)
+ return Combinator_Result;
+
+ generic
with function Combo
(Input : in Traits.Element_Array;
Context : in out Parser_Context;