summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2019-01-10 00:11:30 +1100
committerJed Barber <jjbarber@y7mail.com>2019-01-10 00:11:30 +1100
commit7009e51c15ed51d716102540d5914e3d14a8a128 (patch)
tree6a271a11429758c4364e79a9d7b42a6feca44f8e
parent81f7e19f212f9d1ac75e04e62933e6c918219cfc (diff)
Debug_String functions added to Packrat.Errors and Packrat.Tokens
-rw-r--r--packrat_parser_lib_notes.txt16
-rw-r--r--src/packrat-errors.adb19
-rw-r--r--src/packrat-tokens.adb21
-rw-r--r--src/packrat.ads8
-rw-r--r--test/test_main.adb12
5 files changed, 62 insertions, 14 deletions
diff --git a/packrat_parser_lib_notes.txt b/packrat_parser_lib_notes.txt
index 8e98d56..d9aca31 100644
--- a/packrat_parser_lib_notes.txt
+++ b/packrat_parser_lib_notes.txt
@@ -206,18 +206,6 @@ Is_End_Of_Line
Is_Whitespace
Not_Whitespace
-(for syntax_trees)
-To_String
-Pretty_Print
-
-(for exception messages)
-To_String
-Pretty_Print
-
-(for tokens)
-To_String
-Pretty_Print
-
@@ -239,6 +227,8 @@ List of funcs:
Valid_Message
Valid_Identifier
Valid_Identifier_Array
+Debug_String
+
Join
Encode
Encode_Array
@@ -259,6 +249,7 @@ Token (tagged, controlled, but not limited)
List of funcs:
Create
Initialized
+Debug_String
Label
Value
@@ -274,6 +265,7 @@ List_of_datatypes:
Parse_Graph
List of funcs:
+Debug_String
diff --git a/src/packrat-errors.adb b/src/packrat-errors.adb
index d59e4c7..62a96a7 100644
--- a/src/packrat-errors.adb
+++ b/src/packrat-errors.adb
@@ -3,7 +3,8 @@
with
Ada.Strings.Fixed,
- Ada.Characters.Handling;
+ Ada.Characters.Handling,
+ Ada.Characters.Latin_1;
separate (Packrat)
@@ -13,6 +14,7 @@ package body Errors is
package SU renames Ada.Strings.Unbounded;
package SF renames Ada.Strings.Fixed;
package CH renames Ada.Characters.Handling;
+ package Latin renames Ada.Characters.Latin_1;
@@ -199,6 +201,21 @@ package body Errors is
end Valid_Message;
+ function Debug_String
+ (This : in Error_Message)
+ return String
+ is
+ Result : SU.Unbounded_String := +"";
+ Info : Error_Info_Array := Decode (This);
+ begin
+ for E of Info loop
+ SU.Append (Result, "Expected " & (-E.Symbol) &
+ " at input position" & Integer'Image (E.Position) & Latin.LF);
+ end loop;
+ return -Result;
+ end Debug_String;
+
+
diff --git a/src/packrat-tokens.adb b/src/packrat-tokens.adb
index 4cb10bf..70a866a 100644
--- a/src/packrat-tokens.adb
+++ b/src/packrat-tokens.adb
@@ -2,13 +2,18 @@
with
- Ada.Unchecked_Deallocation;
+ Ada.Unchecked_Deallocation,
+ Ada.Characters.Latin_1;
separate (Packrat)
package body Tokens is
+ package SU renames Ada.Strings.Unbounded;
+ package Latin renames Ada.Characters.Latin_1;
+
+
procedure Free_Array is new Ada.Unchecked_Deallocation
(Object => Element_Array, Name => Element_Array_Access);
@@ -76,6 +81,20 @@ package body Tokens is
end Initialized;
+ function Debug_String
+ (This : in Token)
+ return String
+ is
+ Result : SU.Unbounded_String := +"";
+ begin
+ SU.Append (Result, "Token " & Label_Enum'Image (This.Identifier) &
+ " at input position" & Integer'Image (This.Start_At) & " to" &
+ Integer'Image (This.Finish_At) & " with value length" &
+ Integer'Image (This.Token_Value'Length) & Latin.LF);
+ return -Result;
+ end Debug_String;
+
+
diff --git a/src/packrat.ads b/src/packrat.ads
index c60b798..a17e499 100644
--- a/src/packrat.ads
+++ b/src/packrat.ads
@@ -53,6 +53,10 @@ package Packrat is
(Check : in String)
return Boolean;
+ function Debug_String
+ (This : in Error_Message)
+ return String;
+
function Join
(Left, Right : in Error_Message)
@@ -118,6 +122,10 @@ package Packrat is
(This : in Token)
return Boolean;
+ function Debug_String
+ (This : in Token)
+ return String;
+
function Label
(This : in Token)
diff --git a/test/test_main.adb b/test/test_main.adb
index 404e690..a2682f4 100644
--- a/test/test_main.adb
+++ b/test/test_main.adb
@@ -3,6 +3,7 @@
with
Ada.Text_IO,
+ Packrat,
Ratnest.Tests;
use
@@ -13,14 +14,25 @@ use
procedure Test_Main is
+ type My_Labels is (A, B, C);
+ 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, 3, "abc");
begin
Put_Line ("Running tests for Packrat.Errors...");
Run_Tests (Error_Tests);
New_Line;
+ Put_Line ("Displaying Error_Message debug string output example:");
+ Put (Packrat.Errors.Debug_String (Err));
+ New_Line;
Put_Line ("Running tests for Packrat.Tokens...");
Run_Tests (Token_Tests);
New_Line;
+ Put_Line ("Displaying Token debug string output example:");
+ Put (Tok.Debug_String);
+ New_Line;
Put_Line ("Running tests for Packrat.Util...");
Put_Line ("Testing set predicates...");