summaryrefslogtreecommitdiff
path: root/src
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 /src
parent81f7e19f212f9d1ac75e04e62933e6c918219cfc (diff)
Debug_String functions added to Packrat.Errors and Packrat.Tokens
Diffstat (limited to 'src')
-rw-r--r--src/packrat-errors.adb19
-rw-r--r--src/packrat-tokens.adb21
-rw-r--r--src/packrat.ads8
3 files changed, 46 insertions, 2 deletions
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)