diff options
author | Jed Barber <jjbarber@y7mail.com> | 2021-01-21 20:01:23 +1100 |
---|---|---|
committer | Jed Barber <jjbarber@y7mail.com> | 2021-01-21 20:01:23 +1100 |
commit | 0b0c4df3dc7b94c139c5305ea0991a34f0c43238 (patch) | |
tree | e7360eabe50feef654a1d886483c570a392066bc /src | |
parent | 30d59f09f6908aa0de2ec3a58a0736c8030ffda5 (diff) |
Lexer combinator Needs_More case fixed
Diffstat (limited to 'src')
-rw-r--r-- | src/packrat-lexers.adb | 35 | ||||
-rw-r--r-- | src/packrat-lexers.ads | 8 |
2 files changed, 26 insertions, 17 deletions
diff --git a/src/packrat-lexers.adb b/src/packrat-lexers.adb index b09b6eb..341b87f 100644 --- a/src/packrat-lexers.adb +++ b/src/packrat-lexers.adb @@ -417,7 +417,7 @@ package body Packrat.Lexers is Position : Positive := Start; begin if Start > Input'Last then - return Empty_Fail; + return Empty_Needs_More; end if; for C of Params loop if Position > Input'Last then @@ -441,7 +441,7 @@ package body Packrat.Lexers is Position : Positive := Start; begin if Start > Input'Last then - return Empty_Fail; + return Empty_Needs_More; end if; for I in Integer range 1 .. Number loop if Position > Input'Last then @@ -467,7 +467,7 @@ package body Packrat.Lexers is Counter : Natural := 0; begin if Start > Input'Last then - return Empty_Fail; + return Empty_Needs_More; end if; loop exit when Position > Input'Last; @@ -503,7 +503,7 @@ package body Packrat.Lexers is Counter : Natural := 0; begin if Start > Input'Last then - return Empty_Fail; + return Empty_Needs_More; end if; loop exit when Position > Input'Last; @@ -541,7 +541,7 @@ package body Packrat.Lexers is return Combinator_Result is begin if Start > Input'Last then - return Empty_Fail; + return Empty_Needs_More; elsif Test (Input (Start)) then return (Start, Success); else @@ -556,7 +556,7 @@ package body Packrat.Lexers is return Combinator_Result is begin if Start > Input'Last then - return Empty_Fail; + return Empty_Needs_More; elsif Test (Change (Input (Start))) then return (Start, Success); else @@ -571,7 +571,7 @@ package body Packrat.Lexers is return Combinator_Result is begin if Start > Input'Last then - return Empty_Fail; + return Empty_Needs_More; elsif Input (Start) = Item then return (Start, Success); else @@ -586,7 +586,7 @@ package body Packrat.Lexers is return Combinator_Result is begin if Start > Input'Last then - return Empty_Fail; + return Empty_Needs_More; elsif Change (Input (Start)) = Item then return (Start, Success); else @@ -603,13 +603,10 @@ package body Packrat.Lexers is Current_Offset : Natural := 0; begin if Items'Length = 0 then - return (0, Success); + return Empty_Success; + elsif Start > Input'Last then + return Empty_Needs_More; end if; - - if Input'Last - Start + 1 <= 0 then - return Empty_Fail; - end if; - while Input (Start + Current_Offset) = Items (Items'First + Current_Offset) loop if Items'First + Current_Offset = Items'Last then return (Start + Current_Offset, Success); @@ -632,7 +629,7 @@ package body Packrat.Lexers is return Combinator_Result is begin if Start > Input'Last then - return Empty_Fail; + return Empty_Needs_More; elsif Start + Number - 1 > Input'Last then return (Input'Last, Needs_More); else @@ -649,7 +646,9 @@ package body Packrat.Lexers is Finish : Positive := Start; Status : Result_Status; begin - if Start > Input'Last or else not Test (Input (Start)) then + if Start > Input'Last then + return Empty_Needs_More; + elsif not Test (Input (Start)) then return Empty_Fail; end if; while Finish <= Input'Last and then Test (Input (Finish)) loop @@ -672,7 +671,9 @@ package body Packrat.Lexers is Finish : Positive := Start; Status : Result_Status; begin - if Start > Input'Last or else Test (Input (Start)) then + if Start > Input'Last then + return Empty_Needs_More; + elsif Test (Input (Start)) then return Empty_Fail; end if; while Finish <= Input'Last and then not Test (Input (Finish)) loop diff --git a/src/packrat-lexers.ads b/src/packrat-lexers.ads index 4b6bbc9..c303feb 100644 --- a/src/packrat-lexers.ads +++ b/src/packrat-lexers.ads @@ -305,6 +305,14 @@ private (Finish => 0, Status => Failure); + Empty_Needs_More : constant Combinator_Result := + (Finish => 0, + Status => Needs_More); + + Empty_Success : constant Combinator_Result := + (Finish => 0, + Status => Success); + |