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.adb72
1 files changed, 61 insertions, 11 deletions
diff --git a/src/packrat-tokens.adb b/src/packrat-tokens.adb
index 81d68c3..2e47db9 100644
--- a/src/packrat-tokens.adb
+++ b/src/packrat-tokens.adb
@@ -24,7 +24,7 @@ package body Packrat.Tokens is
function "<"
- (Left, Right : in Token)
+ (Left, Right : in Token_Type)
return Boolean is
begin
if Left.Start_At = Right.Start_At then
@@ -44,13 +44,48 @@ package body Packrat.Tokens is
return Boolean
is
function LT is new Array_Less_Than
- (Base_Type => Token,
+ (Base_Type => Token_Type,
Array_Type => Token_Array);
begin
return LT (Left, Right);
end "<";
+ function "<"
+ (Left, Right : Finished_Token_Type)
+ return Boolean
+ is
+ function LT is new Array_Less_Than
+ (Base_Type => Element_Type,
+ Array_Type => Element_Array);
+ begin
+ if Start (Left.Token) = Start (Right.Token) then
+ if Left.Finish = Right.Finish then
+ if Label (Left.Token) = Label (Right.Token) then
+ return Value (Left.Token) < Value (Right.Token);
+ else
+ return Label (Left.Token) < Label (Right.Token);
+ end if;
+ else
+ return Left.Finish < Right.Finish;
+ end if;
+ else
+ return Start (Left.Token) < Start (Right.Token);
+ end if;
+ end "<";
+
+
+ function "<"
+ (Left, Right : in Finished_Token_Array)
+ return Boolean
+ is
+ function LT is new Array_Less_Than
+ (Base_Type => Finished_Token_Type,
+ Array_Type => Finished_Token_Array);
+ begin
+ return LT (Left, Right);
+ end "<";
+
@@ -58,9 +93,9 @@ package body Packrat.Tokens is
(Ident : in Label_Enum;
Start : in Positive;
Value : in Element_Array)
- return Token is
+ return Token_Type is
begin
- return This : Token do
+ return This : Token_Type do
This.Identifier := Ident;
This.Start_At := Start;
This.Token_Value := Value_Holders.To_Holder (Value);
@@ -72,7 +107,7 @@ package body Packrat.Tokens is
function Debug_String
- (This : in Token)
+ (This : in Token_Type)
return String
is
Result : SU.Unbounded_String := +"";
@@ -84,11 +119,26 @@ package body Packrat.Tokens is
end Debug_String;
+ function Debug_String
+ (This : in Finished_Token_Type)
+ return String
+ is
+ Result : SU.Unbounded_String := +"";
+ begin
+ SU.Append (Result, "Token " & Label_Enum'Image (This.Token.Identifier) &
+ " at input position" & Integer'Image (This.Token.Start_At) & " to" &
+ Integer'Image (This.Finish) & " with value length" &
+ Integer'Image (This.Token.Token_Value.Constant_Reference.Element'Length) &
+ Latin.LF);
+ return -Result;
+ end Debug_String;
+
+
function Label
- (This : in Token)
+ (This : in Token_Type)
return Label_Enum is
begin
return This.Identifier;
@@ -96,7 +146,7 @@ package body Packrat.Tokens is
function Start
- (This : in Token)
+ (This : in Token_Type)
return Positive is
begin
return This.Start_At;
@@ -104,7 +154,7 @@ package body Packrat.Tokens is
function Value
- (This : in Token)
+ (This : in Token_Type)
return Element_Array is
begin
return This.Token_Value.Element;
@@ -115,7 +165,7 @@ package body Packrat.Tokens is
function Is_Label
- (This : in Token)
+ (This : in Token_Type)
return Boolean is
begin
return This.Identifier = Ident;
@@ -123,7 +173,7 @@ package body Packrat.Tokens is
function Is_Start
- (This : in Token)
+ (This : in Token_Type)
return Boolean is
begin
return This.Start_At = Start;
@@ -131,7 +181,7 @@ package body Packrat.Tokens is
function Is_Value
- (This : in Token)
+ (This : in Token_Type)
return Boolean is
begin
return This.Token_Value.Element = Value;