summaryrefslogtreecommitdiff
path: root/src/packrat-graphs.ads
diff options
context:
space:
mode:
Diffstat (limited to 'src/packrat-graphs.ads')
-rw-r--r--src/packrat-graphs.ads70
1 files changed, 43 insertions, 27 deletions
diff --git a/src/packrat-graphs.ads b/src/packrat-graphs.ads
index 5074485..6bceaaf 100644
--- a/src/packrat-graphs.ads
+++ b/src/packrat-graphs.ads
@@ -387,26 +387,52 @@ package Packrat.Graphs is
package Graph_Iterators is
new Ada.Iterator_Interfaces (Cursor, Is_Node);
+ -- Note that if the given Cursor doesn't point to any position,
+ -- then the function should assume that the choice is of what root to
+ -- select and return that value.
type Choosing_Function is access function
+ (Container : in Graph;
+ Position : in Cursor)
+ return Natural;
+
+ -- This function returns True if a Node pointed to by a Cursor should
+ -- be returned, and False if it should be ignored. An example of a
+ -- filter that will probably see a decent amount of use would be Is_Leaf.
+ type Filter_Function is access function
(Position : in Cursor)
+ return Boolean;
+
+
+
+
+ function Default_Choices
+ (Container : in Graph;
+ Position : in Cursor)
return Natural;
+ function Accept_All
+ (Position : in Cursor)
+ return Boolean;
- function Iterate
- (This : in Graph)
- return Graph_Iterators.Reversible_Iterator'Class;
- function Iterate_Subtree
- (This : in Graph;
- Position : in Cursor)
- return Graph_Iterators.Reversible_Iterator'Class;
+ 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
+ with Pre =>
+ Container.Contains (Start_At) or Is_Nothing (Start_At);
- function Iterate_Choice
- (This : in Graph;
- Func : in Choosing_Function)
- return Graph_Iterators.Forward_Iterator'Class;
+ 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
+ with Pre =>
+ Container.Contains (Start_At) or Is_Nothing (Start_At);
@@ -597,24 +623,14 @@ private
- type Forward_Iterator is new Graph_Iterators.Forward_Iterator with record
- Position : Cursor;
- end record;
-
- overriding function First
- (Object : in Forward_Iterator)
- return Cursor;
-
- overriding function Next
- (Object : in Forward_Iterator;
- Place : in Cursor)
- return Cursor;
-
-
-
+ type Iterate_Kind is (Specific_Branch, All_Nodes);
type Reversible_Iterator is new Graph_Iterators.Reversible_Iterator with record
- Position : Cursor;
+ My_Graph : access Graph;
+ Start_Pos : Cursor;
+ Rule : Iterate_Kind;
+ Choose_Func : Choosing_Function;
+ Filter_Func : Filter_Function;
end record;
overriding function First