summaryrefslogtreecommitdiff
path: root/src/packrat-graphs.adb
diff options
context:
space:
mode:
Diffstat (limited to 'src/packrat-graphs.adb')
-rw-r--r--src/packrat-graphs.adb99
1 files changed, 61 insertions, 38 deletions
diff --git a/src/packrat-graphs.adb b/src/packrat-graphs.adb
index f32c628..10e130f 100644
--- a/src/packrat-graphs.adb
+++ b/src/packrat-graphs.adb
@@ -1012,55 +1012,61 @@ package body Packrat.Graphs is
- function Iterate
- (This : in Graph)
- return Graph_Iterators.Reversible_Iterator'Class is
- begin
- return Result : Reversible_Iterator do
- Result.Position := No_Position;
- end return;
- end Iterate;
-
-
- function Iterate_Subtree
- (This : in Graph;
- Position : in Cursor)
- return Graph_Iterators.Reversible_Iterator'Class is
+ function Default_Choices
+ (Container : in Graph;
+ Position : in Cursor)
+ return Natural is
begin
- return Result : Reversible_Iterator do
- Result.Position := No_Position;
- end return;
- end Iterate_Subtree;
+ if Is_Nothing (Position) then
+ return Container.Root_Count;
+ else
+ return Choices (Position);
+ end if;
+ end Default_Choices;
- function Iterate_Choice
- (This : in Graph;
- Func : in Choosing_Function)
- return Graph_Iterators.Forward_Iterator'Class is
+ function Accept_All
+ (Position : in Cursor)
+ return Boolean is
begin
- return Result : Forward_Iterator do
- Result.Position := No_Position;
- end return;
- end Iterate_Choice;
+ return not Is_Nothing (Position);
+ end Accept_All;
- function First
- (Object : in Forward_Iterator)
- return Cursor is
+ function Iterate
+ (Container : in Graph;
+ Start_At : in Cursor := No_Position;
+ Choose : in Choosing_Function := Default_Choices'Access;
+ Filter : in Filter_Function := Accept_All'Access)
+ return Graph_Iterators.Reversible_Iterator'Class is
begin
- return No_Position;
- end First;
+ return This : Reversible_Iterator do
+ This.My_Graph := Container'Unrestricted_Access;
+ This.Start_Pos := Start_At;
+ This.Rule := Specific_Branch;
+ This.Choose_Func := Choose;
+ This.Filter_Func := Filter;
+ end return;
+ end Iterate;
- function Next
- (Object : in Forward_Iterator;
- Place : in Cursor)
- return Cursor is
+
+ function Iterate_All
+ (Container : in Graph;
+ Start_At : in Cursor := No_Position;
+ Filter : in Filter_Function := Accept_All'Access)
+ return Graph_Iterators.Reversible_Iterator'Class is
begin
- return No_Position;
- end Next;
+ return This : Reversible_Iterator do
+ This.My_Graph := Container'Unrestricted_Access;
+ This.Start_Pos := Start_At;
+ This.Rule := All_Nodes;
+ This.Choose_Func := null;
+ This.Filter_Func := Filter;
+ end return;
+ end Iterate_All;
@@ -1070,7 +1076,18 @@ package body Packrat.Graphs is
(Object : in Reversible_Iterator)
return Cursor is
begin
- return No_Position;
+ if Object.My_Graph = null or else Object.My_Graph.all.Is_Empty then
+ return No_Position;
+ elsif Is_Nothing (Object.Start_Pos) then
+ if Object.Rule = All_Nodes then
+ return Object.My_Graph.all.Root (1);
+ else
+ return Object.My_Graph.all.Root
+ (Object.Choose_Func (Object.My_Graph.all, No_Position));
+ end if;
+ else
+ return Object.Start_Pos;
+ end if;
end First;
@@ -1079,6 +1096,12 @@ package body Packrat.Graphs is
Place : in Cursor)
return Cursor is
begin
+ if Object.My_Graph = null or else
+ Object.My_Graph.all.Is_Empty or else
+ Is_Nothing (Place)
+ then
+ return No_Position;
+ end if; -- elsif
return No_Position;
end Next;