diff options
author | Jed Barber <jjbarber@y7mail.com> | 2020-12-02 12:38:38 +1100 |
---|---|---|
committer | Jed Barber <jjbarber@y7mail.com> | 2020-12-02 12:38:38 +1100 |
commit | 0a4e00c7dfa35265de2808c3c405f26b2115ec00 (patch) | |
tree | 1710957474ee5672bb5352356279987bc1f73443 | |
parent | 52403b22ff3463b9b3b0f8f26c0f965f50e4b458 (diff) |
Parser Stamp and Ignore combinators
-rw-r--r-- | src/packrat-parsers.adb | 65 | ||||
-rw-r--r-- | src/packrat-parsers.ads | 4 |
2 files changed, 55 insertions, 14 deletions
diff --git a/src/packrat-parsers.adb b/src/packrat-parsers.adb index f49eca1..4bdbfb4 100644 --- a/src/packrat-parsers.adb +++ b/src/packrat-parsers.adb @@ -22,7 +22,7 @@ package body Packrat.Parsers is (Left, Right : in Tok_Holds.Holder) return Boolean is - use Traits.Tokens; + use type Graphs.Finished_Token_Array; begin return Left.Element < Right.Element; end "<"; @@ -266,7 +266,7 @@ package body Packrat.Parsers is return Combinator_Result is use type Traits.Element_Array; - use type Traits.Tokens.Token_Array; + use type Graphs.Finished_Token_Array; Salt, Temp : Combinator_Result; Adjust : Result_Sets.Set; begin @@ -363,12 +363,37 @@ package body Packrat.Parsers is 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); + Current : Graphs.Finished_Token; + Processed : Result_Sets.Set; + begin + if Salt.Status /= Success then + return Salt; + end if; + for R of Salt.Results loop + Current := + (Token => Traits.Tokens.Create (Label, Start, R.Value.Element), + Finish => R.Finish); + if R.Tokens.Element'Length > 0 then + Context.Result_So_Far.Connect (Current, R.Tokens.Element); + else + Context.Result_So_Far.Include (Current.Token); + end if; + Processed.Insert + ((Finish => R.Finish, + Value => Elem_Holds.Empty_Holder, + Tokens => Tok_Holds.To_Holder ((1 => Current)))); + end loop; + Salt.Results := Processed; + return Salt; + end Actual; + function Memo is new Memoize (To_Key (Start, Stamp'Access), Actual); begin - -- to-do - return - (Results => Result_Sets.Empty_Set, - Curtails => Curtail_Maps.Empty_Map, - Status => Failure); + return Memo (Context); end Stamp; @@ -378,12 +403,28 @@ package body Packrat.Parsers is 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 /= Success then + return Salt; + end if; + for R of Salt.Results loop + Processed.Insert + ((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, Ignore'Access), Actual); begin - -- to-do - return - (Results => Result_Sets.Empty_Set, - Curtails => Curtail_Maps.Empty_Map, - Status => Failure); + return Memo (Context); end Ignore; diff --git a/src/packrat-parsers.ads b/src/packrat-parsers.ads index a5716f2..7ed2c89 100644 --- a/src/packrat-parsers.ads +++ b/src/packrat-parsers.ads @@ -344,8 +344,8 @@ private "=" => Traits."="); package Tok_Holds is new Ada.Containers.Indefinite_Holders - (Element_Type => Traits.Tokens.Token_Array, - "=" => Traits.Tokens."="); + (Element_Type => Graphs.Finished_Token_Array, + "=" => Graphs."="); function "<" (Left, Right : in Elem_Holds.Holder) |