summaryrefslogtreecommitdiff
path: root/src/packrat-lexer.ads
blob: d331645f423a1ad44dc4eac36aed499f2a2fd3bc (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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170


generic

    type Label_Enum is (<>);
    type Element is private;
    type Element_Array is array (Positive range <>) of Element;

    with package Gen_Tokens is new Tokens (Label_Enum, Element, Element_Array);

package Packrat.Lexer is


    type Combinator_Result is new Ada.Finalization.Controlled with private;

    type Combinator is access function
           (Input : in Element_Array;
            Start : in Positive)
        return Combinator_Result;

    type Combinator_Array is array (Positive range <>) of Combinator;

    Empty_Fail : constant Combinator_Result;


    function Create_Result
           (Length : in Natural;
            Status : in Result_Status;
            Value  : in Element_Array)
        return Combinator_Result;

    function Join
           (Left, Right : in Combinator_Result)
        return Combinator_Result;

    function "="
           (Left, Right : in Combinator_Result)
        return Boolean;

    function Status
           (This : in Combinator_Result)
        return Result_Status;

    function Debug_String
           (This : in Combinator_Result)
        return String;




    type Lexer_Context is new Ada.Finalization.Controlled with private;

    Empty_Context : constant Lexer_Context;




    type Lexer_Component is access procedure
           (Context : in out Lexer_Context);

    type Component_Array is array (Positive range <>) of Lexer_Component;

    generic
        Label : in Label_Enum;
        Combo : in Combinator;
    procedure Stamp
           (Context : in out Lexer_Context);

    generic
        Combo : in Combinator;
    procedure Ignore
           (Context : in out Lexer_Context);




    generic
        Components : in Component_Array;
    function Scan
           (Input   : in     Element_Array;
            Context : in out Lexer_Context)
        return Gen_Tokens.Token_Array;

    generic
        Components : in Component_Array;
        Padding    : in Gen_Tokens.Token;
    procedure Scan_Set
           (Input   : in     Element_Array;
            Context : in out Lexer_Context;
            Output  :    out Gen_Tokens.Token_Array);

    generic
        Components : in Component_Array;
    function Scan_Only
           (Input   : in     Element_Array;
            Context : in out Lexer_Context)
        return Gen_Tokens.Token_Array;

    generic
        Gomponents : in Component_Array;
        Padding    : in Gen_Tokens.Token;
    procedure Scan_Set_Only
           (Input   : in     Element_Array;
            Context : in out Lexer_Context;
            Output  :    out Gen_Tokens.Token_Array);

    generic
        Components : in Component_Array;
        with function More
            return Element_Array;
    function Scan_With
           (Input   : in     Element_Array;
            Context : in out Lexer_Context)
        return Gen_Tokens.Token_Array;

    generic
        Components : in Component_Array;
        Padding    : in Gen_Tokens.Token;
        with function More
            return Element_Array;
    procedure Scan_Set_With
           (Input   : in     Element_Array;
            Context : in out Lexer_Context;
            Output  :    out Gen_Tokens.Token_Array);


private


    type Element_Array_Access is access Element_Array;


    Empty_Array : Element_Array (1 .. 0);


    type Combinator_Result is new Ada.Finalization.Controlled with record
        Length : Natural;
        Status : Result_Status;
        Value  : Element_Array_Access;
    end record;


    overriding procedure Initialize
           (This : in out Combinator_Result);

    overriding procedure Adjust
           (This : in out Combinator_Result);

    overriding procedure Finalize
           (This : in out Combinator_Result);


    Empty_Fail : constant Combinator_Result :=
       (Ada.Finalization.Controlled with
        Length => 0,
        Status => Failure,
        Value  => null);




    type Lexer_Context is new Ada.Finalization.Controlled with null record;


    Empty_Context : constant Lexer_Context := (Ada.Finalization.Controlled with null record);


end Packrat.Lexer;