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.ads180
1 files changed, 167 insertions, 13 deletions
diff --git a/src/packrat-graphs.ads b/src/packrat-graphs.ads
index 4095360..877be3a 100644
--- a/src/packrat-graphs.ads
+++ b/src/packrat-graphs.ads
@@ -1,5 +1,10 @@
+with
+
+ Ada.Iterator_Interfaces;
+
+
generic
type Label_Enum is (<>);
type Element is private;
@@ -8,10 +13,70 @@ generic
package Packrat.Graphs is
+ type Node is new My_Interfaces.Node with private;
+
+ type Node_Reference (Data : not null access Node'Class) is limited null record
+ with Implicit_Dereference => Data;
+
type Cursor is new My_Interfaces.Cursor with private;
- type Parse_Graph is new My_Interfaces.Graph with private;
+ type Iter_Cursor (Data : not null access Cursor) is private
+ with Implicit_Dereference => Data;
+
+
+ type Parse_Graph is new My_Interfaces.Graph with private
+ with Default_Iterator => Iterate,
+ Iterator_Element => Node_Reference,
+ Variable_Indexing => Node_At;
+
+
+
+
+ No_Position : constant Cursor;
+
+ Empty_Graph : constant Parse_Graph;
+
+
+
+
+ function Leaf
+ (New_Item : in Element_Array;
+ Start : in Positive;
+ Finish : in Natural)
+ return Node;
+
+ function Branch
+ (Label : in Label_Enum;
+ Start : in Positive;
+ Finish : in Natural)
+ return Node;
+
+
+ function Is_Leaf
+ (This : in Node)
+ return Boolean;
+
+ function Is_Branch
+ (This : in Node)
+ return Boolean;
+
+
+ function Label
+ (This : in Node)
+ return Label_Enum;
+
+ function Elements
+ (This : in Node)
+ return Element_Array;
+
+ function Start
+ (This : in Node)
+ return Positive;
+
+ function Finish
+ (This : in Node)
+ return Natural;
@@ -27,6 +92,10 @@ package Packrat.Graphs is
(Position : in Cursor)
return Natural;
+ function Is_Node
+ (Position : in Cursor)
+ return Boolean;
+
function Is_Root
(Position : in Cursor)
return Boolean;
@@ -39,6 +108,9 @@ package Packrat.Graphs is
(Position : in Cursor)
return Boolean;
+
+
+
function Label
(Position : in Cursor)
return Label_Enum;
@@ -47,9 +119,6 @@ package Packrat.Graphs is
(Position : in Cursor)
return Element_Array;
-
-
-
function Start
(Position : in Cursor)
return Positive;
@@ -145,17 +214,16 @@ package Packrat.Graphs is
- function Leaf
- (New_Item : in Element_Array;
- Start : in Positive;
- Finish : in Natural)
+ function Singleton
+ (Input : in My_Interfaces.Node'Class)
return Parse_Graph;
- function Branch
- (Label : in Label_Enum;
- Start : in Positive;
- Finish : in Natural)
- return Parse_Graph;
+ function Node_At
+ (Container : in Parse_Graph;
+ Position : in My_Interfaces.Cursor'Class)
+ return Node_Reference
+ with Pre =>
+ Position.Is_Node;
@@ -221,15 +289,101 @@ package Packrat.Graphs is
+ function Is_Valid_Node
+ (Position : in Iter_Cursor)
+ return Boolean;
+
+
+
+
+ package Graph_Iterators is
+ new Ada.Iterator_Interfaces (Iter_Cursor, Is_Valid_Node);
+
+ type Choosing_Function is access function
+ (Position : in Cursor)
+ return Natural;
+
+
+
+
+ function Iterate
+ (This : in Parse_Graph)
+ return Graph_Iterators.Reversible_Iterator'Class;
+
+ function Iterate_Subtree
+ (This : in Parse_Graph;
+ Position : in My_Interfaces.Cursor'Class)
+ return Graph_Iterators.Reversible_Iterator'Class;
+
+ function Iterate_Choice
+ (This : in Parse_Graph;
+ Func : in Choosing_Function)
+ return Graph_Iterators.Forward_Iterator'Class;
+
+
+
+
private
+ type Node is new My_Interfaces.Node with null record;
+
type Cursor is new My_Interfaces.Cursor with null record;
+ type Iter_Cursor (Data : not null access Cursor) is null record;
type Parse_Graph is new My_Interfaces.Graph with null record;
+
+
+ No_Node : constant Node := (My_Interfaces.Node with null record);
+
+ No_Position : constant Cursor := (My_Interfaces.Cursor with null record);
+
+ Empty_Graph : constant Parse_Graph := (My_Interfaces.Graph with null record);
+
+
+
+
+ type Forward_Iterator is new Graph_Iterators.Forward_Iterator with record
+ My_Container : access Parse_Graph;
+ My_Position : Cursor;
+ end record;
+
+ overriding function First
+ (Object : in Forward_Iterator)
+ return Iter_Cursor;
+
+ overriding function Next
+ (Object : in Forward_Iterator;
+ Place : in Iter_Cursor)
+ return Iter_Cursor;
+
+ type Reversible_Iterator is new Graph_Iterators.Reversible_Iterator with record
+ My_Container : access Parse_Graph;
+ My_Position : Cursor;
+ end record;
+
+ overriding function First
+ (Object : in Reversible_Iterator)
+ return Iter_Cursor;
+
+ overriding function Next
+ (Object : in Reversible_Iterator;
+ Place : in Iter_Cursor)
+ return Iter_Cursor;
+
+ overriding function Last
+ (Object : in Reversible_Iterator)
+ return Iter_Cursor;
+
+ overriding function Previous
+ (Object : in Reversible_Iterator;
+ Place : in Iter_Cursor)
+ return Iter_Cursor;
+
+
end Packrat.Graphs;