From 43eea37daf162473c8c8e8279c9159d8b052ffdf Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Fri, 13 Nov 2020 11:36:41 +1100 Subject: Refactored Tokens, Errors, Traits --- test/rat_tests-lexer.adb | 140 ++++++++++++++++++++++++----------------------- 1 file changed, 71 insertions(+), 69 deletions(-) (limited to 'test/rat_tests-lexer.adb') diff --git a/test/rat_tests-lexer.adb b/test/rat_tests-lexer.adb index 484c86b..531d175 100644 --- a/test/rat_tests-lexer.adb +++ b/test/rat_tests-lexer.adb @@ -2,6 +2,8 @@ with + Packrat.Errors, + Packrat.Traits, Packrat.Lexer.Debug, Packrat.Util; @@ -15,8 +17,8 @@ package body Rat_Tests.Lexer is type My_Labels is (One, Two, Three); - package String_Tokens is new Packrat.Tokens (My_Labels, Character, String); - package Slexy is new Packrat.Lexer (My_Labels, Character, String, "<", String_Tokens); + package Slexy_Traits is new Packrat.Traits (My_Labels, Character, String); + package Slexy is new Packrat.Lexer (Slexy_Traits); package Slebug is new Slexy.Debug; @@ -553,7 +555,7 @@ package body Rat_Tests.Lexer is function Stamp_Check return Test_Result is - use type String_Tokens.Token; + use type Slexy_Traits.Tokens.Token; use type Packrat.Result_Status; use type Slexy.Component_Result; @@ -576,7 +578,7 @@ package body Rat_Tests.Lexer is begin Comp_Code := My_Stamp (Test_Str1, Context1); if (Slebug.So_Far (Context1).Length /= 1 or else - Slebug.So_Far (Context1).Element (1) /= String_Tokens.Create (One, 1, "abc")) or + Slebug.So_Far (Context1).Element (1) /= Slexy_Traits.Tokens.Create (One, 1, "abc")) or Slebug.Position (Context1) /= 4 or Slebug.Status (Context1) /= Packrat.Success or Slebug.Has_Pass (Context1) then @@ -584,7 +586,7 @@ package body Rat_Tests.Lexer is end if; Comp_Code := My_Stamp (Test_Str1, Context1); if (Slebug.So_Far (Context1).Length /= 1 or else - Slebug.So_Far (Context1).Element (1) /= String_Tokens.Create (One, 1, "abc")) or + Slebug.So_Far (Context1).Element (1) /= Slexy_Traits.Tokens.Create (One, 1, "abc")) or Slebug.Position (Context1) /= 4 or not Slebug.Is_Failure (Comp_Code) or Slebug.Has_Pass (Context1) then @@ -648,12 +650,12 @@ package body Rat_Tests.Lexer is type Word_Enum is (Blank, Word, Whitespace); - package Word_Tokens is new Packrat.Tokens (Word_Enum, Character, String); - package Swordy is new Packrat.Lexer (Word_Enum, Character, String, "<", Word_Tokens); + package Swordy_Traits is new Packrat.Traits (Word_Enum, Character, String); + package Swordy is new Packrat.Lexer (Swordy_Traits); package Swolbug is new Swordy.Debug; - use type Word_Tokens.Token; - use type Word_Tokens.Token_Array; + use type Swordy_Traits.Tokens.Token; + use type Swordy_Traits.Tokens.Token_Array; function Satisfy_Letter is new Swordy.Satisfy (PU.Is_Letter); function Many_Letter is new Swordy.Many (Satisfy_Letter, 1); @@ -673,15 +675,15 @@ package body Rat_Tests.Lexer is Test_Str : String := "one fine day"; Test_Context : Swordy.Lexer_Context := Swordy.Empty_Context; - Intended_Result1 : Word_Tokens.Token_Array := - (1 => Word_Tokens.Create (Word, 1, "one"), - 2 => Word_Tokens.Create (Word, 5, "fine")); - Intended_Result2 : Word_Tokens.Token_Array := - (1 => Word_Tokens.Create (Word, 10, "day")); + Intended_Result1 : Swordy_Traits.Tokens.Token_Array := + (1 => Swordy_Traits.Tokens.Create (Word, 1, "one"), + 2 => Swordy_Traits.Tokens.Create (Word, 5, "fine")); + Intended_Result2 : Swordy_Traits.Tokens.Token_Array := + (1 => Swordy_Traits.Tokens.Create (Word, 10, "day")); - Actual_Result1 : Word_Tokens.Token_Array := + Actual_Result1 : Swordy_Traits.Tokens.Token_Array := My_Scan (Test_Str, Test_Context); - Actual_Result2 : Word_Tokens.Token_Array := + Actual_Result2 : Swordy_Traits.Tokens.Token_Array := My_Scan ("", Test_Context); begin if Actual_Result1 /= Intended_Result1 or Actual_Result2 /= Intended_Result2 then @@ -700,12 +702,12 @@ package body Rat_Tests.Lexer is Test_Str : String := "one fine day"; Test_Context : Swordy.Lexer_Context := Swordy.Empty_Context; - Intended_Result : Word_Tokens.Token_Array := - (1 => Word_Tokens.Create (Word, 1, "one"), - 2 => Word_Tokens.Create (Word, 5, "fine"), - 3 => Word_Tokens.Create (Word, 10, "day")); + Intended_Result : Swordy_Traits.Tokens.Token_Array := + (1 => Swordy_Traits.Tokens.Create (Word, 1, "one"), + 2 => Swordy_Traits.Tokens.Create (Word, 5, "fine"), + 3 => Swordy_Traits.Tokens.Create (Word, 10, "day")); - Actual_Result : Word_Tokens.Token_Array := + Actual_Result : Swordy_Traits.Tokens.Token_Array := My_Scan (Test_Str, Test_Context); begin if Actual_Result /= Intended_Result then @@ -738,17 +740,17 @@ package body Rat_Tests.Lexer is Test_Context : Swordy.Lexer_Context := Swordy.Empty_Context; - Intended_Result : Word_Tokens.Token_Array := - (1 => Word_Tokens.Create (Word, 1, "it"), - 2 => Word_Tokens.Create (Word, 4, "will"), - 3 => Word_Tokens.Create (Word, 9, "happen"), - 4 => Word_Tokens.Create (Word, 17, "again"), - 5 => Word_Tokens.Create (Word, 23, "and"), - 6 => Word_Tokens.Create (Word, 27, "again"), - 7 => Word_Tokens.Create (Word, 33, "and"), - 8 => Word_Tokens.Create (Word, 37, "again")); - - Actual_Result : Word_Tokens.Token_Array := + Intended_Result : Swordy_Traits.Tokens.Token_Array := + (1 => Swordy_Traits.Tokens.Create (Word, 1, "it"), + 2 => Swordy_Traits.Tokens.Create (Word, 4, "will"), + 3 => Swordy_Traits.Tokens.Create (Word, 9, "happen"), + 4 => Swordy_Traits.Tokens.Create (Word, 17, "again"), + 5 => Swordy_Traits.Tokens.Create (Word, 23, "and"), + 6 => Swordy_Traits.Tokens.Create (Word, 27, "again"), + 7 => Swordy_Traits.Tokens.Create (Word, 33, "and"), + 8 => Swordy_Traits.Tokens.Create (Word, 37, "again")); + + Actual_Result : Swordy_Traits.Tokens.Token_Array := My_Scan (More_Input'Unrestricted_Access, Test_Context); begin if Actual_Result /= Intended_Result then @@ -763,27 +765,27 @@ package body Rat_Tests.Lexer is is procedure My_Scan is new Swordy.Scan_Set ((Stamp_Word'Access, Ignore_Whitespace'Access), - Latin.EOT, Word_Tokens.Create (Blank, 1, "")); + Latin.EOT, Swordy_Traits.Tokens.Create (Blank, 1, "")); Test_Str1 : String (1 .. 10) := "one tw"; Test_Str2 : String (1 .. 10) := "o three"; Test_Str3 : String (1 .. 10) := Latin.EOT & " "; Test_Context : Swordy.Lexer_Context := Swordy.Empty_Context; - Intended_Result1 : Word_Tokens.Token_Array := - (1 => Word_Tokens.Create (Word, 1, "one"), - 2 => Word_Tokens.Create (Blank, 1, ""), - 3 => Word_Tokens.Create (Blank, 1, "")); - Intended_Result2 : Word_Tokens.Token_Array := - (1 => Word_Tokens.Create (Word, 9, "two"), - 2 => Word_Tokens.Create (Blank, 1, ""), - 3 => Word_Tokens.Create (Blank, 1, "")); - Intended_Result3 : Word_Tokens.Token_Array := - (1 => Word_Tokens.Create (Word, 16, "three"), - 2 => Word_Tokens.Create (Blank, 1, ""), - 3 => Word_Tokens.Create (Blank, 1, "")); - - Actual_Result : Word_Tokens.Token_Array (1 .. 3); + Intended_Result1 : Swordy_Traits.Tokens.Token_Array := + (1 => Swordy_Traits.Tokens.Create (Word, 1, "one"), + 2 => Swordy_Traits.Tokens.Create (Blank, 1, ""), + 3 => Swordy_Traits.Tokens.Create (Blank, 1, "")); + Intended_Result2 : Swordy_Traits.Tokens.Token_Array := + (1 => Swordy_Traits.Tokens.Create (Word, 9, "two"), + 2 => Swordy_Traits.Tokens.Create (Blank, 1, ""), + 3 => Swordy_Traits.Tokens.Create (Blank, 1, "")); + Intended_Result3 : Swordy_Traits.Tokens.Token_Array := + (1 => Swordy_Traits.Tokens.Create (Word, 16, "three"), + 2 => Swordy_Traits.Tokens.Create (Blank, 1, ""), + 3 => Swordy_Traits.Tokens.Create (Blank, 1, "")); + + Actual_Result : Swordy_Traits.Tokens.Token_Array (1 .. 3); begin My_Scan (Test_Str1, Test_Context, Actual_Result); if Actual_Result /= Intended_Result1 then @@ -821,24 +823,24 @@ package body Rat_Tests.Lexer is procedure My_Scan is new Swordy.Scan_Set_With ((Stamp_Word'Access, Ignore_Whitespace'Access), - Latin.EOT, Word_Tokens.Create (Blank, 1, "")); + Latin.EOT, Swordy_Traits.Tokens.Create (Blank, 1, "")); Test_Context : Swordy.Lexer_Context := Swordy.Empty_Context; - Intended_Result1 : Word_Tokens.Token_Array := - (1 => Word_Tokens.Create (Word, 1, "it"), - 2 => Word_Tokens.Create (Word, 4, "will"), - 3 => Word_Tokens.Create (Word, 9, "happen"), - 4 => Word_Tokens.Create (Word, 16, "again"), - 5 => Word_Tokens.Create (Word, 22, "and")); - Intended_Result2 : Word_Tokens.Token_Array := - (1 => Word_Tokens.Create (Word, 26, "again"), - 2 => Word_Tokens.Create (Word, 32, "and"), - 3 => Word_Tokens.Create (Word, 36, "again"), - 4 => Word_Tokens.Create (Blank, 1, ""), - 5 => Word_Tokens.Create (Blank, 1, "")); - - Actual_Result : Word_Tokens.Token_Array (1 .. 5); + Intended_Result1 : Swordy_Traits.Tokens.Token_Array := + (1 => Swordy_Traits.Tokens.Create (Word, 1, "it"), + 2 => Swordy_Traits.Tokens.Create (Word, 4, "will"), + 3 => Swordy_Traits.Tokens.Create (Word, 9, "happen"), + 4 => Swordy_Traits.Tokens.Create (Word, 16, "again"), + 5 => Swordy_Traits.Tokens.Create (Word, 22, "and")); + Intended_Result2 : Swordy_Traits.Tokens.Token_Array := + (1 => Swordy_Traits.Tokens.Create (Word, 26, "again"), + 2 => Swordy_Traits.Tokens.Create (Word, 32, "and"), + 3 => Swordy_Traits.Tokens.Create (Word, 36, "again"), + 4 => Swordy_Traits.Tokens.Create (Blank, 1, ""), + 5 => Swordy_Traits.Tokens.Create (Blank, 1, "")); + + Actual_Result : Swordy_Traits.Tokens.Token_Array (1 .. 5); begin My_Scan (More_Input'Unrestricted_Access, Test_Context, Actual_Result); if Actual_Result /= Intended_Result1 then @@ -867,7 +869,7 @@ package body Rat_Tests.Lexer is ((+"WORD", 1), (+"WHITESPACE", 1)); begin declare - Result : Word_Tokens.Token_Array := My_Scan (Test_Str, Test_Context); + Result : Swordy_Traits.Tokens.Token_Array := My_Scan (Test_Str, Test_Context); begin return Fail; end; @@ -895,7 +897,7 @@ package body Rat_Tests.Lexer is ((+"WORD", 1), (+"WHITESPACE", 1)); begin declare - Result : Word_Tokens.Token_Array := My_Scan (Test_Str, Test_Context); + Result : Swordy_Traits.Tokens.Token_Array := My_Scan (Test_Str, Test_Context); begin return Fail; end; @@ -934,7 +936,7 @@ package body Rat_Tests.Lexer is ((+"WORD", 1), (+"WHITESPACE", 1)); begin declare - Result : Word_Tokens.Token_Array := + Result : Swordy_Traits.Tokens.Token_Array := My_Scan (Get_Input'Unrestricted_Access, Test_Context); begin return Fail; @@ -955,12 +957,12 @@ package body Rat_Tests.Lexer is procedure My_Scan is new Swordy.Scan_Set ((Stamp_Word'Access, Ignore_Whitespace'Access), - Latin.EOT, Word_Tokens.Create (Blank, 1, "")); + Latin.EOT, Swordy_Traits.Tokens.Create (Blank, 1, "")); Test_Str : String := "()()"; Test_Context : Swordy.Lexer_Context := Swordy.Empty_Context; - Result : Word_Tokens.Token_Array (1 .. 5); + Result : Swordy_Traits.Tokens.Token_Array (1 .. 5); Expected_Errors : Packrat.Errors.Error_Info_Array := ((+"WORD", 1), (+"WHITESPACE", 1)); @@ -995,11 +997,11 @@ package body Rat_Tests.Lexer is procedure My_Scan is new Swordy.Scan_Set_With ((Stamp_Word'Access, Ignore_Whitespace'Access), - Latin.EOT, Word_Tokens.Create (Blank, 1, "")); + Latin.EOT, Swordy_Traits.Tokens.Create (Blank, 1, "")); Test_Context : Swordy.Lexer_Context := Swordy.Empty_Context; - Result : Word_Tokens.Token_Array (1 .. 5); + Result : Swordy_Traits.Tokens.Token_Array (1 .. 5); Expected_Errors : Packrat.Errors.Error_Info_Array := ((+"WORD", 1), (+"WHITESPACE", 1)); -- cgit