summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--example/sentence.adb8
-rw-r--r--src/packrat-lexers.adb2
-rw-r--r--src/packrat-lexers.ads6
-rw-r--r--src/packrat-parse_graphs.adb192
-rw-r--r--src/packrat-parse_graphs.ads121
-rw-r--r--src/packrat-parsers.adb12
-rw-r--r--src/packrat-parsers.ads6
-rw-r--r--src/packrat-standard.ads2
-rw-r--r--src/packrat-tokens.adb72
-rw-r--r--src/packrat-tokens.ads61
-rw-r--r--test/packrat-lexers-debug.adb2
-rw-r--r--test/packrat-lexers-debug.ads2
-rw-r--r--test/rat_tests-lexers.adb4
-rw-r--r--test/rat_tests-parse_graphs.adb92
-rw-r--r--test/rat_tests-tokens.adb12
-rw-r--r--test/test_main.adb2
16 files changed, 316 insertions, 280 deletions
diff --git a/example/sentence.adb b/example/sentence.adb
index f522b5f..5270d3a 100644
--- a/example/sentence.adb
+++ b/example/sentence.adb
@@ -115,12 +115,18 @@ begin
Put_Line ("Lexer token output:");
for T of Lexed_Tokens loop
- Put (My_Rat.Lexer_Traits.Tokens.Debug_String (T));
+ Put (My_Rat.Lexer_Tokens.Debug_String (T));
end loop;
New_Line;
Put_Line ("Parser graph output:");
Put_Line (My_Rat.Parse_Graphs.Debug_String (Result_Graph));
+ New_Line;
+
+ Put_Line ("Root tokens:");
+ for T of Result_Graph.Root_Elements loop
+ Put (My_Rat.Parser_Tokens.Debug_String (T));
+ end loop;
end Sentence;
diff --git a/src/packrat-lexers.adb b/src/packrat-lexers.adb
index 830fdeb..34bd5c0 100644
--- a/src/packrat-lexers.adb
+++ b/src/packrat-lexers.adb
@@ -71,7 +71,7 @@ package body Packrat.Lexers is
procedure Token_Vector_To_Array
(Input_Vector : in Token_Vectors.Vector;
- Padding : in Traits.Tokens.Token;
+ Padding : in Traits.Tokens.Token_Type;
Output_Array : out Traits.Tokens.Token_Array) is
begin
for N in Integer range 1 .. Output_Array'Length loop
diff --git a/src/packrat-lexers.ads b/src/packrat-lexers.ads
index 68a01d0..034590c 100644
--- a/src/packrat-lexers.ads
+++ b/src/packrat-lexers.ads
@@ -94,7 +94,7 @@ package Packrat.Lexers is
generic
Components : in Component_Array;
Pad_In : in Traits.Element_Type;
- Pad_Out : in Traits.Tokens.Token;
+ Pad_Out : in Traits.Tokens.Token_Type;
package Scan_Set is
procedure Scan
@@ -109,7 +109,7 @@ package Packrat.Lexers is
generic
Components : in Component_Array;
Pad_In : in Traits.Element_Type;
- Pad_Out : in Traits.Tokens.Token;
+ Pad_Out : in Traits.Tokens.Token_Type;
package Scan_Set_With is
procedure Scan
@@ -294,7 +294,7 @@ private
package Token_Vectors is new Ada.Containers.Vectors
(Index_Type => Positive,
- Element_Type => Traits.Tokens.Token,
+ Element_Type => Traits.Tokens.Token_Type,
"=" => Traits.Tokens."=");
package Label_Vectors is new Ada.Containers.Vectors
diff --git a/src/packrat-parse_graphs.adb b/src/packrat-parse_graphs.adb
index b919cff..2d5c2a5 100644
--- a/src/packrat-parse_graphs.adb
+++ b/src/packrat-parse_graphs.adb
@@ -30,69 +30,11 @@ package body Packrat.Parse_Graphs is
function "<"
- (Left, Right : Finished_Token)
- return Boolean
- is
- Left_Index, Right_Index : Positive;
- begin
- if Traits.Tokens.Start (Left.Token) = Traits.Tokens.Start (Right.Token) then
- if Left.Finish = Right.Finish then
- if Traits.Tokens.Label (Left.Token) = Traits.Tokens.Label (Right.Token) then
- Left_Index := Traits.Tokens.Value (Left.Token)'First;
- Right_Index := Traits.Tokens.Value (Right.Token)'First;
- while Left_Index <= Traits.Tokens.Value (Left.Token)'Last and
- Right_Index <= Traits.Tokens.Value (Right.Token)'Last
- loop
- if Traits.Tokens.Value (Left.Token) (Left_Index) <
- Traits.Tokens.Value (Right.Token) (Right_Index)
- then
- return True;
- elsif Traits.Tokens.Value (Left.Token) (Left_Index) /=
- Traits.Tokens.Value (Right.Token) (Right_Index)
- then
- return False;
- end if;
- Left_Index := Left_Index + 1;
- Right_Index := Right_Index + 1;
- end loop;
- return Traits.Tokens.Value (Left.Token)'Length <
- Traits.Tokens.Value (Right.Token)'Length;
- else
- return Traits.Tokens.Label (Left.Token) < Traits.Tokens.Label (Right.Token);
- end if;
- else
- return Left.Finish < Right.Finish;
- end if;
- else
- return Traits.Tokens.Start (Left.Token) < Traits.Tokens.Start (Right.Token);
- end if;
- end "<";
-
-
- function "<"
- (Left, Right : in Finished_Token_Array)
- return Boolean
- is
- Left_Index : Positive := Left'First;
- Right_Index : Positive := Right'First;
- begin
- while Left_Index <= Left'Last and Right_Index <= Right'Last loop
- if Left (Left_Index) < Right (Right_Index) then
- return True;
- elsif Left (Left_Index) /= Right (Right_Index) then
- return False;
- end if;
- Left_Index := Left_Index + 1;
- Right_Index := Right_Index + 1;
- end loop;
- return Left'Length < Right'Length;
- end "<";
-
-
- function "<"
(Left, Right : in Finished_Token_Vectors.Vector)
return Boolean
is
+ use type Ada.Containers.Count_Type;
+ use type Traits.Tokens.Finished_Token_Type;
Left_Index : Positive := Left.First_Index;
Right_Index : Positive := Right.First_Index;
begin
@@ -190,8 +132,8 @@ package body Packrat.Parse_Graphs is
return Finish_Vectors.Vector
is
Result : Finish_Vectors.Vector;
- Current : Finish_Type;
- Node_Label : Traits.Tokens.Token;
+ Current : Traits.Tokens.Finish_Type;
+ Node_Label : Traits.Tokens.Token_Type;
begin
Node_Label := Container.Internal_Graph.Label (Node);
for Fin_Token of Container.Root_Elems loop
@@ -217,7 +159,7 @@ package body Packrat.Parse_Graphs is
return Finish_Vectors.Vector
is
Result : Finish_Vectors.Vector;
- Current : Finish_Type;
+ Current : Traits.Tokens.Finish_Type;
begin
for Edge of Container.Internal_Graph.Outbound (Node) loop
Current := Container.Internal_Graph.Label (Edge).Group_Finish;
@@ -261,7 +203,7 @@ package body Packrat.Parse_Graphs is
end Image;
Mapping : Enum_Node_Maps.Map := Generate_Map (Container);
- Current : Traits.Tokens.Token;
+ Current : Traits.Tokens.Token_Type;
Result : SU.Unbounded_String;
begin
for Iter in Mapping.Iterate loop
@@ -272,7 +214,8 @@ package body Packrat.Parse_Graphs is
for Fin of In_Finishes (Container, Node) loop
SU.Append (Result, Image (Fin) & " ->" & Latin.HT);
declare
- Groupings : Token_Group_Array := Container.Subgroups ((Current, Fin));
+ A_Fin_Token : Traits.Tokens.Finished_Token_Type := (Current, Fin);
+ Groupings : Token_Group_Array := Container.Subgroups (A_Fin_Token);
begin
if Groupings'Length = 0 then
SU.Append (Result, "Leaf" & Latin.LF);
@@ -309,7 +252,7 @@ package body Packrat.Parse_Graphs is
function Contains
(Container : in Parse_Graph;
- Token : in Traits.Tokens.Token)
+ Token : in Traits.Tokens.Token_Type)
return Boolean is
begin
return Container.Label_Map.Contains (Token);
@@ -318,9 +261,10 @@ package body Packrat.Parse_Graphs is
function Contains
(Container : in Parse_Graph;
- Position : in Finished_Token)
+ Position : in Traits.Tokens.Finished_Token_Type)
return Boolean
is
+ use type Traits.Tokens.Finished_Token_Type;
Node : Node_ID_Type;
begin
if not Container.Contains (Position.Token) then
@@ -374,13 +318,15 @@ package body Packrat.Parse_Graphs is
function Reachable
(Container : in Parse_Graph;
- Position : in Finished_Token)
+ Position : in Traits.Tokens.Finished_Token_Type)
return Boolean
is
-- This is basically a depth first search function.
function Finder
- (Current : in Finished_Token)
- return Boolean is
+ (Current : in Traits.Tokens.Finished_Token_Type)
+ return Boolean
+ is
+ use type Traits.Tokens.Finished_Token_Type;
begin
return Current = Position or else
(for some Grouping of Container.Subgroups (Current) =>
@@ -431,7 +377,7 @@ package body Packrat.Parse_Graphs is
function Valid_Token
- (Fin_Token : in Finished_Token)
+ (Fin_Token : in Traits.Tokens.Finished_Token_Type)
return Boolean is
begin
return Fin_Token.Finish + 1 >= Traits.Tokens.Start (Fin_Token.Token);
@@ -439,8 +385,8 @@ package body Packrat.Parse_Graphs is
function Valid_Starts_Finishes
- (Parent : in Finished_Token;
- Subtokens : in Finished_Token_Array)
+ (Parent : in Traits.Tokens.Finished_Token_Type;
+ Subtokens : in Traits.Tokens.Finished_Token_Array)
return Boolean
is
Subvec : Finished_Token_Vectors.Vector;
@@ -468,13 +414,15 @@ package body Packrat.Parse_Graphs is
function Loops_Introduced
(Container : in Parse_Graph;
- Parent : in Finished_Token;
- Subtokens : in Finished_Token_Array)
+ Parent : in Traits.Tokens.Finished_Token_Type;
+ Subtokens : in Traits.Tokens.Finished_Token_Array)
return Boolean
is
function Looper
- (Current : in Finished_Token)
- return Boolean is
+ (Current : in Traits.Tokens.Finished_Token_Type)
+ return Boolean
+ is
+ use type Traits.Tokens.Finished_Token_Type;
begin
if not Container.Contains (Current.Token) then
return False;
@@ -494,20 +442,24 @@ package body Packrat.Parse_Graphs is
function Is_Sorted
- (Finishes : in Finish_Array)
+ (Finishes : in Traits.Tokens.Finish_Array)
return Boolean
is
- function Actual is new Sorted (Finish_Type, Finish_Array);
+ function Actual is new Sorted
+ (Traits.Tokens.Finish_Type, Traits.Tokens.Finish_Array);
begin
return Actual (Finishes);
end Is_Sorted;
function Is_Sorted
- (Positions : in Finished_Token_Array)
+ (Positions : in Traits.Tokens.Finished_Token_Array)
return Boolean
is
- function Actual is new Sorted (Finished_Token, Finished_Token_Array);
+ function Actual is new Sorted
+ (Traits.Tokens.Finished_Token_Type,
+ Traits.Tokens.Finished_Token_Array,
+ Traits.Tokens."<");
begin
return Actual (Positions);
end Is_Sorted;
@@ -524,20 +476,24 @@ package body Packrat.Parse_Graphs is
function No_Duplicates
- (Finishes : in Finish_Array)
+ (Finishes : in Traits.Tokens.Finish_Array)
return Boolean
is
- function Actual is new No_Dups (Finish_Type, Finish_Array);
+ function Actual is new No_Dups
+ (Traits.Tokens.Finish_Type, Traits.Tokens.Finish_Array);
begin
return Actual (Finishes);
end No_Duplicates;
function No_Duplicates
- (Positions : in Finished_Token_Array)
+ (Positions : in Traits.Tokens.Finished_Token_Array)
return Boolean
is
- function Actual is new No_Dups (Finished_Token, Finished_Token_Array);
+ function Actual is new No_Dups
+ (Traits.Tokens.Finished_Token_Type,
+ Traits.Tokens.Finished_Token_Array,
+ Traits.Tokens."=");
begin
return Actual (Positions);
end No_Duplicates;
@@ -558,7 +514,7 @@ package body Packrat.Parse_Graphs is
procedure Include
(Container : in out Parse_Graph;
- Token : in Traits.Tokens.Token)
+ Token : in Traits.Tokens.Token_Type)
is
Node_ID : Node_ID_Type;
begin
@@ -572,8 +528,8 @@ package body Packrat.Parse_Graphs is
procedure Connect
(Container : in out Parse_Graph;
- Parent : in Finished_Token;
- Subtokens : in Finished_Token_Array)
+ Parent : in Traits.Tokens.Finished_Token_Type;
+ Subtokens : in Traits.Tokens.Finished_Token_Array)
is
Parent_ID : Node_ID_Type;
Use_GID : Group_ID_Type;
@@ -608,7 +564,7 @@ package body Packrat.Parse_Graphs is
procedure Prune
(Container : in out Parse_Graph;
- Token : in Traits.Tokens.Token) is
+ Token : in Traits.Tokens.Token_Type) is
begin
if not Container.Contains (Token) then
return;
@@ -625,8 +581,9 @@ package body Packrat.Parse_Graphs is
procedure Prune
(Container : in out Parse_Graph;
- Position : in Finished_Token)
+ Position : in Traits.Tokens.Finished_Token_Type)
is
+ use type Traits.Tokens.Finished_Token_Type;
Node : Node_ID_Type;
begin
if not Container.Contains (Position.Token) then
@@ -735,7 +692,7 @@ package body Packrat.Parse_Graphs is
procedure Set_Root
(Container : in out Parse_Graph;
- Tokens : in Finished_Token_Array) is
+ Tokens : in Traits.Tokens.Finished_Token_Array) is
begin
Container.Clear_Root;
for Fin_Token of Tokens loop
@@ -756,10 +713,12 @@ package body Packrat.Parse_Graphs is
function Root_Elements
(Container : in Parse_Graph)
- return Finished_Token_Array
+ return Traits.Tokens.Finished_Token_Array
is
function V2A is new Vector_To_Array
- (Finished_Token, Finished_Token_Array, Finished_Token_Vectors);
+ (Traits.Tokens.Finished_Token_Type,
+ Traits.Tokens.Finished_Token_Array,
+ Finished_Token_Vectors);
begin
return V2A (Container.Root_Elems);
end Root_Elements;
@@ -770,10 +729,11 @@ package body Packrat.Parse_Graphs is
function Finish_List
(Container : in Parse_Graph;
- Token : in Traits.Tokens.Token)
- return Finish_Array
+ Token : in Traits.Tokens.Token_Type)
+ return Traits.Tokens.Finish_Array
is
- function V2A is new Vector_To_Array (Finish_Type, Finish_Array, Finish_Vectors);
+ function V2A is new Vector_To_Array
+ (Traits.Tokens.Finish_Type, Traits.Tokens.Finish_Array, Finish_Vectors);
Result : Finish_Vectors.Vector;
begin
for Fin_Token of Container.Root_Elems loop
@@ -793,7 +753,7 @@ package body Packrat.Parse_Graphs is
function Is_Leaf
(Container : in Parse_Graph;
- Position : in Finished_Token)
+ Position : in Traits.Tokens.Finished_Token_Type)
return Boolean is
begin
for Edge of Container.Internal_Graph.Outbound
@@ -809,7 +769,7 @@ package body Packrat.Parse_Graphs is
function Is_Branch
(Container : in Parse_Graph;
- Position : in Finished_Token)
+ Position : in Traits.Tokens.Finished_Token_Type)
return Boolean is
begin
return not Container.Is_Leaf (Position);
@@ -821,14 +781,14 @@ package body Packrat.Parse_Graphs is
function Subgroups
(Container : in Parse_Graph;
- Position : in Finished_Token)
+ Position : in Traits.Tokens.Finished_Token_Type)
return Token_Group_Array
is
function V2A is new Vector_To_Array
(Token_Group, Token_Group_Array, Token_Group_Vectors);
Groupings : Group_Finished_Token_Maps.Map;
Edge_Label : Edge_Label_Type;
- Next_Token : Finished_Token;
+ Next_Token : Traits.Tokens.Finished_Token_Type;
Result : Token_Group_Vectors.Vector;
begin
for Edge of Container.Internal_Graph.Outbound
@@ -883,7 +843,7 @@ package body Packrat.Parse_Graphs is
function Element
(Grouping : in Token_Group;
Index : in Positive)
- return Finished_Token is
+ return Traits.Tokens.Finished_Token_Type is
begin
return Grouping.Elems.Element (Index);
end Element;
@@ -891,10 +851,12 @@ package body Packrat.Parse_Graphs is
function Elements
(Grouping : in Token_Group)
- return Finished_Token_Array
+ return Traits.Tokens.Finished_Token_Array
is
function V2A is new Vector_To_Array
- (Finished_Token, Finished_Token_Array, Finished_Token_Vectors);
+ (Traits.Tokens.Finished_Token_Type,
+ Traits.Tokens.Finished_Token_Array,
+ Finished_Token_Vectors);
begin
return V2A (Grouping.Elems);
end Elements;
@@ -902,7 +864,7 @@ package body Packrat.Parse_Graphs is
function Parent
(Grouping : in Token_Group)
- return Finished_Token is
+ return Traits.Tokens.Finished_Token_Type is
begin
return Grouping.Parent;
end Parent;
@@ -910,7 +872,7 @@ package body Packrat.Parse_Graphs is
function Finish
(Grouping : in Token_Group)
- return Finish_Type is
+ return Traits.Tokens.Finish_Type is
begin
return Grouping.Parent.Finish;
end Finish;
@@ -959,13 +921,15 @@ package body Packrat.Parse_Graphs is
function Ambiguities
(Container : in Parse_Graph;
Ambiguous_Root : out Boolean)
- return Finished_Token_Array
+ return Traits.Tokens.Finished_Token_Array
is
function V2A is new Vector_To_Array
- (Finished_Token, Finished_Token_Array, Finished_Token_Vectors);
+ (Traits.Tokens.Finished_Token_Type,
+ Traits.Tokens.Finished_Token_Array,
+ Finished_Token_Vectors);
Seen_Finishes : Finish_Group_Maps.Map;
Edge_Label : Edge_Label_Type;
- Next_Token : Finished_Token;
+ Next_Token : Traits.Tokens.Finished_Token_Type;
Result : Finished_Token_Vectors.Vector;
begin
Ambiguous_Root := Container.Has_Root and then Container.Is_Root_Ambiguous;
@@ -1037,9 +1001,9 @@ package body Packrat.Parse_Graphs is
function Token_Isomorph
(Left_Graph : in Parse_Graph;
- Left_Position : in Finished_Token;
+ Left_Position : in Traits.Tokens.Finished_Token_Type;
Right_Graph : in Parse_Graph;
- Right_Position : in Finished_Token;
+ Right_Position : in Traits.Tokens.Finished_Token_Type;
Offset : in Integer;
Mapping : in out Isomorph_Maps.Map)
return Boolean
@@ -1115,9 +1079,9 @@ package body Packrat.Parse_Graphs is
function Isomorphic_Subgraph
(Left_Graph : in Parse_Graph;
- Left_Position : in Finished_Token;
+ Left_Position : in Traits.Tokens.Finished_Token_Type;
Right_Graph : in Parse_Graph;
- Right_Position : in Finished_Token)
+ Right_Position : in Traits.Tokens.Finished_Token_Type)
return Boolean
is
Offset : Integer :=
@@ -1136,7 +1100,7 @@ package body Packrat.Parse_Graphs is
function To_Node
(Container : in Parse_Graph;
- Token : in Traits.Tokens.Token)
+ Token : in Traits.Tokens.Token_Type)
return Node_ID_Type is
begin
return Container.Label_Map.Element (Token);
@@ -1145,7 +1109,7 @@ package body Packrat.Parse_Graphs is
function To_Node
(Container : in Parse_Graph;
- Position : in Finished_Token)
+ Position : in Traits.Tokens.Finished_Token_Type)
return Node_ID_Type is
begin
return Container.Label_Map.Element (Position.Token);
diff --git a/src/packrat-parse_graphs.ads b/src/packrat-parse_graphs.ads
index 208292c..7d14652 100644
--- a/src/packrat-parse_graphs.ads
+++ b/src/packrat-parse_graphs.ads
@@ -27,26 +27,7 @@ package Packrat.Parse_Graphs is
Empty_Graph : constant Parse_Graph;
- subtype Finish_Type is Natural;
- type Finish_Array is array (Positive range <>) of Finish_Type;
-
- type Finished_Token is record
- Token : Traits.Tokens.Token;
- Finish : Finish_Type;
- end record;
-
- type Finished_Token_Array is array (Positive range <>) of Finished_Token;
-
- function "<"
- (Left, Right : in Finished_Token)
- return Boolean;
-
- function "<"
- (Left, Right : in Finished_Token_Array)
- return Boolean;
-
- use type Ada.Containers.Count_Type;
- type Token_Group is private with Type_Invariant => Length (Token_Group) > 0;
+ type Token_Group is private with Type_Invariant => Integer (Length (Token_Group)) > 0;
type Token_Group_Array is array (Positive range <>) of Token_Group;
function "<"
@@ -89,12 +70,12 @@ package Packrat.Parse_Graphs is
function Contains
(Container : in Parse_Graph;
- Token : in Traits.Tokens.Token)
+ Token : in Traits.Tokens.Token_Type)
return Boolean;
function Contains
(Container : in Parse_Graph;
- Position : in Finished_Token)
+ Position : in Traits.Tokens.Finished_Token_Type)
return Boolean;
function Contains
@@ -104,7 +85,7 @@ package Packrat.Parse_Graphs is
function Reachable
(Container : in Parse_Graph;
- Position : in Finished_Token)
+ Position : in Traits.Tokens.Finished_Token_Type)
return Boolean
with Pre => Container.Has_Root;
@@ -114,29 +95,29 @@ package Packrat.Parse_Graphs is
with Pre => Container.Has_Root;
function Valid_Token
- (Fin_Token : in Finished_Token)
+ (Fin_Token : in Traits.Tokens.Finished_Token_Type)
return Boolean;
function Valid_Starts_Finishes
- (Parent : in Finished_Token;
- Subtokens : in Finished_Token_Array)
+ (Parent : in Traits.Tokens.Finished_Token_Type;
+ Subtokens : in Traits.Tokens.Finished_Token_Array)
return Boolean
with Pre => Subtokens'Length > 0;
function Loops_Introduced
(Container : in Parse_Graph;
- Parent : in Finished_Token;
- Subtokens : in Finished_Token_Array)
+ Parent : in Traits.Tokens.Finished_Token_Type;
+ Subtokens : in Traits.Tokens.Finished_Token_Array)
return Boolean
with Pre => Subtokens'Length > 0 and
Valid_Starts_Finishes (Parent, Subtokens);
function Is_Sorted
- (Finishes : in Finish_Array)
+ (Finishes : in Traits.Tokens.Finish_Array)
return Boolean;
function Is_Sorted
- (Positions : in Finished_Token_Array)
+ (Positions : in Traits.Tokens.Finished_Token_Array)
return Boolean;
function Is_Sorted
@@ -144,11 +125,11 @@ package Packrat.Parse_Graphs is
return Boolean;
function No_Duplicates
- (Finishes : in Finish_Array)
+ (Finishes : in Traits.Tokens.Finish_Array)
return Boolean;
function No_Duplicates
- (Positions : in Finished_Token_Array)
+ (Positions : in Traits.Tokens.Finished_Token_Array)
return Boolean;
function No_Duplicates
@@ -160,25 +141,25 @@ package Packrat.Parse_Graphs is
procedure Include
(Container : in out Parse_Graph;
- Token : in Traits.Tokens.Token)
+ Token : in Traits.Tokens.Token_Type)
with Post => Container.Contains (Token);
procedure Connect
(Container : in out Parse_Graph;
- Parent : in Finished_Token;
- Subtokens : in Finished_Token_Array)
+ Parent : in Traits.Tokens.Finished_Token_Type;
+ Subtokens : in Traits.Tokens.Finished_Token_Array)
with Pre => Subtokens'Length > 0 and
Valid_Starts_Finishes (Parent, Subtokens) and
not Container.Loops_Introduced (Parent, Subtokens);
procedure Prune
(Container : in out Parse_Graph;
- Token : in Traits.Tokens.Token)
+ Token : in Traits.Tokens.Token_Type)
with Post => not Container.Contains (Token);
procedure Prune
(Container : in out Parse_Graph;
- Position : in Finished_Token)
+ Position : in Traits.Tokens.Finished_Token_Type)
with Post => not Container.Contains (Position);
procedure Prune
@@ -200,7 +181,7 @@ package Packrat.Parse_Graphs is
procedure Set_Root
(Container : in out Parse_Graph;
- Tokens : in Finished_Token_Array)
+ Tokens : in Traits.Tokens.Finished_Token_Array)
with Pre => (for all F of Tokens => Container.Contains (F.Token)),
Post => Container.Has_Root;
@@ -210,7 +191,7 @@ package Packrat.Parse_Graphs is
function Root_Elements
(Container : in Parse_Graph)
- return Finished_Token_Array
+ return Traits.Tokens.Finished_Token_Array
with Pre => Container.Has_Root;
@@ -218,21 +199,21 @@ package Packrat.Parse_Graphs is
function Finish_List
(Container : in Parse_Graph;
- Token : in Traits.Tokens.Token)
- return Finish_Array
+ Token : in Traits.Tokens.Token_Type)
+ return Traits.Tokens.Finish_Array
with Pre => Container.Contains (Token),
Post => Is_Sorted (Finish_List'Result) and
No_Duplicates (Finish_List'Result);
function Is_Leaf
(Container : in Parse_Graph;
- Position : in Finished_Token)
+ Position : in Traits.Tokens.Finished_Token_Type)
return Boolean
with Pre => Container.Contains (Position);
function Is_Branch
(Container : in Parse_Graph;
- Position : in Finished_Token)
+ Position : in Traits.Tokens.Finished_Token_Type)
return Boolean
with Pre => Container.Contains (Position);
@@ -241,7 +222,7 @@ package Packrat.Parse_Graphs is
function Subgroups
(Container : in Parse_Graph;
- Position : in Finished_Token)
+ Position : in Traits.Tokens.Finished_Token_Type)
return Token_Group_Array
with Pre => Container.Contains (Position),
Post => Is_Sorted (Subgroups'Result) and
@@ -263,22 +244,22 @@ package Packrat.Parse_Graphs is
function Element
(Grouping : in Token_Group;
Index : in Positive)
- return Finished_Token
+ return Traits.Tokens.Finished_Token_Type
with Pre => Index in First_Index (Grouping) .. Last_Index (Grouping);
function Elements
(Grouping : in Token_Group)
- return Finished_Token_Array
+ return Traits.Tokens.Finished_Token_Array
with Post => Is_Sorted (Elements'Result) and
Valid_Starts_Finishes (Parent (Grouping), Elements'Result);
function Parent
(Grouping : in Token_Group)
- return Finished_Token;
+ return Traits.Tokens.Finished_Token_Type;
function Finish
(Grouping : in Token_Group)
- return Finish_Type;
+ return Traits.Tokens.Finish_Type;
@@ -300,7 +281,7 @@ package Packrat.Parse_Graphs is
function Ambiguities
(Container : in Parse_Graph;
Ambiguous_Root : out Boolean)
- return Finished_Token_Array
+ return Traits.Tokens.Finished_Token_Array
with Post => Is_Sorted (Ambiguities'Result) and
No_Duplicates (Ambiguities'Result);
@@ -314,9 +295,9 @@ package Packrat.Parse_Graphs is
function Isomorphic_Subgraph
(Left_Graph : in Parse_Graph;
- Left_Position : in Finished_Token;
+ Left_Position : in Traits.Tokens.Finished_Token_Type;
Right_Graph : in Parse_Graph;
- Right_Position : in Finished_Token)
+ Right_Position : in Traits.Tokens.Finished_Token_Type)
return Boolean
with Pre => Left_Graph.Contains (Left_Position) and
Right_Graph.Contains (Right_Position);
@@ -335,14 +316,14 @@ private
type Node_ID_Type is new Positive;
type Edge_ID_Type is new Positive;
- subtype Node_Label_Type is Traits.Tokens.Token;
+ subtype Node_Label_Type is Traits.Tokens.Token_Type;
subtype Group_ID_Type is Positive;
type Edge_Label_Type is record
Group_ID : Group_ID_Type;
- Group_Finish : Finish_Type;
- Subnode_Finish : Finish_Type;
+ Group_Finish : Traits.Tokens.Finish_Type;
+ Subnode_Finish : Traits.Tokens.Finish_Type;
end record;
@@ -350,12 +331,12 @@ private
function To_Node
(Container : in Parse_Graph;
- Token : in Traits.Tokens.Token)
+ Token : in Traits.Tokens.Token_Type)
return Node_ID_Type;
function To_Node
(Container : in Parse_Graph;
- Position : in Finished_Token)
+ Position : in Traits.Tokens.Finished_Token_Type)
return Node_ID_Type;
function Locally_Reachable
@@ -368,7 +349,7 @@ private
-- This 'use type' is to avoid some ambiguities with "=" functions when
-- instantiating the Base package.
- use type Traits.Tokens.Token;
+ use type Traits.Tokens.Token_Type;
package Base is new Directed_Graphs
(Node_ID_Type => Node_ID_Type,
@@ -382,14 +363,15 @@ private
package Finished_Token_Vectors is new Ada.Containers.Vectors
(Index_Type => Positive,
- Element_Type => Finished_Token);
+ Element_Type => Traits.Tokens.Finished_Token_Type,
+ "=" => Traits.Tokens."=");
function "<"
(Left, Right : in Finished_Token_Vectors.Vector)
return Boolean;
type Token_Group is record
- Parent : Finished_Token;
+ Parent : Traits.Tokens.Finished_Token_Type;
Elems : Finished_Token_Vectors.Vector;
end record;
@@ -399,13 +381,14 @@ private
package Finish_Vectors is new Ada.Containers.Vectors
(Index_Type => Positive,
- Element_Type => Finish_Type);
+ Element_Type => Traits.Tokens.Finish_Type);
package Finish_Sort is new Finish_Vectors.Generic_Sorting;
package Node_Label_Maps is new Ada.Containers.Ordered_Maps
- (Key_Type => Traits.Tokens.Token,
- Element_Type => Node_ID_Type);
+ (Key_Type => Traits.Tokens.Token_Type,
+ Element_Type => Node_ID_Type,
+ "<" => Traits.Tokens."<");
type Parse_Graph is tagged record
Internal_Graph : Base.Graph := Base.Empty_Graph;
@@ -429,7 +412,8 @@ private
(Index_Type => Positive,
Element_Type => Token_Group);
- package Finished_Token_Sort is new Finished_Token_Vectors.Generic_Sorting;
+ package Finished_Token_Sort is new
+ Finished_Token_Vectors.Generic_Sorting ("<" => Traits.Tokens."<");
package Token_Group_Sort is new Token_Group_Vectors.Generic_Sorting;
package Group_Finished_Token_Maps is new Ada.Containers.Ordered_Maps
@@ -438,7 +422,7 @@ private
"=" => Finished_Token_Vectors."=");
package Finish_Group_Maps is new Ada.Containers.Ordered_Maps
- (Key_Type => Finish_Type,
+ (Key_Type => Traits.Tokens.Finish_Type,
Element_Type => Group_ID_Type);
package Enum_Node_Maps is new Ada.Containers.Ordered_Maps
@@ -451,9 +435,10 @@ private
package Isomorph_Maps is new Ada.Containers.Ordered_Maps
- (Key_Type => Finished_Token,
+ (Key_Type => Traits.Tokens.Finished_Token_Type,
Element_Type => Finished_Token_Vectors.Vector,
- "=" => Finished_Token_Vectors."=");
+ "=" => Finished_Token_Vectors."=",
+ "<" => Traits.Tokens."<");
function Group_Isomorph
(Left_Graph : in Parse_Graph;
@@ -466,9 +451,9 @@ private
function Token_Isomorph
(Left_Graph : in Parse_Graph;
- Left_Position : in Finished_Token;
+ Left_Position : in Traits.Tokens.Finished_Token_Type;
Right_Graph : in Parse_Graph;
- Right_Position : in Finished_Token;
+ Right_Position : in Traits.Tokens.Finished_Token_Type;
Offset : in Integer;
Mapping : in out Isomorph_Maps.Map)
return Boolean;
diff --git a/src/packrat-parsers.adb b/src/packrat-parsers.adb
index d854f73..1a3935c 100644
--- a/src/packrat-parsers.adb
+++ b/src/packrat-parsers.adb
@@ -23,7 +23,7 @@ package body Packrat.Parsers is
(Left, Right : in Tok_Holds.Holder)
return Boolean
is
- use type Graphs.Finished_Token_Array;
+ use type Traits.Tokens.Finished_Token_Array;
begin
return Left.Element < Right.Element;
end "<";
@@ -86,10 +86,10 @@ package body Packrat.Parsers is
function Element
(Hold : in Tok_Holds.Holder)
- return Graphs.Finished_Token_Array is
+ return Traits.Tokens.Finished_Token_Array is
begin
if Hold.Is_Empty then
- return Value : Graphs.Finished_Token_Array (1 .. 0);
+ return Value : Traits.Tokens.Finished_Token_Array (1 .. 0);
else
return Hold.Element;
end if;
@@ -300,7 +300,7 @@ package body Packrat.Parsers is
return Combinator_Result
is
use type Traits.Element_Array;
- use type Graphs.Finished_Token_Array;
+ use type Traits.Tokens.Finished_Token_Array;
Salt, Temp : Combinator_Result;
Adjust : Result_Sets.Set;
begin
@@ -401,7 +401,7 @@ package body Packrat.Parsers is
return Graphs.Empty_Graph;
end if;
declare
- Root_Elems : Graphs.Finished_Token_Array (1 .. Length);
+ Root_Elems : Traits.Tokens.Finished_Token_Array (1 .. Length);
begin
for R of Root_Result.Results loop
for T of Element (R.Tokens) loop
@@ -538,7 +538,7 @@ package body Packrat.Parsers is
return Combinator_Result
is
Salt : Combinator_Result := Combo (Input, Context, Start);
- Current : Graphs.Finished_Token;
+ Current : Traits.Tokens.Finished_Token_Type;
Processed : Result_Sets.Set;
begin
if Salt.Status = Failure then
diff --git a/src/packrat-parsers.ads b/src/packrat-parsers.ads
index 93d06dd..03b262c 100644
--- a/src/packrat-parsers.ads
+++ b/src/packrat-parsers.ads
@@ -331,8 +331,8 @@ private
"=" => Traits."=");
package Tok_Holds is new Ada.Containers.Indefinite_Holders
- (Element_Type => Graphs.Finished_Token_Array,
- "=" => Graphs."=");
+ (Element_Type => Traits.Tokens.Finished_Token_Array,
+ "=" => Traits.Tokens."=");
function "<"
(Left, Right : in Elem_Holds.Holder)
@@ -348,7 +348,7 @@ private
function Element
(Hold : in Tok_Holds.Holder)
- return Graphs.Finished_Token_Array;
+ return Traits.Tokens.Finished_Token_Array;
diff --git a/src/packrat-standard.ads b/src/packrat-standard.ads
index bf0b815..b51804d 100644
--- a/src/packrat-standard.ads
+++ b/src/packrat-standard.ads
@@ -36,7 +36,7 @@ package Packrat.Standard is
package Parser_Traits is new Packrat.Traits
(Label_Enum => Parser_Labels,
- Element_Type => Lexer_Tokens.Token,
+ Element_Type => Lexer_Tokens.Token_Type,
Element_Array => Lexer_Tokens.Token_Array,
"<" => Lexer_Tokens."<");
diff --git a/src/packrat-tokens.adb b/src/packrat-tokens.adb
index 81d68c3..2e47db9 100644
--- a/src/packrat-tokens.adb
+++ b/src/packrat-tokens.adb
@@ -24,7 +24,7 @@ package body Packrat.Tokens is
function "<"
- (Left, Right : in Token)
+ (Left, Right : in Token_Type)
return Boolean is
begin
if Left.Start_At = Right.Start_At then
@@ -44,13 +44,48 @@ package body Packrat.Tokens is
return Boolean
is
function LT is new Array_Less_Than
- (Base_Type => Token,
+ (Base_Type => Token_Type,
Array_Type => Token_Array);
begin
return LT (Left, Right);
end "<";
+ function "<"
+ (Left, Right : Finished_Token_Type)
+ return Boolean
+ is
+ function LT is new Array_Less_Than
+ (Base_Type => Element_Type,
+ Array_Type => Element_Array);
+ begin
+ if Start (Left.Token) = Start (Right.Token) then
+ if Left.Finish = Right.Finish then
+ if Label (Left.Token) = Label (Right.Token) then
+ return Value (Left.Token) < Value (Right.Token);
+ else
+ return Label (Left.Token) < Label (Right.Token);
+ end if;
+ else
+ return Left.Finish < Right.Finish;
+ end if;
+ else
+ return Start (Left.Token) < Start (Right.Token);
+ end if;
+ end "<";
+
+
+ function "<"
+ (Left, Right : in Finished_Token_Array)
+ return Boolean
+ is
+ function LT is new Array_Less_Than
+ (Base_Type => Finished_Token_Type,
+ Array_Type => Finished_Token_Array);
+ begin
+ return LT (Left, Right);
+ end "<";
+
@@ -58,9 +93,9 @@ package body Packrat.Tokens is
(Ident : in Label_Enum;
Start : in Positive;
Value : in Element_Array)
- return Token is
+ return Token_Type is
begin
- return This : Token do
+ return This : Token_Type do
This.Identifier := Ident;
This.Start_At := Start;
This.Token_Value := Value_Holders.To_Holder (Value);
@@ -72,7 +107,7 @@ package body Packrat.Tokens is
function Debug_String
- (This : in Token)
+ (This : in Token_Type)
return String
is
Result : SU.Unbounded_String := +"";
@@ -84,11 +119,26 @@ package body Packrat.Tokens is
end Debug_String;
+ function Debug_String
+ (This : in Finished_Token_Type)
+ return String
+ is
+ Result : SU.Unbounded_String := +"";
+ begin
+ SU.Append (Result, "Token " & Label_Enum'Image (This.Token.Identifier) &
+ " at input position" & Integer'Image (This.Token.Start_At) & " to" &
+ Integer'Image (This.Finish) & " with value length" &
+ Integer'Image (This.Token.Token_Value.Constant_Reference.Element'Length) &
+ Latin.LF);
+ return -Result;
+ end Debug_String;
+
+
function Label
- (This : in Token)
+ (This : in Token_Type)
return Label_Enum is
begin
return This.Identifier;
@@ -96,7 +146,7 @@ package body Packrat.Tokens is
function Start
- (This : in Token)
+ (This : in Token_Type)
return Positive is
begin
return This.Start_At;
@@ -104,7 +154,7 @@ package body Packrat.Tokens is
function Value
- (This : in Token)
+ (This : in Token_Type)
return Element_Array is
begin
return This.Token_Value.Element;
@@ -115,7 +165,7 @@ package body Packrat.Tokens is
function Is_Label
- (This : in Token)
+ (This : in Token_Type)
return Boolean is
begin
return This.Identifier = Ident;
@@ -123,7 +173,7 @@ package body Packrat.Tokens is
function Is_Start
- (This : in Token)
+ (This : in Token_Type)
return Boolean is
begin
return This.Start_At = Start;
@@ -131,7 +181,7 @@ package body Packrat.Tokens is
function Is_Value
- (This : in Token)
+ (This : in Token_Type)
return Boolean is
begin
return This.Token_Value.Element = Value;
diff --git a/src/packrat-tokens.ads b/src/packrat-tokens.ads
index b731b13..5018610 100644
--- a/src/packrat-tokens.ads
+++ b/src/packrat-tokens.ads
@@ -17,65 +17,96 @@ generic
package Packrat.Tokens is
- type Token is private;
- type Token_Array is array (Positive range <>) of Token;
+ type Token_Type is private;
+ type Token_Array is array (Positive range <>) of Token_Type;
+
+ subtype Finish_Type is Natural;
+ type Finish_Array is array (Positive range <>) of Finish_Type;
+
+ type Finished_Token_Type is record
+ Token : Token_Type;
+ Finish : Finish_Type;
+ end record;
+
+ type Finished_Token_Array is array (Positive range <>) of Finished_Token_Type;
+
+
function "<"
- (Left, Right : in Token)
+ (Left, Right : in Token_Type)
return Boolean;
function "<"
(Left, Right : in Token_Array)
return Boolean;
+ function "<"
+ (Left, Right : in Finished_Token_Type)
+ return Boolean;
+
+ function "<"
+ (Left, Right : in Finished_Token_Array)
+ return Boolean;
+
+
+
+
+ -- Note: The Start index indicates where the token was found
+ -- in whatever array it was lexed from. The Value does *not*
+ -- have to correspond with whatever is found there.
function Create
(Ident : in Label_Enum;
Start : in Positive;
Value : in Element_Array)
- return Token;
+ return Token_Type;
- -- Note: The Start index indicates where the token was found
- -- in whatever array it was lexed from. The Value does *not*
- -- have to correspond with whatever is found there.
function Debug_String
- (This : in Token)
+ (This : in Token_Type)
return String;
+ function Debug_String
+ (This : in Finished_Token_Type)
+ return String;
+
+
+
function Label
- (This : in Token)
+ (This : in Token_Type)
return Label_Enum;
function Start
- (This : in Token)
+ (This : in Token_Type)
return Positive;
function Value
- (This : in Token)
+ (This : in Token_Type)
return Element_Array;
+
+
generic
Ident : in Label_Enum;
function Is_Label
- (This : in Token)
+ (This : in Token_Type)
return Boolean;
generic
Start : in Positive;
function Is_Start
- (This : in Token)
+ (This : in Token_Type)
return Boolean;
generic
Value : in Element_Array;
function Is_Value
- (This : in Token)
+ (This : in Token_Type)
return Boolean;
@@ -90,7 +121,7 @@ private
return Boolean;
- type Token is record
+ type Token_Type is record
Identifier : Label_Enum;
Start_At : Positive;
Token_Value : Value_Holders.Holder;
diff --git a/test/packrat-lexers-debug.adb b/test/packrat-lexers-debug.adb
index d748fd4..f7121e1 100644
--- a/test/packrat-lexers-debug.adb
+++ b/test/packrat-lexers-debug.adb
@@ -91,7 +91,7 @@ package body Packrat.Lexers.Debug is
function Element
(Vec : in Token_Vector;
Dex : in Positive)
- return Traits.Tokens.Token is
+ return Traits.Tokens.Token_Type is
begin
return Token_Vectors.Vector (Vec).Element (Dex);
end Element;
diff --git a/test/packrat-lexers-debug.ads b/test/packrat-lexers-debug.ads
index 0dace45..0a8d1fe 100644
--- a/test/packrat-lexers-debug.ads
+++ b/test/packrat-lexers-debug.ads
@@ -63,7 +63,7 @@ package Packrat.Lexers.Debug is
function Element
(Vec : in Token_Vector;
Dex : in Positive)
- return Traits.Tokens.Token;
+ return Traits.Tokens.Token_Type;
diff --git a/test/rat_tests-lexers.adb b/test/rat_tests-lexers.adb
index 95324a9..e216461 100644
--- a/test/rat_tests-lexers.adb
+++ b/test/rat_tests-lexers.adb
@@ -555,7 +555,7 @@ package body Rat_Tests.Lexers is
function Stamp_Check
return Test_Result
is
- use type Slexy_Traits.Tokens.Token;
+ use type Slexy_Traits.Tokens.Token_Type;
use type Packrat.Result_Status;
use type Slexy.Component_Result;
@@ -654,7 +654,7 @@ package body Rat_Tests.Lexers is
package Swordy is new Packrat.Lexers (Swordy_Traits);
package Swolbug is new Swordy.Debug;
- use type Swordy_Traits.Tokens.Token;
+ use type Swordy_Traits.Tokens.Token_Type;
use type Swordy_Traits.Tokens.Token_Array;
function Satisfy_Letter is new Swordy.Satisfy (PU.Is_Letter);
diff --git a/test/rat_tests-parse_graphs.adb b/test/rat_tests-parse_graphs.adb
index 5cc0edb..06f977b 100644
--- a/test/rat_tests-parse_graphs.adb
+++ b/test/rat_tests-parse_graphs.adb
@@ -21,31 +21,31 @@ package body Rat_Tests.Parse_Graphs is
-- These tokens are defined here purely to reduce verbosity when
-- manually constructing the various test graphs in the package initialisation.
- Noun_1 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Noun, 1, "i");
- Noun_4 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Noun, 4, "man");
- Noun_7 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Noun, 7, "park");
- Noun_10 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Noun, 10, "bat");
+ Noun_1 : My_Traits.Tokens.Token_Type := My_Traits.Tokens.Create (Noun, 1, "i");
+ Noun_4 : My_Traits.Tokens.Token_Type := My_Traits.Tokens.Create (Noun, 4, "man");
+ Noun_7 : My_Traits.Tokens.Token_Type := My_Traits.Tokens.Create (Noun, 7, "park");
+ Noun_10 : My_Traits.Tokens.Token_Type := My_Traits.Tokens.Create (Noun, 10, "bat");
- Det_3 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Determiner, 3, "a");
- Det_6 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Determiner, 6, "the");
- Det_9 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Determiner, 9, "a");
+ Det_3 : My_Traits.Tokens.Token_Type := My_Traits.Tokens.Create (Determiner, 3, "a");
+ Det_6 : My_Traits.Tokens.Token_Type := My_Traits.Tokens.Create (Determiner, 6, "the");
+ Det_9 : My_Traits.Tokens.Token_Type := My_Traits.Tokens.Create (Determiner, 9, "a");
- NP_1 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Noun_Phrase, 1, "");
- NP_3 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Noun_Phrase, 3, "");
- NP_6 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Noun_Phrase, 6, "");
- NP_9 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Noun_Phrase, 9, "");
+ NP_1 : My_Traits.Tokens.Token_Type := My_Traits.Tokens.Create (Noun_Phrase, 1, "");
+ NP_3 : My_Traits.Tokens.Token_Type := My_Traits.Tokens.Create (Noun_Phrase, 3, "");
+ NP_6 : My_Traits.Tokens.Token_Type := My_Traits.Tokens.Create (Noun_Phrase, 6, "");
+ NP_9 : My_Traits.Tokens.Token_Type := My_Traits.Tokens.Create (Noun_Phrase, 9, "");
- Prep_5 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Preposition, 5, "in");
- Prep_8 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Preposition, 8, "with");
+ Prep_5 : My_Traits.Tokens.Token_Type := My_Traits.Tokens.Create (Preposition, 5, "in");
+ Prep_8 : My_Traits.Tokens.Token_Type := My_Traits.Tokens.Create (Preposition, 8, "with");
- PP_5 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Prepositional_Phrase, 5, "");
- PP_8 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Prepositional_Phrase, 8, "");
+ PP_5 : My_Traits.Tokens.Token_Type := My_Traits.Tokens.Create (Prepositional_Phrase, 5, "");
+ PP_8 : My_Traits.Tokens.Token_Type := My_Traits.Tokens.Create (Prepositional_Phrase, 8, "");
- Verb_2 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Verb, 2, "saw");
+ Verb_2 : My_Traits.Tokens.Token_Type := My_Traits.Tokens.Create (Verb, 2, "saw");
- VP_2 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Verb_Phrase, 2, "");
+ VP_2 : My_Traits.Tokens.Token_Type := My_Traits.Tokens.Create (Verb_Phrase, 2, "");
- Sen_1 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Sentence, 1, "");
+ Sen_1 : My_Traits.Tokens.Token_Type := My_Traits.Tokens.Create (Sentence, 1, "");
-- This should be set up to be identical to the example parse in the paper
@@ -62,13 +62,13 @@ package body Rat_Tests.Parse_Graphs is
-- A simple subgraph of the above, slid to start at position 1,
-- covering the phrase "in the park".
- Prep_1 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Preposition, 1, "in");
- Det_2 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Determiner, 2, "the");
- Noun_3 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Noun, 3, "park");
+ Prep_1 : My_Traits.Tokens.Token_Type := My_Traits.Tokens.Create (Preposition, 1, "in");
+ Det_2 : My_Traits.Tokens.Token_Type := My_Traits.Tokens.Create (Determiner, 2, "the");
+ Noun_3 : My_Traits.Tokens.Token_Type := My_Traits.Tokens.Create (Noun, 3, "park");
- NP_2 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Noun_Phrase, 2, "");
+ NP_2 : My_Traits.Tokens.Token_Type := My_Traits.Tokens.Create (Noun_Phrase, 2, "");
- PP_1 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Prepositional_Phrase, 1, "");
+ PP_1 : My_Traits.Tokens.Token_Type := My_Traits.Tokens.Create (Prepositional_Phrase, 1, "");
Slide_Graph : Graphs.Parse_Graph;
@@ -76,13 +76,13 @@ package body Rat_Tests.Parse_Graphs is
-- A slid version of Small_Graph, covering the same "saw a man" phrase.
- Verb_1 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Verb, 1, "saw");
- Det_2a : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Determiner, 2, "a");
- Noun_3a : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Noun, 3, "man");
+ Verb_1 : My_Traits.Tokens.Token_Type := My_Traits.Tokens.Create (Verb, 1, "saw");
+ Det_2a : My_Traits.Tokens.Token_Type := My_Traits.Tokens.Create (Determiner, 2, "a");
+ Noun_3a : My_Traits.Tokens.Token_Type := My_Traits.Tokens.Create (Noun, 3, "man");
-- NP_2 as above is fine
- VP_1 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Verb_Phrase, 1, "");
+ VP_1 : My_Traits.Tokens.Token_Type := My_Traits.Tokens.Create (Verb_Phrase, 1, "");
Slid_Small_Graph : Graphs.Parse_Graph;
@@ -299,8 +299,8 @@ package body Rat_Tests.Parse_Graphs is
function Is_Sorted_Check
return Test_Result
is
- Test_1 : Graphs.Finish_Array := (1, 3, 5, 6, 7, 11);
- Test_2 : Graphs.Finish_Array := (3, 5, 2, 8, 4, 10);
+ Test_1 : My_Traits.Tokens.Finish_Array := (1, 3, 5, 6, 7, 11);
+ Test_2 : My_Traits.Tokens.Finish_Array := (3, 5, 2, 8, 4, 10);
begin
if not Graphs.Is_Sorted (Test_1) or
Graphs.Is_Sorted (Test_2)
@@ -314,8 +314,8 @@ package body Rat_Tests.Parse_Graphs is
function No_Duplicates_Check
return Test_Result
is
- Test_1 : Graphs.Finish_Array := (1, 2, 3, 4, 8, 10, 5);
- Test_2 : Graphs.Finish_Array := (5, 6, 8, 2, 4, 5, 5, 8);
+ Test_1 : My_Traits.Tokens.Finish_Array := (1, 2, 3, 4, 8, 10, 5);
+ Test_2 : My_Traits.Tokens.Finish_Array := (5, 6, 8, 2, 4, 5, 5, 8);
begin
if not Graphs.No_Duplicates (Test_1) or
Graphs.No_Duplicates (Test_2)
@@ -371,8 +371,8 @@ package body Rat_Tests.Parse_Graphs is
function Prune_Check
return Test_Result
is
- use type My_Traits.Tokens.Token;
- use type Graphs.Finished_Token_Array;
+ use type My_Traits.Tokens.Token_Type;
+ use type My_Traits.Tokens.Finished_Token_Array;
Paper : Graphs.Parse_Graph := Paper_Graph;
begin
if not Paper.Contains (Prep_5) then
@@ -465,7 +465,7 @@ package body Rat_Tests.Parse_Graphs is
function Root_Elements_Check
return Test_Result
is
- use type Graphs.Finished_Token_Array;
+ use type My_Traits.Tokens.Finished_Token_Array;
begin
if Paper_Graph.Root_Elements /= ((Sen_1, 4), (Sen_1, 7), (Sen_1, 10)) then
return Fail;
@@ -480,7 +480,7 @@ package body Rat_Tests.Parse_Graphs is
function Finish_List_Check
return Test_Result
is
- use type Graphs.Finish_Array;
+ use type My_Traits.Tokens.Finish_Array;
begin
if Paper_Graph.Finish_List (Sen_1) /= (4, 7, 10) or
Paper_Graph.Finish_List (NP_3) /= (4, 7, 10) or
@@ -528,7 +528,7 @@ package body Rat_Tests.Parse_Graphs is
return Test_Result
is
use type Ada.Containers.Count_Type;
- use type Graphs.Finished_Token_Array;
+ use type My_Traits.Tokens.Finished_Token_Array;
Paper : Graphs.Token_Group_Array := Paper_Graph.Subgroups ((NP_3, 10));
Extra : Graphs.Token_Group_Array := Paper_Graph.Subgroups ((NP_1, 1));
begin
@@ -629,7 +629,7 @@ package body Rat_Tests.Parse_Graphs is
function Element_Check
return Test_Result
is
- use type Graphs.Finished_Token;
+ use type My_Traits.Tokens.Finished_Token_Type;
Paper : Graphs.Token_Group_Array := Paper_Graph.Subgroups ((NP_3, 10));
begin
if Graphs.Element (Paper (1), 1) /= (NP_3, 4) or
@@ -644,7 +644,7 @@ package body Rat_Tests.Parse_Graphs is
function Elements_Check
return Test_Result
is
- use type Graphs.Finished_Token_Array;
+ use type My_Traits.Tokens.Finished_Token_Array;
Paper : Graphs.Token_Group_Array := Paper_Graph.Subgroups ((NP_3, 10));
begin
if Graphs.Elements (Paper (1)) /= ((NP_3, 4), (PP_5, 10)) or
@@ -659,7 +659,7 @@ package body Rat_Tests.Parse_Graphs is
function Parent_Check
return Test_Result
is
- use type Graphs.Finished_Token;
+ use type My_Traits.Tokens.Finished_Token_Type;
Paper_1 : Graphs.Token_Group_Array := Paper_Graph.Subgroups ((Sen_1, 4));
Paper_2 : Graphs.Token_Group_Array := Paper_Graph.Subgroups ((NP_3, 10));
Paper_3 : Graphs.Token_Group_Array := Paper_Graph.Subgroups ((NP_1, 1));
@@ -680,7 +680,7 @@ package body Rat_Tests.Parse_Graphs is
function Finish_Check
return Test_Result
is
- use type Graphs.Finish_Type;
+ use type My_Traits.Tokens.Finish_Type;
Paper_1 : Graphs.Token_Group_Array := Paper_Graph.Subgroups ((Sen_1, 4));
Paper_2 : Graphs.Token_Group_Array := Paper_Graph.Subgroups ((NP_3, 10));
Paper_3 : Graphs.Token_Group_Array := Paper_Graph.Subgroups ((NP_1, 1));
@@ -731,19 +731,19 @@ package body Rat_Tests.Parse_Graphs is
function Ambiguities_Check
return Test_Result
is
- use type Graphs.Finished_Token_Array;
+ use type My_Traits.Tokens.Finished_Token_Array;
Paper_Root, Small_Root, Slide_Root : Boolean;
- Paper_Result : Graphs.Finished_Token_Array :=
+ Paper_Result : My_Traits.Tokens.Finished_Token_Array :=
Paper_Graph.Ambiguities (Paper_Root);
- Small_Result : Graphs.Finished_Token_Array :=
+ Small_Result : My_Traits.Tokens.Finished_Token_Array :=
Small_Graph.Ambiguities (Small_Root);
- Slide_Result : Graphs.Finished_Token_Array :=
+ Slide_Result : My_Traits.Tokens.Finished_Token_Array :=
Slide_Graph.Ambiguities (Slide_Root);
-- Result is expected to be sorted
- Expected_Paper_Result : Graphs.Finished_Token_Array :=
+ Expected_Paper_Result : My_Traits.Tokens.Finished_Token_Array :=
((Sen_1, 7), (Sen_1, 10), (NP_3, 10));
begin
if Paper_Result /= Expected_Paper_Result or
@@ -795,7 +795,7 @@ begin
-- Constructing the various test graphs
Paper_Graph.Connect ((NP_1, 1),
- (1 => Graphs.Finished_Token'(Noun_1, 1)));
+ (1 => My_Traits.Tokens.Finished_Token_Type'(Noun_1, 1)));
Paper_Graph.Connect ((NP_3, 4),
((Det_3, 3), (Noun_4, 4)));
Paper_Graph.Connect ((NP_3, 7),
diff --git a/test/rat_tests-tokens.adb b/test/rat_tests-tokens.adb
index 74a3c0a..95fe5ff 100644
--- a/test/rat_tests-tokens.adb
+++ b/test/rat_tests-tokens.adb
@@ -17,10 +17,10 @@ package body Rat_Tests.Tokens is
function Adjust_Check
return Test_Result
is
- A : My_Tokens.Token;
+ A : My_Tokens.Token_Type;
begin
declare
- B : My_Tokens.Token := My_Tokens.Create (One, 1, "abc");
+ B : My_Tokens.Token_Type := My_Tokens.Create (One, 1, "abc");
begin
A := B;
end;
@@ -37,9 +37,9 @@ package body Rat_Tests.Tokens is
function Equals_Check
return Test_Result
is
- use type My_Tokens.Token;
- A : My_Tokens.Token := My_Tokens.Create (One, 1, "abc");
- B : My_Tokens.Token := My_Tokens.Create (One, 1, "abc");
+ use type My_Tokens.Token_Type;
+ A : My_Tokens.Token_Type := My_Tokens.Create (One, 1, "abc");
+ B : My_Tokens.Token_Type := My_Tokens.Create (One, 1, "abc");
begin
if A /= B then
return Fail;
@@ -54,7 +54,7 @@ package body Rat_Tests.Tokens is
function Store_Check
return Test_Result
is
- T : My_Tokens.Token := My_Tokens.Create (One, 1, "abc");
+ T : My_Tokens.Token_Type := My_Tokens.Create (One, 1, "abc");
begin
if My_Tokens.Label (T) /= One or else
My_Tokens.Start (T) /= 1 or else
diff --git a/test/test_main.adb b/test/test_main.adb
index af59fdf..1edf4e6 100644
--- a/test/test_main.adb
+++ b/test/test_main.adb
@@ -44,7 +44,7 @@ procedure Test_Main is
package My_Tokens is new Packrat.Tokens (My_Labels, Character, String);
Err : Packrat.Errors.Error_Message := Packrat.Errors.Encode ("A", 1);
- Tok : My_Tokens.Token := My_Tokens.Create (A, 1, "abc");
+ Tok : My_Tokens.Token_Type := My_Tokens.Create (A, 1, "abc");
begin