From 698f793f34436e9c27d969b6d838aa96336f04f4 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Thu, 3 Dec 2020 00:33:28 +1100 Subject: Root parser combinator --- src/packrat-parsers.adb | 20 ++++++++++++++++++-- 1 file 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; -- cgit