summaryrefslogtreecommitdiff
path: root/src/packrat.ads
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2019-01-09 22:58:10 +1100
committerJed Barber <jjbarber@y7mail.com>2019-01-09 22:58:10 +1100
commit81f7e19f212f9d1ac75e04e62933e6c918219cfc (patch)
tree2f353225fc46d619e1f09c6e26ec7c3f6f6b53a3 /src/packrat.ads
parente9862fcf976878cdec96b5f00adee010fd1c8382 (diff)
Packrat.Tokens added, tested, and functional
Diffstat (limited to 'src/packrat.ads')
-rw-r--r--src/packrat.ads79
1 files changed, 78 insertions, 1 deletions
diff --git a/src/packrat.ads b/src/packrat.ads
index 1c81958..c60b798 100644
--- a/src/packrat.ads
+++ b/src/packrat.ads
@@ -2,7 +2,8 @@
with
- Ada.Strings.Unbounded;
+ Ada.Strings.Unbounded,
+ Ada.Finalization;
package Packrat is
@@ -88,6 +89,82 @@ package Packrat is
end Errors;
+
+
+ generic
+ type Label_Enum is (<>);
+ type Element is private;
+ type Element_Array is array (Positive range <>) of Element;
+ package Tokens is
+
+
+ type Token is new Ada.Finalization.Controlled with private;
+
+
+ function Create
+ (Ident : in Label_Enum;
+ Start : in Positive;
+ Finish : in Natural;
+ Value : in Element_Array)
+ return Token;
+
+
+ -- Note: The Start and Finish indices indicate where the token was found
+ -- in whatever array it was lexed from. The Value does *not* have
+ -- to correspond with whatever is found in the Start .. Finish range.
+
+
+ function Initialized
+ (This : in Token)
+ return Boolean;
+
+
+ function Label
+ (This : in Token)
+ return Label_Enum
+ with Pre => Initialized (This);
+
+ function Start
+ (This : in Token)
+ return Positive;
+
+ function Finish
+ (This : in Token)
+ return Natural;
+
+ function Value
+ (This : in Token)
+ return Element_Array
+ with Pre => Initialized (This);
+
+
+ private
+
+
+ type Element_Array_Access is access Element_Array;
+
+
+ type Token is new Ada.Finalization.Controlled with record
+ Identifier : Label_Enum;
+ Start_At : Positive;
+ Finish_At : Natural;
+ Token_Value : Element_Array_Access;
+ end record;
+
+
+ overriding procedure Initialize
+ (This : in out Token);
+
+ overriding procedure Adjust
+ (This : in out Token);
+
+ overriding procedure Finalize
+ (This : in out Token);
+
+
+ end Tokens;
+
+
private