From 6f15340717a5d2dccdcf8de0a03a161c5abeef70 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Sun, 27 Jan 2019 19:08:11 +1100 Subject: Iteration specifications added for Parse_Graphs --- src/packrat.ads | 84 ++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 69 insertions(+), 15 deletions(-) (limited to 'src/packrat.ads') diff --git a/src/packrat.ads b/src/packrat.ads index 05a8e6a..d1fc9a0 100644 --- a/src/packrat.ads +++ b/src/packrat.ads @@ -191,6 +191,62 @@ package Packrat is package Interfaces is + type Node is interface; + + + function Leaf + (New_Item : in Element_Array; + Start : in Positive; + Finish : in Natural) + return Node is abstract + with Pre'Class => + Finish + 1 >= Start, + Post'Class => + Is_Leaf (Leaf'Result); + + function Branch + (Label : in Label_Enum; + Start : in Positive; + Finish : in Natural) + return Node is abstract + with Pre'Class => + Finish + 1 >= Start, + Post'Class => + Is_Branch (Branch'Result); + + + function Is_Leaf + (This : in Node) + return Boolean is abstract; + + function Is_Branch + (This : in Node) + return Boolean is abstract; + + + function Label + (This : in Node) + return Label_Enum is abstract + with Pre'Class => + This.Is_Branch; + + function Elements + (This : in Node) + return Element_Array is abstract + with Pre'Class => + This.Is_Leaf; + + function Start + (This : in Node) + return Positive is abstract; + + function Finish + (This : in Node) + return Natural is abstract; + + + + type Cursor is interface; @@ -205,12 +261,20 @@ package Packrat is with Pre'Class => not Position.Is_Nothing; + function Is_Node + (Position : in Cursor) + return Boolean is abstract + with Post'Class => + (if Is_Node'Result then not Position.Is_Nothing); + function Is_Root (Position : in Cursor) return Boolean is abstract with Post'Class => (if Is_Root'Result then - Position.Parent.Is_Nothing and Position.Depth = 0); + not Position.Is_Nothing and + Position.Parent.Is_Nothing and + Position.Depth = 0); function Is_Branch (Position : in Cursor) @@ -224,6 +288,7 @@ package Packrat is with Post'Class => (if Is_Leaf'Result then not Position.Is_Nothing); + function Label (Position : in Cursor) return Label_Enum is abstract @@ -236,7 +301,6 @@ package Packrat is with Pre'Class => Position.Is_Leaf; - function Start (Position : in Cursor) return Positive is abstract @@ -370,21 +434,11 @@ package Packrat is (if Contains'Result then not Position.Is_Nothing); - function Leaf - (New_Item : in Element_Array; - Start : in Positive; - Finish : in Natural) - return Graph is abstract - with Post'Class => - Leaf'Result.Node_Count = 1; - - function Branch - (Label : in Label_Enum; - Start : in Positive; - Finish : in Natural) + function Singleton + (Input : in Node'Class) return Graph is abstract with Post'Class => - Branch'Result.Node_Count = 1; + Singleton'Result.Node_Count = 1; function Is_Empty -- cgit