diff options
author | Jed Barber <jjbarber@y7mail.com> | 2020-04-20 15:49:56 +1000 |
---|---|---|
committer | Jed Barber <jjbarber@y7mail.com> | 2020-04-20 15:49:56 +1000 |
commit | 42d3982f1e6335cb99c382ddd91c324e5fa458ad (patch) | |
tree | fe7208dc36dd42d82552d7d1044d9ebb6a4ea570 /src | |
parent | d8e6a2bcf74f1059f83c681e646fd8a22876e737 (diff) |
Updated and fixed tests, fixed Pass_Forward array sliding bug
Diffstat (limited to 'src')
-rw-r--r-- | src/packrat-lexer.adb | 64 | ||||
-rw-r--r-- | src/packrat-lexer.ads | 8 |
2 files changed, 38 insertions, 34 deletions
diff --git a/src/packrat-lexer.adb b/src/packrat-lexer.adb index 319e05c..bd8d7ea 100644 --- a/src/packrat-lexer.adb +++ b/src/packrat-lexer.adb @@ -170,6 +170,36 @@ package body Packrat.Lexer is end Token_Vector_To_Array; + function Slide + (Input : in Element_Array) + return Element_Array + is + subtype Slider is Element_Array (1 .. Input'Length); + begin + return Slider (Input); + end Slide; + + + procedure Internal_Scan_Core + (Input : in Element_Array; + Context : in out Lexer_Context; + Components : in Component_Array) + is + Raise_Error : Boolean; + begin + Raise_Error := True; + for C of Components loop + if C (Input, Context) = Component_Success then + Raise_Error := False; + exit; + end if; + end loop; + if Raise_Error then + Raise_Lexer_Error (Context.Error_Labels, Context.Position); + end if; + end Internal_Scan_Core; + + @@ -181,7 +211,7 @@ package body Packrat.Lexer is Real_Input : Input_Holders.Holder; begin if not Context.Pass_Forward.Is_Empty then - Real_Input.Replace_Element (Context.Pass_Forward.Element & Input); + Real_Input.Replace_Element (Slide (Context.Pass_Forward.Element) & Input); else Real_Input.Replace_Element (Input); end if; @@ -206,7 +236,7 @@ package body Packrat.Lexer is Real_Input : Input_Holders.Holder; begin if not Context.Pass_Forward.Is_Empty then - Real_Input.Replace_Element (Context.Pass_Forward.Element & Input); + Real_Input.Replace_Element (Slide (Context.Pass_Forward.Element) & Input); else Real_Input.Replace_Element (Input); end if; @@ -236,7 +266,8 @@ package body Packrat.Lexer is Real_Input.Replace_Element (Input.all); Empty_Input := Real_Input.Element'Length = 0; if not Context.Pass_Forward.Is_Empty then - Real_Input.Replace_Element (Context.Pass_Forward.Element & Real_Input.Element); + Real_Input.Replace_Element + (Slide (Context.Pass_Forward.Element) & Real_Input.Element); end if; Tidy_Context (Context, Components'Length); @@ -262,7 +293,7 @@ package body Packrat.Lexer is Real_Input : Input_Holders.Holder; begin if not Context.Pass_Forward.Is_Empty then - Real_Input.Replace_Element (Context.Pass_Forward.Element & Input); + Real_Input.Replace_Element (Slide (Context.Pass_Forward.Element) & Input); else Real_Input.Replace_Element (Input); end if; @@ -298,10 +329,11 @@ package body Packrat.Lexer is Context.Result_So_Far.Clear; loop Real_Input.Replace_Element (Input.all); - Empty_Input := Real_Input.Element'Length = 0 or + Empty_Input := Real_Input.Element'Length = 0 or else Real_Input.Element (Real_Input.Element'First) = Pad_In; if not Context.Pass_Forward.Is_Empty then - Real_Input.Replace_Element (Context.Pass_Forward.Element & Real_Input.Element); + Real_Input.Replace_Element + (Slide (Context.Pass_Forward.Element) & Real_Input.Element); end if; Tidy_Context (Context, Components'Length); @@ -329,26 +361,6 @@ package body Packrat.Lexer is end Scan_Set_With; - procedure Internal_Scan_Core - (Input : in Element_Array; - Context : in out Lexer_Context; - Components : in Component_Array) - is - Raise_Error : Boolean; - begin - Raise_Error := True; - for C of Components loop - if C (Input, Context) = Component_Success then - Raise_Error := False; - exit; - end if; - end loop; - if Raise_Error then - Raise_Lexer_Error (Context.Error_Labels, Context.Position); - end if; - end Internal_Scan_Core; - - diff --git a/src/packrat-lexer.ads b/src/packrat-lexer.ads index 9973cdd..a797d7f 100644 --- a/src/packrat-lexer.ads +++ b/src/packrat-lexer.ads @@ -315,14 +315,6 @@ private Allow_Incomplete => True); - - - procedure Internal_Scan_Core - (Input : in Element_Array; - Context : in out Lexer_Context; - Components : in Component_Array); - - end Packrat.Lexer; |