summaryrefslogtreecommitdiff
path: root/src/packrat-tokens.ads
blob: d636f55913018248ea57d81ab3420465c80d8eff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136


--  This source is licensed under the Sunset License v1.0


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 <>;
    with function "<" (Left, Right : in Element_Array) return Boolean is <>;

package Packrat.Tokens is


    type Token_Type is private;
    type Token_Array is array (Positive range <>) of Token_Type;

    subtype Finish_Type is Natural;
    type Finish_Array is array (Positive range <>) of Finish_Type;

    type Finished_Token_Type is record
        Token  : Token_Type;
        Finish : Finish_Type;
    end record;

    type Finished_Token_Array is array (Positive range <>) of Finished_Token_Type;




    function "<"
           (Left, Right : in Token_Type)
        return Boolean;

    function "<"
           (Left, Right : in Token_Array)
        return Boolean;

    function "<"
           (Left, Right : in Finished_Token_Type)
        return Boolean;

    function "<"
           (Left, Right : in Finished_Token_Array)
        return Boolean;




    --  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 Create
           (Ident  : in Label_Enum;
            Start  : in Positive;
            Value  : in Element_Array)
        return Token_Type;




    function Debug_String
           (This : in Token_Type)
        return String;

    function Debug_String
           (This : in Finished_Token_Type)
        return String;




    function Label
           (This : in Token_Type)
        return Label_Enum;

    function Start
           (This : in Token_Type)
        return Positive;

    function Value
           (This : in Token_Type)
        return Element_Array;




    generic
        Ident : in Label_Enum;
    function Is_Label
           (This : in Token_Type)
        return Boolean;

    generic
        Start : in Positive;
    function Is_Start
           (This : in Token_Type)
        return Boolean;

    generic
        Value : in Element_Array;
    function Is_Value
           (This : in Token_Type)
        return Boolean;


private


    package Value_Holders is new Ada.Containers.Indefinite_Holders (Element_Array);


    function "<"
           (Left, Right : in Value_Holders.Holder)
        return Boolean;


    type Token_Type is record
        Identifier  : Label_Enum;
        Start_At    : Positive;
        Token_Value : Value_Holders.Holder;
    end record;


end Packrat.Tokens;