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-tokens.ads | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/packrat-tokens.ads (limited to 'src/packrat-tokens.ads') diff --git a/src/packrat-tokens.ads b/src/packrat-tokens.ads new file mode 100644 index 0000000..bfb70ac --- /dev/null +++ b/src/packrat-tokens.ads @@ -0,0 +1,73 @@ + + +private with + + Ada.Containers.Indefinite_Holders; + + +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 Packrat.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 Packrat.Tokens; + + -- cgit