summaryrefslogtreecommitdiff
path: root/src/packrat-parsers.adb
diff options
context:
space:
mode:
Diffstat (limited to 'src/packrat-parsers.adb')
-rw-r--r--src/packrat-parsers.adb167
1 files changed, 99 insertions, 68 deletions
diff --git a/src/packrat-parsers.adb b/src/packrat-parsers.adb
index df88e71..d854f73 100644
--- a/src/packrat-parsers.adb
+++ b/src/packrat-parsers.adb
@@ -416,82 +416,111 @@ package body Packrat.Parsers is
end Finish_Root;
- procedure Parse
- (Input : in Traits.Element_Array;
- Context : in out Parser_Context;
- Result : out Graphs.Parse_Graph) is
- begin
- Tidy_Context (Input, Context);
- Context.Allow_Incomplete := (Input'Length /= 0);
- declare
- use type Traits.Element_Array;
- Real_Input : Traits.Element_Array :=
- (if Context.Pass_Forward.Is_Empty
- then Slide (Input, Context.Current_Position)
- else Element (Context.Pass_Forward) & Input);
- Root_Result : Combinator_Result :=
- Root (Real_Input, Context, Context.Global_Start);
- begin
- if Root_Result.Status = Failure then
- raise Parser_Error with -Context.Error_String;
- end if;
- if Input'Length = 0 then
- Result := Finish_Root (Root_Result, Context);
- return;
- end if;
- if not Context.Needs_More.Is_Empty then
- Context.Current_Position := Context.Needs_More.First_Element;
- Context.Pass_Forward.Replace_Element
- (Real_Input (Context.Current_Position .. Real_Input'Last));
- else
- Context.Current_Position := Real_Input'Last + 1;
- Context.Pass_Forward.Clear;
- end if;
- end;
- end Parse;
+ package body Parse_Parts is
+ Context : Parser_Context := Empty_Context;
- function Parse_Only
- (Input : in Traits.Element_Array;
- Context : in out Parser_Context)
- return Graphs.Parse_Graph is
- begin
- Tidy_Context (Input, Context);
- Context.Allow_Incomplete := False;
- declare
- use type Traits.Element_Array;
- Real_Input : Traits.Element_Array :=
- (if Context.Pass_Forward.Is_Empty
- then Slide (Input, Context.Current_Position)
- else Element (Context.Pass_Forward) & Input);
- Root_Result : Combinator_Result :=
- Root (Real_Input, Context, Context.Global_Start);
+ procedure Parse
+ (Input : in Traits.Element_Array;
+ Result : out Graphs.Parse_Graph) is
begin
- if Root_Result.Status /= Success then
- raise Parser_Error with -Context.Error_String;
- end if;
- return Finish_Root (Root_Result, Context);
- end;
- end Parse_Only;
+ Tidy_Context (Input, Context);
+ Context.Allow_Incomplete := (Input'Length /= 0);
+ declare
+ use type Traits.Element_Array;
+ Real_Input : Traits.Element_Array :=
+ (if Context.Pass_Forward.Is_Empty
+ then Slide (Input, Context.Current_Position)
+ else Element (Context.Pass_Forward) & Input);
+ Root_Result : Combinator_Result :=
+ Root (Real_Input, Context, Context.Global_Start);
+ begin
+ if Root_Result.Status = Failure then
+ raise Parser_Error with -Context.Error_String;
+ end if;
+ if Input'Length = 0 then
+ Result := Finish_Root (Root_Result, Context);
+ return;
+ end if;
+ if not Context.Needs_More.Is_Empty then
+ Context.Current_Position := Context.Needs_More.First_Element;
+ Context.Pass_Forward.Replace_Element
+ (Real_Input (Context.Current_Position .. Real_Input'Last));
+ else
+ Context.Current_Position := Real_Input'Last + 1;
+ Context.Pass_Forward.Clear;
+ end if;
+ end;
+ end Parse;
+ procedure Reset is
+ begin
+ Context := Empty_Context;
+ end Reset;
- function Parse_With
- (Input : in With_Input;
- Context : in out Parser_Context)
- return Graphs.Parse_Graph
- is
- procedure My_Parse is new Parse (Root);
- Result : Graphs.Parse_Graph;
- begin
- loop
+ end Parse_Parts;
+
+
+ package body Parse_Once is
+
+ Context : Parser_Context := Empty_Context;
+
+ function Parse
+ (Input : in Traits.Element_Array)
+ return Graphs.Parse_Graph is
+ begin
+ Tidy_Context (Input, Context);
+ Context.Allow_Incomplete := False;
declare
- Next_Input : Traits.Element_Array := Input.all;
+ use type Traits.Element_Array;
+ Real_Input : Traits.Element_Array :=
+ (if Context.Pass_Forward.Is_Empty
+ then Slide (Input, Context.Current_Position)
+ else Element (Context.Pass_Forward) & Input);
+ Root_Result : Combinator_Result :=
+ Root (Real_Input, Context, Context.Global_Start);
begin
- My_Parse (Next_Input, Context, Result);
- exit when Next_Input'Length = 0;
+ if Root_Result.Status /= Success then
+ raise Parser_Error with -Context.Error_String;
+ end if;
+ return Finish_Root (Root_Result, Context);
end;
- end loop;
- return Result;
+ end Parse;
+
+ procedure Reset is
+ begin
+ Context := Empty_Context;
+ end Reset;
+
+ end Parse_Once;
+
+
+ package body Parse_With is
+
+ package My_Parse is new Parse_Parts (Root);
+
+ function Parse
+ (Input : in With_Input)
+ return Graphs.Parse_Graph
+ is
+ Result : Graphs.Parse_Graph;
+ begin
+ loop
+ declare
+ Next_Input : Traits.Element_Array := Input.all;
+ begin
+ My_Parse.Parse (Next_Input, Result);
+ exit when Next_Input'Length = 0;
+ end;
+ end loop;
+ return Result;
+ end Parse;
+
+ procedure Reset is
+ begin
+ My_Parse.Reset;
+ end Reset;
+
end Parse_With;
@@ -584,6 +613,8 @@ package body Packrat.Parsers is
package body Redirect is
+ Combo : Combinator := null;
+
procedure Set
(Target : in Combinator) is
begin