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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
-- This source is licensed under the Sunset License v1.0
with
Unit_Tests;
use
Unit_Tests;
private with
Packrat.No_Lex,
Packrat.Utilities,
Packrat.Parsers.Debug,
Packrat.Errors,
Packrat.Traits;
package Rat_Tests.Parsers is
function Sequence_Check return Test_Result;
function Sequence_2_Check return Test_Result;
function Choice_Check return Test_Result;
function Choice_2_Check return Test_Result;
function Count_Check return Test_Result;
function Many_Nomin_Check return Test_Result;
function Many_Min_Check return Test_Result;
function Followed_By_Check return Test_Result;
function Not_Followed_By_Check return Test_Result;
function Many_Until_Nomin_Check return Test_Result;
function Many_Until_Min_Check return Test_Result;
function Satisfy_Check return Test_Result;
function Satisfy_With_Check return Test_Result;
function Match_Check return Test_Result;
function Match_With_Check return Test_Result;
function Multimatch_Check return Test_Result;
function Take_Check return Test_Result;
function Take_While_Check return Test_Result;
function Take_Until_Check return Test_Result;
function Empty_Check return Test_Result;
function Not_Empty_Check return Test_Result;
Combinator_Tests : Test_Array :=
((+"Sequence", Sequence_Check'Access),
(+"Sequence_2", Sequence_2_Check'Access),
(+"Choice", Choice_Check'Access),
(+"Choice_2", Choice_2_Check'Access),
(+"Count", Count_Check'Access),
(+"Many No Minimum", Many_Nomin_Check'Access),
(+"Many With Minimum", Many_Min_Check'Access),
(+"Followed_By", Followed_By_Check'Access),
(+"Not_Followed_By", Not_Followed_By_Check'Access),
(+"Many_Until No Minimum", Many_Until_Nomin_Check'Access),
(+"Many_Until With Minimum", Many_Until_Min_Check'Access),
(+"Satisfy", Satisfy_Check'Access),
(+"Satisfy_With", Satisfy_With_Check'Access),
(+"Match", Match_Check'Access),
(+"Match_With", Match_With_Check'Access),
(+"Multimatch", Multimatch_Check'Access),
(+"Take", Take_Check'Access),
(+"Take_While", Take_While_Check'Access),
(+"Take_Until", Take_Until_Check'Access),
(+"Empty", Empty_Check'Access),
(+"Not_Empty", Not_Empty_Check'Access));
function Parse_Parts_Check return Test_Result;
function Parse_Parts_Left_Check return Test_Result;
function Parse_Parts_Exception_Check return Test_Result;
function Parse_Once_Check return Test_Result;
function Parse_Once_Exception_Check return Test_Result;
Parser_Tests : Test_Array :=
((+"Parse_Parts", Parse_Parts_Check'Access),
(+"Parse_Parts Left Recursive", Parse_Parts_Left_Check'Access),
(+"Parse_Parts Exception", Parse_Parts_Exception_Check'Access),
(+"Parse_Once", Parse_Once_Check'Access),
(+"Parse_Once Exception", Parse_Once_Exception_Check'Access));
function Default_Result_Check return Test_Result;
function Left_Recursion_Check return Test_Result;
Other_Tests : Test_Array :=
((+"Default Combinator Result", Default_Result_Check'Access),
(+"Left Recursion", Left_Recursion_Check'Access));
private
type Parser_Labels_One is (One, Two, Three, Four, Five, Six);
package Pone is new Packrat.No_Lex
(Parser_Labels_One, Character, String);
package One_Debug is new Pone.Parsers.Debug;
function Match_AB is new Pone.Parsers.Multimatch ("ab");
function Match_CDE is new Pone.Parsers.Multimatch ("cde");
function Match_FG is new Pone.Parsers.Multimatch ("fg");
function Seq_ABCDEFG is new Pone.Parsers.Sequence
((Match_AB'Access, Match_CDE'Access, Match_FG'Access));
function Match_C is new Pone.Parsers.Match ('c');
function Many_C is new Pone.Parsers.Many (Match_C, 1);
function Match_CC is new Pone.Parsers.Multimatch ("cc");
function Match_CCCDE is new Pone.Parsers.Multimatch ("cccde");
function Choose_CCCDE is new Pone.Parsers.Choice
((Many_C'Access, Match_CC'Access, Match_CCCDE'Access));
type Add_Sub_Labels is (Sum, Number);
package Left_Sums is new Packrat.No_Lex
(Add_Sub_Labels, Character, String);
package Sum_Redir is new Left_Sums.Parsers.Redirect;
function Sat_Digit is new Left_Sums.Parsers.Satisfy (Packrat.Utilities.Is_Digit);
function Factor is new Left_Sums.Parsers.Stamp (Number, Sat_Digit);
function Match_Plus is new Left_Sums.Parsers.Match ('+');
function Match_Minus is new Left_Sums.Parsers.Match ('-');
function Sum_Plus is new Left_Sums.Parsers.Sequence
((Sum_Redir.Call'Access, Match_Plus'Access, Factor'Access));
function Sum_Minus is new Left_Sums.Parsers.Sequence
((Sum_Redir.Call'Access, Match_Minus'Access, Factor'Access));
function Sum_Choice is new Left_Sums.Parsers.Choice
((Sum_Plus'Access, Sum_Minus'Access, Factor'Access));
function Sum is new Left_Sums.Parsers.Stamp (Sum, Sum_Choice);
function Sum_Expr is new Left_Sums.Parsers.Sequence_2 (Sum, Left_Sums.Parsers.End_Of_Input);
package Sum_Parse_Once is new Left_Sums.Parsers.Parse_Once (Sum_Expr);
package Add_Redir is new Left_Sums.Parsers.Redirect;
function Add_Plus is new Left_Sums.Parsers.Sequence
((Add_Redir.Call'Access, Match_Plus'Access, Factor'Access));
function Add_Choice is new Left_Sums.Parsers.Choice_2 (Add_Plus, Factor);
function Add is new Left_Sums.Parsers.Stamp (Sum, Add_Choice);
function Add_Expr is new Left_Sums.Parsers.Sequence_2 (Add, Left_Sums.Parsers.End_Of_Input);
package Add_Parse_Once is new Left_Sums.Parsers.Parse_Once (Add_Expr);
package Add_Parse_Parts is new Left_Sums.Parsers.Parse_Parts (Add_Expr);
type Add_Error_Labels is (Sum_Err, Plus_Err, Number_Err, Eof_Err);
package Add_Errors is new Packrat.No_Lex
(Add_Error_Labels, Character, String);
package Adder_Redir is new Add_Errors.Parsers.Redirect;
function Sater_Digit is new Add_Errors.Parsers.Satisfy (Packrat.Utilities.Is_Digit);
function Stamper_Number is new Add_Errors.Parsers.Stamp (Number_Err, Sater_Digit);
function Matcher_Plus is new Add_Errors.Parsers.Match ('+');
function Discarder_Plus is new Add_Errors.Parsers.Discard (Plus_Err, Matcher_Plus);
function Sumer_Plus is new Add_Errors.Parsers.Sequence
((Stamper_Number'Access, Discarder_Plus'Access, Adder_Redir.Call'Access));
function Sumer_Choice is new Add_Errors.Parsers.Choice
((Sumer_Plus'Access, Stamper_Number'Access));
function Sumer is new Add_Errors.Parsers.Stamp (Sum_Err, Sumer_Choice);
function Discarder_End is new Add_Errors.Parsers.Discard
(Eof_Err, Add_Errors.Parsers.End_Of_Input);
function Sumer_Expr is new Add_Errors.Parsers.Sequence_2 (Sumer, Discarder_End);
package Adder_Parse_Once is new Add_Errors.Parsers.Parse_Once (Sumer_Expr);
package Adder_Parse_Parts is new Add_Errors.Parsers.Parse_Parts (Sumer_Expr);
function Alphanum_Switch
(Char : in Character)
return Character;
end Rat_Tests.Parsers;
|