diff options
Diffstat (limited to 'src/packrat-lexer.adb')
-rw-r--r-- | src/packrat-lexer.adb | 49 |
1 files changed, 39 insertions, 10 deletions
diff --git a/src/packrat-lexer.adb b/src/packrat-lexer.adb index 0b0f571..ce793a5 100644 --- a/src/packrat-lexer.adb +++ b/src/packrat-lexer.adb @@ -81,19 +81,23 @@ package body Packrat.Lexer is end if; Total_Valsize := Left_Valsize + Right_Valsize; - if Left.Status = Success then + if Left.Status = Success or Left.Status = Optional_More then Merge.Length := Left.Length + Right.Length; Merge.Status := Right.Status; - if Total_Valsize /= 0 or Right.Status /= Failure then + if Total_Valsize > 0 then Merge.Value := new Element_Array (1 .. Total_Valsize); - if Left_Valsize /= 0 then + if Left.Value /= null then Merge.Value.all (1 .. Left_Valsize) := Left.Value.all; end if; - if Right_Valsize /= 0 then + if Right.Value /= null then Merge.Value.all (Left_Valsize + 1 .. Total_Valsize) := Right.Value.all; end if; end if; return Merge; + elsif Left.Status = Needs_More then + Merge := Left; + Merge.Status := Failure; + return Merge; else return Left; end if; @@ -104,15 +108,23 @@ package body Packrat.Lexer is (Left, Right : in Combinator_Result) return Boolean is - Null_Check : Boolean := - Left.Value = null and Right.Value = null; - Value_Check : Boolean := - Left.Value /= null and then Right.Value /= null and then - Left.Value.all = Right.Value.all; + Left_Valsize, Right_Valsize : Natural; begin + if Left.Value = null then + Left_Valsize := 0; + else + Left_Valsize := Left.Value.all'Length; + end if; + if Right.Value = null then + Right_Valsize := 0; + else + Right_Valsize := Right.Value.all'Length; + end if; + return Left.Length = Right.Length and Left.Status = Right.Status and - (Null_Check or Value_Check); + Left_Valsize = Right_Valsize and + (Left_Valsize = 0 or else Left.Value.all = Right.Value.all); end "="; @@ -124,6 +136,23 @@ package body Packrat.Lexer is end Status; + function Debug_String + (This : in Combinator_Result) + return String + is + Value_Length : Natural; + begin + if This.Value = null then + Value_Length := 0; + else + Value_Length := This.Value.all'Length; + end if; + return Integer'Image (This.Length) + & " " & Result_Status'Image (This.Status) + & " " & Integer'Image (Value_Length); + end Debug_String; + + end Packrat.Lexer; |