From 8828e68cb86c865d625961c07c7ce2eb4ae191bc Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Sat, 7 Nov 2020 01:21:54 +1100 Subject: Parse_Graphs complete aside from isomorphism and testing --- src/packrat-tokens.adb | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/packrat-tokens.adb') diff --git a/src/packrat-tokens.adb b/src/packrat-tokens.adb index e0ea10d..08e0181 100644 --- a/src/packrat-tokens.adb +++ b/src/packrat-tokens.adb @@ -16,6 +16,45 @@ package body Tokens is + function "<" + (Left, Right : in Token) + return Boolean + is + Left_Index, Right_Index : Positive; + begin + if Left.Start_At = Right.Start_At then + if Left.Identifier = Right.Identifier then + Left_Index := Left.Token_Value.Constant_Reference.Element'First; + Right_Index := Right.Token_Value.Constant_Reference.Element'First; + while Left_Index <= Left.Token_Value.Constant_Reference.Element'Last and + Right_Index <= Right.Token_Value.Constant_Reference.Element'Last + loop + if Left.Token_Value.Constant_Reference.Element (Left_Index) < + Right.Token_Value.Constant_Reference.Element (Right_Index) + then + return True; + elsif Left.Token_Value.Constant_Reference.Element (Left_Index) /= + Right.Token_Value.Constant_Reference.Element (Right_Index) + then + return False; + end if; + Left_Index := Left_Index + 1; + Right_Index := Right_Index + 1; + end loop; + return Left.Token_Value.Constant_Reference.Element'Length < + Right.Token_Value.Constant_Reference.Element'Length; + else + return Left.Identifier < Right.Identifier; + end if; + else + return Left.Start_At < Right.Start_At; + end if; + end "<"; + + + + + function Create (Ident : in Label_Enum; Start : in Positive; -- cgit