summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2019-01-08 16:29:30 +1100
committerJed Barber <jjbarber@y7mail.com>2019-01-08 16:29:30 +1100
commit2912e22000bff5b83b77daeb2b5ed111c47268b8 (patch)
treee953e4387171f3308c4b14cf7ca0ebfb7dc391e2 /src
parent1e67356ba64622e07877db1c65f823f0f58b1321 (diff)
Packrat.Errors specification and tests
Diffstat (limited to 'src')
-rw-r--r--src/packrat-errors.adb105
-rw-r--r--src/packrat.adb11
-rw-r--r--src/packrat.ads85
3 files changed, 201 insertions, 0 deletions
diff --git a/src/packrat-errors.adb b/src/packrat-errors.adb
new file mode 100644
index 0000000..44b9202
--- /dev/null
+++ b/src/packrat-errors.adb
@@ -0,0 +1,105 @@
+
+
+separate (Packrat)
+package body Errors is
+
+
+ package SU renames Ada.Strings.Unbounded;
+
+
+
+
+
+ function Valid_Identifier
+ (Check : in String)
+ return Boolean is
+ begin
+ return True;
+ end Valid_Identifier;
+
+
+ function Valid_Identifier
+ (Check : in SU.Unbounded_String)
+ return Boolean is
+ begin
+ return True;
+ end Valid_Identifier;
+
+
+ function Valid_Identifier_Array
+ (Check : in Error_Info_Array)
+ return Boolean is
+ begin
+ return True;
+ end Valid_Identifier_Array;
+
+
+ function Valid_Message
+ (Check : in String)
+ return Boolean is
+ begin
+ return True;
+ end Valid_Message;
+
+
+
+
+
+ function Join
+ (Left, Right : in Error_Message)
+ return Error_Message is
+ begin
+ return "";
+ end Join;
+
+
+
+
+
+ function Encode
+ (Name : in String;
+ Pos : in Natural)
+ return Error_Message is
+ begin
+ return "";
+ end Encode;
+
+
+ function Encode
+ (Name : in SU.Unbounded_String;
+ Pos : in Natural)
+ return Error_Message is
+ begin
+ return "";
+ end Encode;
+
+
+ function Encode
+ (Info : in Error_Info)
+ return Error_Message is
+ begin
+ return "";
+ end Encode;
+
+
+ function Encode_Array
+ (Info : in Error_Info_Array)
+ return Error_Message is
+ begin
+ return "";
+ end Encode_Array;
+
+
+ function Decode
+ (Msg : in Error_Message)
+ return Error_Info_Array
+ is
+ Result : Error_Info_Array (1 .. 0);
+ begin
+ return Result;
+ end Decode;
+
+
+end Errors;
+
+
diff --git a/src/packrat.adb b/src/packrat.adb
new file mode 100644
index 0000000..e78d0ae
--- /dev/null
+++ b/src/packrat.adb
@@ -0,0 +1,11 @@
+
+
+package body Packrat is
+
+
+ package body Errors is separate;
+
+
+end Packrat;
+
+
diff --git a/src/packrat.ads b/src/packrat.ads
index 36410d5..628923f 100644
--- a/src/packrat.ads
+++ b/src/packrat.ads
@@ -1,8 +1,93 @@
+with
+
+ Ada.Strings.Unbounded;
+
+
package Packrat is
+ Parse_Error : exception;
+
+
+
+
+ package Errors is
+
+
+ subtype Error_Message is String
+ with Dynamic_Predicate => Valid_Message (Error_Message);
+
+ type Error_Info is record
+ Symbol : Ada.Strings.Unbounded.Unbounded_String;
+ Position : Natural;
+ end record;
+
+ type Error_Info_Array is array (Positive range <>) of Error_Info;
+
+
+ -- Note: No consideration is given to ordering of Error_Info items
+ -- encoded into an Error_Message string.
+
+ -- Note: Using "&" to join two Valid Error_Messages together
+ -- will result in an Error_Message that is also Valid,
+ -- but for best results Join should be used instead to
+ -- prevent duplication of Error_Info in the message.
+
+
+ function Valid_Identifier
+ (Check : in String)
+ return Boolean;
+
+ function Valid_Identifier
+ (Check : in Ada.Strings.Unbounded.Unbounded_String)
+ return Boolean;
+
+ function Valid_Identifier_Array
+ (Check : in Error_Info_Array)
+ return Boolean;
+
+ function Valid_Message
+ (Check : in String)
+ return Boolean;
+
+
+ function Join
+ (Left, Right : in Error_Message)
+ return Error_Message;
+
+
+ function Encode
+ (Name : in String;
+ Pos : in Natural)
+ return Error_Message
+ with Pre => Valid_Identifier (Name);
+
+ function Encode
+ (Name : in Ada.Strings.Unbounded.Unbounded_String;
+ Pos : in Natural)
+ return Error_Message
+ with Pre => Valid_Identifier (Name);
+
+ function Encode
+ (Info : in Error_Info)
+ return Error_Message
+ with Pre => Valid_Identifier (Info.Symbol);
+
+ function Encode_Array
+ (Info : in Error_Info_Array)
+ return Error_Message
+ with Pre => Valid_Identifier_Array (Info);
+
+ function Decode
+ (Msg : in Error_Message)
+ return Error_Info_Array;
+
+
+ end Errors;
+
+
private