summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2019-01-13 00:31:06 +1100
committerJed Barber <jjbarber@y7mail.com>2019-01-13 00:31:06 +1100
commit6537721f85aa4f0d8607c9df506a343fb0093bef (patch)
tree1830f29da6dcf449ec994198b14d7055b58a9c9b
parent3526877189d0787eb16f23fc233c21be3475c9c7 (diff)
Added equals function overload for Tokens
-rw-r--r--src/packrat-tokens.adb25
-rw-r--r--src/packrat.ads6
2 files changed, 30 insertions, 1 deletions
diff --git a/src/packrat-tokens.adb b/src/packrat-tokens.adb
index 240ecee..382b8d8 100644
--- a/src/packrat-tokens.adb
+++ b/src/packrat-tokens.adb
@@ -74,6 +74,31 @@ package body Tokens is
end Create;
+ function "="
+ (Left, Right : in Token)
+ return Boolean
+ is
+ Left_Valsize, Right_Valsize : Natural;
+ begin
+ if Left.Token_Value = null then
+ Left_Valsize := 0;
+ else
+ Left_Valsize := Left.Token_Value.all'Length;
+ end if;
+ if Right.Token_Value = null then
+ Right_Valsize := 0;
+ else
+ Right_Valsize := Right.Token_Value.all'Length;
+ end if;
+
+ return Left.Identifier = Right.Identifier and
+ Left.Start_At = Right.Start_At and
+ Left.Finish_At = Right.Finish_At and
+ Left_Valsize = Right_Valsize and
+ (Left_Valsize = 0 or else Left.Token_Value.all = Right.Token_Value.all);
+ end "=";
+
+
diff --git a/src/packrat.ads b/src/packrat.ads
index 41035fc..0ee8463 100644
--- a/src/packrat.ads
+++ b/src/packrat.ads
@@ -9,7 +9,7 @@ with
package Packrat is
- type Result_Status is (Failure, Partial, Success);
+ type Result_Status is (Failure, Needs_More, Optional_More, Success);
Parser_Error : exception;
@@ -117,6 +117,10 @@ package Packrat is
Value : in Element_Array)
return Token;
+ function "="
+ (Left, Right : in Token)
+ return Boolean;
+
-- Note: The Start and Finish indices indicate where the token was found
-- in whatever array it was lexed from. The Value does *not* have