summaryrefslogtreecommitdiff
path: root/src/packrat-tokens.adb
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-tokens.adb
parente9862fcf976878cdec96b5f00adee010fd1c8382 (diff)
Packrat.Tokens added, tested, and functional
Diffstat (limited to 'src/packrat-tokens.adb')
-rw-r--r--src/packrat-tokens.adb116
1 files changed, 116 insertions, 0 deletions
diff --git a/src/packrat-tokens.adb b/src/packrat-tokens.adb
new file mode 100644
index 0000000..4cb10bf
--- /dev/null
+++ b/src/packrat-tokens.adb
@@ -0,0 +1,116 @@
+
+
+with
+
+ Ada.Unchecked_Deallocation;
+
+
+separate (Packrat)
+package body Tokens is
+
+
+ procedure Free_Array is new Ada.Unchecked_Deallocation
+ (Object => Element_Array, Name => Element_Array_Access);
+
+
+
+
+
+ procedure Initialize
+ (This : in out Token) is
+ begin
+ This.Start_At := 1;
+ This.Finish_At := 0;
+ end Initialize;
+
+
+ procedure Adjust
+ (This : in out Token)
+ is
+ New_Array : Element_Array_Access :=
+ new Element_Array (This.Token_Value'Range);
+ begin
+ New_Array.all := This.Token_Value.all;
+ This.Token_Value := New_Array;
+ end Adjust;
+
+
+ procedure Finalize
+ (This : in out Token) is
+ begin
+ if This.Token_Value /= null then
+ Free_Array (This.Token_Value);
+ end if;
+ end Finalize;
+
+
+
+
+
+ function Create
+ (Ident : in Label_Enum;
+ Start : in Positive;
+ Finish : in Natural;
+ Value : in Element_Array)
+ return Token
+ is
+ This : Token;
+ begin
+ This.Identifier := Ident;
+ This.Start_At := Start;
+ This.Finish_At := Finish;
+ This.Token_Value := new Element_Array (Value'Range);
+ This.Token_Value.all := Value;
+ return This;
+ end Create;
+
+
+
+
+
+ function Initialized
+ (This : in Token)
+ return Boolean is
+ begin
+ return This.Token_Value /= null;
+ end Initialized;
+
+
+
+
+
+ function Label
+ (This : in Token)
+ return Label_Enum is
+ begin
+ return This.Identifier;
+ end Label;
+
+
+ function Start
+ (This : in Token)
+ return Positive is
+ begin
+ return This.Start_At;
+ end Start;
+
+
+ function Finish
+ (This : in Token)
+ return Natural is
+ begin
+ return This.Finish_At;
+ end Finish;
+
+
+ function Value
+ (This : in Token)
+ return Element_Array is
+ begin
+ return This.Token_Value.all;
+ end Value;
+
+
+end Tokens;
+
+