blob: 387c02c41fd7d93ae2d96e745882b22b144d1b65 (
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
|
with
Ada.Text_IO,
Packrat.No_Lex,
Packrat.Utilities;
use
Ada.Text_IO;
procedure Ssss is
Input : String := "xxxx";
type Parser_Labels is (S, X);
package My_Rat is new Packrat.No_Lex (Parser_Labels, Character, String);
package S_Redir is new My_Rat.Parsers.Redirect;
function Match_X is new My_Rat.Parsers.Match ('x');
function Let_X is new My_Rat.Parsers.Stamp (X, Match_X);
function S_Seq is new My_Rat.Parsers.Sequence
((Let_X'Access, S_Redir.Call'Access, S_Redir.Call'Access));
function S_Choice is new My_Rat.Parsers.Choice
((S_Seq'Access, My_Rat.Parsers.Empty'Access));
function S is new My_Rat.Parsers.Stamp (S, S_Choice);
package Parser is new My_Rat.Parsers.Parse_Once (S);
Result_Graph : My_Rat.Parser_Result;
begin
S_Redir.Set (S'Access);
Result_Graph := Parser.Parse (Input);
Put_Line ("Input:");
Put_Line (Input);
New_Line;
Put_Line ("Parser graph output:");
Put_Line (My_Rat.Parse_Graphs.Debug_String (Result_Graph));
New_Line;
Put_Line ("Root tokens:");
for T of Result_Graph.Root_Elements loop
Put (My_Rat.Parser_Tokens.Debug_String (T));
end loop;
end Ssss;
|