summaryrefslogtreecommitdiff
path: root/src/packrat.ads
blob: 1c81958d4b205cb6f5c3451fc73cda886cf9cb7e (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


with

    Ada.Strings.Unbounded;


package Packrat is


    Parse_Error : exception;




    package Errors is


        subtype Error_Message is String
            with Dynamic_Predicate => Valid_Message (Error_Message);

        type Error_Info is record
            Symbol   : Ada.Strings.Unbounded.Unbounded_String;
            Position : Natural;
        end record;

        type Error_Info_Array is array (Positive range <>) of Error_Info;


        --  Note: No consideration is given to ordering of Error_Info items
        --        encoded into an Error_Message string.

        --  Note: Using "&" to join two Valid Error_Messages together
        --        will result in an Error_Message that is also Valid,
        --        but for best results Join should be used instead to
        --        prevent duplication of Error_Info in the message.


        function Valid_Identifier
               (Check : in String)
            return Boolean;

        function Valid_Identifier
               (Check : in Ada.Strings.Unbounded.Unbounded_String)
            return Boolean;

        function Valid_Identifier_Array
               (Check : in Error_Info_Array)
            return Boolean;

        function Valid_Message
               (Check : in String)
            return Boolean;


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


        function Encode
               (Name : in String;
                Pos  : in Natural)
            return Error_Message
            with Pre => Valid_Identifier (Name);

        function Encode
               (Name : in Ada.Strings.Unbounded.Unbounded_String;
                Pos  : in Natural)
            return Error_Message
            with Pre => Valid_Identifier (Name);

        function Encode
               (Info : in Error_Info)
            return Error_Message
            with Pre => Valid_Identifier (Info.Symbol);

        function Encode_Array
               (Info : in Error_Info_Array)
            return Error_Message
            with Pre => Valid_Identifier_Array (Info);

        function Decode
               (Msg : in Error_Message)
            return Error_Info_Array;


    end Errors;


private


    function "+"
           (S : in String)
        return Ada.Strings.Unbounded.Unbounded_String
        renames Ada.Strings.Unbounded.To_Unbounded_String;

    function "-"
           (US : in Ada.Strings.Unbounded.Unbounded_String)
        return String
        renames Ada.Strings.Unbounded.To_String;


end Packrat;