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 --- src/packrat.ads | 156 -------------------------------------------------------- 1 file changed, 156 deletions(-) (limited to 'src/packrat.ads') diff --git a/src/packrat.ads b/src/packrat.ads index 58afbaa..7f124e1 100644 --- a/src/packrat.ads +++ b/src/packrat.ads @@ -4,10 +4,6 @@ with Ada.Strings.Unbounded; -private with - - Ada.Containers.Indefinite_Holders; - package Packrat is @@ -19,158 +15,6 @@ package Packrat is Lexer_Error : exception; - - -- need to restructure all this to separate these nested packages out into their own files - -- and also to add in a Traits package to contain the Enum/Element/Array generic stuff - - - - package Errors is - - - subtype Error_Message is String - with Dynamic_Predicate => Valid_Message (Error_Message); - - type Error_Info is record - Symbol : Ada.Strings.Unbounded.Unbounded_String; - Position : Natural; - end record; - - type Error_Info_Array is array (Positive range <>) of Error_Info; - - - -- Note: No consideration is given to ordering of Error_Info items - -- encoded into an Error_Message string. - - -- Note: Using "&" to join two Valid Error_Messages together - -- will result in an Error_Message that is also Valid, - -- but for best results Join should be used instead to - -- prevent duplication of Error_Info in the message. - - - function Valid_Identifier - (Check : in String) - return Boolean; - - function Valid_Identifier - (Check : in Ada.Strings.Unbounded.Unbounded_String) - return Boolean; - - function Valid_Identifier_Array - (Check : in Error_Info_Array) - return Boolean; - - function Valid_Message - (Check : in String) - return Boolean; - - function Debug_String - (This : in Error_Message) - return String; - - - function Join - (Left, Right : in Error_Message) - return Error_Message; - - - function Encode - (Name : in String; - Pos : in Natural) - return Error_Message - with Pre => Valid_Identifier (Name); - - function Encode - (Name : in Ada.Strings.Unbounded.Unbounded_String; - Pos : in Natural) - return Error_Message - with Pre => Valid_Identifier (Name); - - function Encode - (Info : in Error_Info) - return Error_Message - with Pre => Valid_Identifier (Info.Symbol); - - function Encode_Array - (Info : in Error_Info_Array) - return Error_Message - with Pre => Valid_Identifier_Array (Info); - - function Decode - (Msg : in Error_Message) - return Error_Info_Array; - - - end Errors; - - - - - generic - type Label_Enum is (<>); - type Element_Type is private; - type Element_Array is array (Positive range <>) of Element_Type; - with function "<" (Left, Right : in Element_Type) return Boolean is <>; - package Tokens is - - - type Token is private; - type Token_Array is array (Positive range <>) of Token; - - - function "<" - (Left, Right : in Token) - return Boolean; - - - function Create - (Ident : in Label_Enum; - Start : in Positive; - Value : in Element_Array) - return Token; - - - -- Note: The Start index indicates where the token was found - -- in whatever array it was lexed from. The Value does *not* - -- have to correspond with whatever is found there. - - - function Debug_String - (This : in Token) - return String; - - - function Label - (This : in Token) - return Label_Enum; - - function Start - (This : in Token) - return Positive; - - function Value - (This : in Token) - return Element_Array; - - - private - - - package Value_Holders is new Ada.Containers.Indefinite_Holders (Element_Array); - - - type Token is record - Identifier : Label_Enum; - Start_At : Positive; - Token_Value : Value_Holders.Holder; - end record; - - - end Tokens; - - - - private -- cgit