jintp_0.2.0_f1c20f36/src/jintp.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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
with Ada.Containers;
with Ada.Containers.Hashed_Maps;
with Ada.Finalization;
with Ada.Strings.Unbounded;
with Ada.Strings.Unbounded.Hash;

package Jintp is

   use Ada.Strings.Unbounded;

   Default_Expression_Start : constant String := "{{";
   Default_Expression_End : constant String := "}}";
   Default_Statement_Start : constant String := "{%";
   Default_Statement_End : constant String := "%}";
   Default_Comment_Start : constant String := "{#";
   Default_Comment_End : constant String := "#}";

   type Environment is new Ada.Finalization.Limited_Controlled with private;

   type Dictionary is new Ada.Finalization.Controlled with private;

   type List is new Ada.Finalization.Controlled with private;

   Template_Error : exception;

   overriding function "=" (Left, Right : Dictionary) return Boolean;

   overriding function "=" (Left, Right : List) return Boolean;

   function Render (File_Name : String;
                    Values : Dictionary)
                    return String;

   function Render (File_Name : String;
                    Values : Dictionary)
                    return Unbounded_String;

   procedure Configure (Settings : in out Environment;
                        Expression_Start : String := Default_Expression_Start;
                        Expression_End : String := Default_Expression_End;
                        Statement_Start : String := Default_Statement_Start;
                        Statement_End : String := Default_Statement_End;
                        Comment_Start : String := Default_Comment_Start;
                        Comment_End : String := Default_Comment_End;
                        Max_Cache_Size : Natural := 200;
                        Trim_Blocks : Boolean := False;
                        Lstrip_Blocks : Boolean := False);

   function Render (File_Name : String;
                    Values : Dictionary;
                    Settings : in out Environment'Class)
                    return String;

   function Render (File_Name : String;
                    Values : Dictionary;
                    Settings : in out Environment'Class)
                    return Unbounded_String;

   function Refers (Source : List'Class;
                    Target : Dictionary)
                    return Boolean;

   function Refers (Source : Dictionary'Class;
                    Target : Dictionary)
                    return Boolean;

   function Refers (Source : Dictionary'Class;
                    Target : List)
                    return Boolean;

   function Refers (Source : List'Class;
                    Target : List)
                    return Boolean;

   procedure Insert (Container : in out Dictionary;
                     Key : String;
                     New_Item : String);

   procedure Insert (Container : in out Dictionary;
                     Key : Unbounded_String;
                     New_Item : String);

   procedure Insert (Container : in out Dictionary;
                     Key : String;
                     New_Item : Unbounded_String);

   procedure Insert (Container : in out Dictionary;
                     Key : Unbounded_String;
                     New_Item : Unbounded_String);

   procedure Insert (Container : in out Dictionary;
                     Key : String;
                     New_Item : Integer);

   procedure Insert (Container : in out Dictionary;
                     Key : Unbounded_String;
                     New_Item : Integer);

   procedure Insert (Container : in out Dictionary;
                     Key : String;
                     New_Item : Boolean);

   procedure Insert (Container : in out Dictionary;
                     Key : String;
                     New_Item : List'Class)
   with Pre => not Refers (New_Item, Container);

   procedure Insert (Container : in out Dictionary;
                     Key : Unbounded_String;
                     New_Item : Boolean);

   procedure Insert (Container : in out Dictionary;
                     Key : String;
                     New_Item : Dictionary)
   with Pre => not Refers (New_Item, Container);

   procedure Append (Container : in out List;
                     New_Item : List)
   with Pre => not Refers (New_Item, Container);

   --  Enable precodition check for the following procedures
   --  to prevent the creation of cycles in the tree
   pragma Assertion_Policy (Pre => Check);

   procedure Insert (Container : in out Dictionary;
                     Key : Unbounded_String;
                     New_Item : List'Class)
     with Pre => not Refers (New_Item, Container)
     or else raise Template_Error with "inserting list would create cycle";

   procedure Insert (Container : in out Dictionary;
                     Key : Unbounded_String;
                     New_Item : Dictionary)
     with Pre => not Refers (New_Item, Container)
     or else raise Template_Error with "inserting dictionary would create cycle";

   procedure Insert (Container : in out Dictionary;
                     Key : Integer;
                     New_Item : String);

   procedure Insert (Container : in out Dictionary;
                     Key : Integer;
                     New_Item : Unbounded_String);

   procedure Insert (Container : in out Dictionary;
                     Key : Integer;
                     New_Item : Integer);

   procedure Insert (Container : in out Dictionary;
                     Key : Integer;
                     New_Item : Boolean);

   procedure Insert (Container : in out Dictionary;
                     Key : Integer;
                     New_Item : List'Class)
     with Pre => not Refers (New_Item, Container)
     or else raise Template_Error with "inserting list would create cycle";

   procedure Insert (Container : in out Dictionary;
                     Key : Integer;
                     New_Item : Dictionary'Class)
     with Pre => not Refers (New_Item, Container)
     or else raise Template_Error with "inserting dictionary would create cycle";

   procedure Clear (Container : in out Dictionary);

   procedure Append (Container : in out List;
                     New_Item : String);

   procedure Append (Container : in out List;
                     New_Item : Unbounded_String);

   procedure Append (Container : in out List;
                     New_Item : Dictionary'Class)
     with Pre => not Refers (New_Item, Container)
     or else raise Template_Error with "inserting dictionary would create cycle";

   procedure Clear (Container : in out List);

   type Unbounded_String_Array is array (Positive range <>)
     of Unbounded_String;

   type Filter_Function is access function (Arguments : Unbounded_String_Array)
                                            return Unbounded_String;

   procedure Register_Filter (Settings : in out Environment;
                              Filter : Filter_Function;
                              Name : String);

private
   type Dictionary_Assocs;

   type Assocs_Access is access Dictionary_Assocs;

   type Dictionary is new Ada.Finalization.Controlled with record
      Assocs : Assocs_Access;
   end record;

   overriding procedure Adjust (D : in out Dictionary);

   overriding procedure Finalize (D : in out Dictionary);

   type List_Elements;

   type List_Elements_Access is access List_Elements;

   type List is new Ada.Finalization.Controlled with record
      Elements : List_Elements_Access;
   end record;

   overriding procedure Adjust (L : in out List);

   overriding procedure Finalize (L : in out List);

   type Template;

   type Template_Access is access Template;

   package Template_Access_Maps is new
     Ada.Containers.Hashed_Maps (Key_Type => Unbounded_String,
                                 Element_Type => Template_Access,
                                 Hash => Ada.Strings.Unbounded.Hash,
                                 Equivalent_Keys => "=");

   protected type Template_Cache is
      function Get (Path : String) return Template_Access;
      procedure Put (Path : String;
                     Template : Template_Access;
                     Max_Size : Natural;
                     Inserted : out Boolean);
      function Size return Natural;
      procedure Cleanup;
   private
      Templates_Map : Template_Access_Maps.Map
        := Template_Access_Maps.Empty_Map;
   end Template_Cache;

   package Filter_Maps is new
     Ada.Containers.Hashed_Maps (Key_Type => Unbounded_String,
                                 Element_Type => Filter_Function,
                                 Hash => Ada.Strings.Unbounded.Hash,
                                 Equivalent_Keys => "=");

   type Environment is new Ada.Finalization.Limited_Controlled with record
      Expression_Start : Unbounded_String
        := To_Unbounded_String (Default_Expression_Start);
      Expression_End : Unbounded_String
        := To_Unbounded_String (Default_Expression_End);
      Statement_Start : Unbounded_String
        := To_Unbounded_String (Default_Statement_Start);
      Statement_End : Unbounded_String
        := To_Unbounded_String (Default_Statement_End);
      Comment_Start : Unbounded_String
        := To_Unbounded_String (Default_Comment_Start);
      Comment_End : Unbounded_String
        := To_Unbounded_String (Default_Comment_End);
      Cached_Templates : Template_Cache;
      Max_Cache_Size : Natural := 200;
      Trim_Blocks : Boolean := False;
      Lstrip_Blocks : Boolean := False;
      Filters : Filter_Maps.Map := Filter_Maps.Empty_Map;
   end record;

   overriding procedure Finalize (Self : in out Environment);

end Jintp;