summaryrefslogtreecommitdiff
path: root/src/packrat-tokens.adb
diff options
context:
space:
mode:
Diffstat (limited to 'src/packrat-tokens.adb')
-rw-r--r--src/packrat-tokens.adb93
1 files changed, 9 insertions, 84 deletions
diff --git a/src/packrat-tokens.adb b/src/packrat-tokens.adb
index 382b8d8..aae0ae6 100644
--- a/src/packrat-tokens.adb
+++ b/src/packrat-tokens.adb
@@ -2,7 +2,6 @@
with
- Ada.Unchecked_Deallocation,
Ada.Characters.Latin_1;
@@ -14,45 +13,6 @@ package body Tokens is
package Latin renames Ada.Characters.Latin_1;
- 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
- begin
- if This.Token_Value /= null then
- declare
- New_Array : Element_Array_Access :=
- new Element_Array (1 .. This.Token_Value'Length);
- begin
- New_Array.all := This.Token_Value.all;
- This.Token_Value := New_Array;
- end;
- end if;
- 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;
-
-
@@ -61,55 +21,20 @@ package body Tokens is
Start : in Positive;
Finish : in Natural;
Value : in Element_Array)
- return Token
- is
- This : Token;
+ return Token is
begin
- This.Identifier := Ident;
- This.Start_At := Start;
- This.Finish_At := Finish;
- This.Token_Value := new Element_Array (1 .. Value'Length);
- This.Token_Value.all := Value;
- return This;
+ return This : Token do
+ This.Identifier := Ident;
+ This.Start_At := Start;
+ This.Finish_At := Finish;
+ This.Token_Value := Value_Holders.To_Holder (Value);
+ end return;
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 "=";
-
-
- function Initialized
- (This : in Token)
- return Boolean is
- begin
- return This.Token_Value /= null;
- end Initialized;
-
-
function Debug_String
(This : in Token)
return String
@@ -119,7 +44,7 @@ package body Tokens is
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);
+ Integer'Image (This.Token_Value.Constant_Reference.Element'Length) & Latin.LF);
return -Result;
end Debug_String;
@@ -155,7 +80,7 @@ package body Tokens is
(This : in Token)
return Element_Array is
begin
- return This.Token_Value.all;
+ return This.Token_Value.Element;
end Value;