summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/packrat-parsers.adb46
-rw-r--r--src/packrat-parsers.ads3
2 files changed, 24 insertions, 25 deletions
diff --git a/src/packrat-parsers.adb b/src/packrat-parsers.adb
index 85bfbc9..6672dc3 100644
--- a/src/packrat-parsers.adb
+++ b/src/packrat-parsers.adb
@@ -359,27 +359,31 @@ package body Packrat.Parsers is
function Finish_Root
(Root_Result : in Combinator_Result;
- Context : in out Parser_Context;
- Label : in Traits.Label_Enum)
+ Context : in out Parser_Context)
return Graphs.Parse_Graph
is
- Root_Elems : Graphs.Finished_Token_Array (1 .. Integer (Root_Result.Results.Length));
+ Length : Natural := 0;
Index : Positive := 1;
begin
for R of Root_Result.Results loop
- Root_Elems (Index) :=
- (Token => Traits.Tokens.Create (Label, Context.Global_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;
- Index := Index + 1;
+ Length := Length + Integer (R.Tokens.Element'Length);
end loop;
- Context.Result_So_Far.Set_Root (Root_Elems);
- Context.Result_So_Far.Delete_Unreachable;
- return Context.Result_So_Far;
+ if Length = 0 then
+ return Graphs.Empty_Graph;
+ end if;
+ declare
+ Root_Elems : Graphs.Finished_Token_Array (1 .. Length);
+ begin
+ for R of Root_Result.Results loop
+ for T of R.Tokens.Element loop
+ Root_Elems (Index) := T;
+ Index := Index + 1;
+ end loop;
+ end loop;
+ Context.Result_So_Far.Set_Root (Root_Elems);
+ Context.Result_So_Far.Delete_Unreachable;
+ return Context.Result_So_Far;
+ end;
end Finish_Root;
@@ -400,11 +404,10 @@ package body Packrat.Parsers is
Root (Real_Input, Context, Context.Global_Start);
begin
if Root_Result.Status = Failure then
- raise Parser_Error with Packrat.Errors.Encode
- (Traits.Label_Enum'Image (Label), Context.Global_Start);
+ raise Parser_Error;
end if;
if Input'Length = 0 then
- Result := Finish_Root (Root_Result, Context, Label);
+ Result := Finish_Root (Root_Result, Context);
return;
end if;
if not Context.Needs_More.Is_Empty then
@@ -436,10 +439,9 @@ package body Packrat.Parsers is
Root (Real_Input, Context, Context.Global_Start);
begin
if Root_Result.Status /= Success then
- raise Parser_Error with Packrat.Errors.Encode
- (Traits.Label_Enum'Image (Label), Context.Global_Start);
+ raise Parser_Error;
end if;
- return Finish_Root (Root_Result, Context, Label);
+ return Finish_Root (Root_Result, Context);
end;
end Parse_Only;
@@ -449,7 +451,7 @@ package body Packrat.Parsers is
Context : in out Parser_Context)
return Graphs.Parse_Graph
is
- procedure My_Parse is new Parse (Label, Root);
+ procedure My_Parse is new Parse (Root);
Result : Graphs.Parse_Graph;
begin
loop
diff --git a/src/packrat-parsers.ads b/src/packrat-parsers.ads
index 471d667..93ad258 100644
--- a/src/packrat-parsers.ads
+++ b/src/packrat-parsers.ads
@@ -70,7 +70,6 @@ package Packrat.Parsers is
generic
- Label : in Traits.Label_Enum;
with function Root
(Input : in Traits.Element_Array;
Context : in out Parser_Context;
@@ -82,7 +81,6 @@ package Packrat.Parsers is
Result : out Graphs.Parse_Graph);
generic
- Label : in Traits.Label_Enum;
with function Root
(Input : in Traits.Element_Array;
Context : in out Parser_Context;
@@ -94,7 +92,6 @@ package Packrat.Parsers is
return Graphs.Parse_Graph;
generic
- Label : in Traits.Label_Enum;
with function Root
(Input : in Traits.Element_Array;
Context : in out Parser_Context;