gnoga_2.1.2_5f127c56/deps/simple_components/parsers-json.ads

  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
203
204
205
206
207
208
209
210
211
212
213
214
215
--                                                                    --
--  package                         Copyright (c)  Dmitry A. Kazakov  --
--     Parsers.JSON                                Luebeck            --
--  Implementation                                 Autumn, 2019       --
--                                                                    --
--                                Last revision :  19:57 14 Sep 2019  --
--                                                                    --
--  This  library  is  free software; you can redistribute it and/or  --
--  modify it under the terms of the GNU General Public  License  as  --
--  published by the Free Software Foundation; either version  2  of  --
--  the License, or (at your option) any later version. This library  --
--  is distributed in the hope that it will be useful,  but  WITHOUT  --
--  ANY   WARRANTY;   without   even   the   implied   warranty   of  --
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  --
--  General  Public  License  for  more  details.  You  should  have  --
--  received  a  copy  of  the GNU General Public License along with  --
--  this library; if not, write to  the  Free  Software  Foundation,  --
--  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.    --
--                                                                    --
--  As a special exception, if other files instantiate generics from  --
--  this unit, or you link this unit with other files to produce  an  --
--  executable, this unit does not by  itself  cause  the  resulting  --
--  executable to be covered by the GNU General Public License. This  --
--  exception  does not however invalidate any other reasons why the  --
--  executable file might be covered by the GNU Public License.       --
--____________________________________________________________________--

with Ada.Strings.Maps;  use Ada.Strings.Maps;
with Strings_Edit;      use Strings_Edit;

package Parsers.JSON is
--
-- JSON_Value_Type -- The JSON value type
--
   type JSON_Value_Type is
        (  JSON_Boolean, -- True / False
           JSON_Null,    -- Null
           JSON_Number,  -- Numeric value
           JSON_String,  -- Text
           JSON_Array,   -- Array of any values, a sequence
           JSON_Object   -- Name to value mapping
        );
--
-- JSON_Value -- The JSON value
--
   type JSON_String_Ptr is access constant String;
   type JSON_Value;
   type JSON_Value_Ptr is access constant JSON_Value;
   type JSON_Sequence;
   type JSON_Sequence_Ptr is access constant JSON_Sequence;
   type JSON_Pair_Array;
   type JSON_Pair_Array_Ptr is access constant JSON_Pair_Array;
   type JSON_Value
        (  JSON_Type : JSON_Value_Type := JSON_Boolean
        )  is
   record
      case JSON_Type is
         when JSON_Boolean =>
            Condition : Boolean := False;
         when JSON_Null =>
            null;
         when JSON_Number =>
            Value     : Long_Float := 0.0;
         when JSON_String =>
            Text      : JSON_String_Ptr;
         when JSON_Array =>
            Sequence  : JSON_Sequence_Ptr;
         when JSON_Object =>
            Map       : JSON_Pair_Array_Ptr;
      end case;
   end record;
   type JSON_Sequence is array (Positive range <>) of JSON_Value;
   type JSON_Pair is record
      Name  : JSON_String_Ptr;
      Value : JSON_Value;
   end record;
   type JSON_Pair_Array is array (Positive range <>) of JSON_Pair;
--
-- Put -- Put a value in JSON format
--
--    Destination - The string that accepts the output
--    Pointer     - The current position in the string
--    Value       - The value to be put
--    Escape      - Escape any non-printable or non-ASCII characters
--    Field       - The output field
--    Justify     - Alignment within the field
--    Fill        - The fill character
--
-- Exceptions:
--
--    Data_Error   - Invalid UTF-8 encoding of a string or tag
--    Layout_Error - Pointer is  not in Destination'Range or there is no
--                   room for the output.
--
   procedure Put
             (  Destination : in out String;
                Pointer     : in out Integer;
                Value       : JSON_Sequence;
                Escape      : Boolean   := False;
                Field       : Natural   := 0;
                Justify     : Alignment := Left;
                Fill        : Character := ' '
             );
   procedure Put
             (  Destination : in out String;
                Pointer     : in out Integer;
                Value       : JSON_Pair_Array;
                Escape      : Boolean   := False;
                Field       : Natural   := 0;
                Justify     : Alignment := Left;
                Fill        : Character := ' '
             );
   procedure Put
             (  Destination : in out String;
                Pointer     : in out Integer;
                Value       : JSON_Value;
                Escape      : Boolean   := False;
                Field       : Natural   := 0;
                Justify     : Alignment := Left;
                Fill        : Character := ' '
             );
   procedure Put
             (  Destination : in out String;
                Pointer     : in out Integer;
                Value       : String;
                Escape      : Boolean   := False;
                Field       : Natural   := 0;
                Justify     : Alignment := Left;
                Fill        : Character := ' '
             );
--
-- Image -- String in JSON format
--
--    Value  - The value to be converted
--    Escape - Escape any non-printable or non-ASCII characters
--
-- Returns :
--
--    The result string
--
-- Exceptions:
--
--    Data_Error - Invalid UTF-8 encoding of a string or tag
--
   function Image
            (  Value  : JSON_Sequence;
               Escape : Boolean := False
            )  return String;
   function Image
            (  Value  : JSON_Pair_Array;
               Escape : Boolean := False
            ) return String;
   function Image
            (  Value  : JSON_Value;
               Escape : Boolean := False
            )  return String;
   function Image
            (  Value  : String;
               Escape : Boolean := False
            )  return String;

private
   WS : constant Character_Set :=
                    To_Set
                    (  ' '
                    &  Character'Val (9)
                    &  Character'Val (10)
                    &  Character'Val (13)
                    );
--
-- Check_Spelling -- Of a name, no checks
--
   procedure Check_Spelling (Name : String);
--
-- Check_Matched -- Check if no broken keyword matched
--
   function Check_Matched (Source : String; Pointer : Integer)
      return Boolean;
--
-- Operations -- All the operations supported
--
   type Operations is
        (  Comma,        Colon,        -- Commas , and :
           Left_Brace,   Right_Brace,  -- Braces {}
           Left_Bracket, Right_Bracket -- Brackets []
        );
--
-- "and" -- Checks operation associations, always True (Ok)
--
   function "and" (Left, Right : Operations) return Boolean;
--
-- Is_Commutative -- No commutative operations, always False
--
   function Is_Commutative (Left, Right : Operations) return Boolean;
--
-- Is_Inverse -- No commutative operations, always False
--
   function Is_Inverse (Operation : Operations) return Boolean;
--
-- Group_Inverse -- No commutative operations, never called
--
   function Group_Inverse (Operation : Operations) return Operations;
--
-- Priorities -- The levels of association
--
   type Priorities is mod 2;
--
-- Tokens -- The lexical tokens
--
   type JSON_Argument is record
      Name  : JSON_String_Ptr;
      Value : JSON_Value;
   end record;

end Parsers.JSON;