summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2020-12-03 00:33:28 +1100
committerJed Barber <jjbarber@y7mail.com>2020-12-03 00:33:28 +1100
commit698f793f34436e9c27d969b6d838aa96336f04f4 (patch)
treed759e7ea20254c49daa073c0c4e46160ee69ac48
parente07aa7be550b1ecf557e554f680380dff5eef4cd (diff)
Root parser combinator
-rw-r--r--src/packrat-parsers.adb20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/packrat-parsers.adb b/src/packrat-parsers.adb
index 4bdbfb4..8533b96 100644
--- a/src/packrat-parsers.adb
+++ b/src/packrat-parsers.adb
@@ -312,9 +312,25 @@ package body Packrat.Parsers is
Start : in Positive)
return Component_Result
is
+ Salt : Combinator_Result := Combo (Input, Context, Start);
+ Index : Positive := 1;
+ Root_Elems : Graphs.Finished_Token_Array (1 .. Integer (Salt.Results.Length));
begin
- -- to-do
- return (Status => Failure);
+ if Salt.Status /= Success then
+ return (Status => Salt.Status);
+ end if;
+ for R of Salt.Results loop
+ Root_Elems (Index) :=
+ (Token => Traits.Tokens.Create (Label, Start, R.Value.Element),
+ Finish => R.Finish);
+ if R.Tokens.Element'Length > 0 then
+ Context.Result_So_Far.Connect (Root_Elems (Index), R.Tokens.Element);
+ else
+ Context.Result_So_Far.Include (Root_Elems (Index).Token);
+ end if;
+ end loop;
+ Context.Result_So_Far.Set_Root (Root_Elems);
+ return (Status => Success);
end Root;