summaryrefslogtreecommitdiff
path: root/test/packrat-parsers-debug.adb
blob: 9e61bcc306649e3711f5853404c389c4f31c06c6 (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


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


with

    Ada.Characters.Latin_1,
    Ada.Strings.Unbounded;


package body Packrat.Parsers.Debug is


    package Latin renames Ada.Characters.Latin_1;
    package SU renames Ada.Strings.Unbounded;





    function Parts
           (This : in Combinator_Result)
        return Result_Part_Array
    is
        Arr : Result_Part_Array (1 .. Integer (This.Results.Length));
        Index : Positive := 1;
    begin
        for R of This.Results loop
            Arr (Index) := Result_Part (R);
            Index := Index + 1;
        end loop;
        return Arr;
    end Parts;


    function Curtails
           (This : in Combinator_Result)
        return Curtail_Map is
    begin
        return (This.Curtails with null record);
    end Curtails;


    function Status
           (This : in Combinator_Result)
        return Result_Status is
    begin
        return This.Status;
    end Status;





    function Finish
           (Part : in Result_Part)
        return Traits.Tokens.Finish_Type is
    begin
        return Part.Finish;
    end Finish;

    function Value
           (Part : in Result_Part)
        return Traits.Element_Array is
    begin
        if Part.Value.Is_Empty then
            return Arr : Traits.Element_Array (1 .. 0);
        else
            return Part.Value.Element;
        end if;
    end Value;

    function Tokens
           (Part : in Result_Part)
        return Traits.Tokens.Finished_Token_Array is
    begin
        if Part.Tokens.Is_Empty then
            return Arr : Traits.Tokens.Finished_Token_Array (1 .. 0);
        else
            return Part.Tokens.Element;
        end if;
    end Tokens;





    function Is_Empty
           (Curt : in Curtail_Map)
        return Boolean is
    begin
        return Packrat.Parsers.Curtail_Maps.Map (Curt).Is_Empty;
    end Is_Empty;





    function Debug_String
           (This : in Combinator_Result)
        return String
    is
        Str : SU.Unbounded_String;
        Index : Integer := 1;
    begin
        for Part of Parts (This) loop
            SU.Append (Str, "Part" & Integer'Image (Index) & ":" & Latin.LF);
            SU.Append (Str, Latin.HT & "Fin:" &
                Traits.Tokens.Finish_Type'Image (Finish (Part)) & Latin.LF);
            SU.Append (Str, Latin.HT & "Val:" & Integer'Image (Value (Part)'Length) & Latin.LF);
            SU.Append (Str, Latin.HT & "Tok:" & Latin.LF);
            for Tok of Tokens (Part) loop
                SU.Append (Str, Latin.HT & Latin.HT & Traits.Tokens.Debug_String (Tok) & Latin.LF);
            end loop;
            Index := Index + 1;
        end loop;
        SU.Append (Str, Latin.HT & "Status: " & Result_Status'Image (Status (This)) & Latin.LF);
        return -Str;
    end Debug_String;


end Packrat.Parsers.Debug;