gnoga_2.1.2_5f127c56/deps/zanyblue/src/zbmcompile/zbmcompile-parser_handler.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
--  -*- coding: utf-8 -*-
--
--  ZanyBlue, an Ada library and framework for finite element analysis.
--
--  Copyright (c) 2012, 2016, Michael Rohan <mrohan@zanyblue.com>
--  All rights reserved.
--
--  Redistribution and use in source and binary forms, with or without
--  modification, are permitted provided that the following conditions
--  are met:
--
--    * Redistributions of source code must retain the above copyright
--      notice, this list of conditions and the following disclaimer.
--
--    * Redistributions in binary form must reproduce the above copyright
--      notice, this list of conditions and the following disclaimer in the
--      documentation and/or other materials provided with the distribution.
--
--    * Neither the name of ZanyBlue nor the names of its contributors may
--      be used to endorse or promote products derived from this software
--      without specific prior written permission.
--
--  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
--  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
--  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
--  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
--  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
--  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
--  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
--  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
--  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
--  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
--  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--

with Ada.Containers.Indefinite_Hashed_Maps;
with Ada.Containers.Indefinite_Hashed_Sets;

with ZanyBlue.Text.Locales;
with ZanyBlue.Text.Catalogs;

package ZBMCompile.Parser_Handler is

   use Ada.Containers;
   use ZanyBlue.Text;
   use ZanyBlue.Text.Locales;
   use ZanyBlue.Text.Catalogs;

   type Key_Definition is record
      Line_Number : Positive := 1;
      Arg_Types   : String_Vectors.Vector;
   end record;
   --  Information about the definition of a key for a message.  A list of
   --  these records is maintained to cover the locales loaded.  This
   --  information is used to check the cross locale consistency of messages,
   --  i.e., does a localized message refer to an argument number beyond
   --  the numbers used by the base locale.

   package Locale_Definitions_Package is new Indefinite_Hashed_Maps
     (Key_Type => String, Element_Type => Key_Definition, Hash => Wide_Hash,
      Equivalent_Keys => "=");
   subtype Locale_Definitions_Map is Locale_Definitions_Package.Map;
   function "="
     (Left, Right : Locale_Definitions_Map)
      return Boolean;
   --  Associate a locale with the description of the key defined in it.

   package Key_Definitions_Package is new Indefinite_Hashed_Maps
     (Key_Type => String, Element_Type => Locale_Definitions_Map,
      Hash     => Wide_Hash, Equivalent_Keys => "=");
   subtype Key_Definitions_Map is Key_Definitions_Package.Map;
   function "="
     (Left, Right : Key_Definitions_Map)
      return Boolean;
   --  Associate keys with their definitions in various locales

   package Locale_Sets is new Indefinite_Hashed_Sets
     (Element_Type => String, Hash => Wide_Hash, Equivalent_Elements => "=");
   subtype Locale_Set_Type is Locale_Sets.Set;
   --  Is a particular locale defined for a facility

   type Facility_Descriptor_Type is record
      Keys    : Key_Definitions_Map;
      Locales : Locale_Set_Type;
   end record;
   --  Description of the information gathered for a particular facility.
   --  This is used for both inter-locale consistency checks and the generation
   --  of accessor routines.

   package Facility_Descriptor_Package is new Indefinite_Hashed_Maps
     (Key_Type => String, Element_Type => Facility_Descriptor_Type,
      Hash     => Wide_Hash, Equivalent_Keys => "=");
   subtype Facility_Descriptor_Map is Facility_Descriptor_Package.Map;
   --  Associate facilities with the keys defined for it.

   type ZBMC_Handler_Type (Unchecked : Boolean)
   is new Catalog_Handler_Type with record
      Message_Info : Facility_Descriptor_Map;
   end record;
   --  The parser handler type used when parsing ".properties" files.

   overriding procedure Add_Key_Value
     (Handler       : in out ZBMC_Handler_Type;
      Facility      :        String;
      Key           :        String;
      Value         :        String;
      Locale        :        Locale_Type;
      Source_Locale :        Locale_Type;
      File_Name     :        String;
      Line_Number   :        Natural);
   --  Call back used to add messages to a catalog.  Simply verify the message
   --  and then invoke our parent's method to do the actually addition.

   overriding procedure Duplicate_Key
     (Handler       : in out ZBMC_Handler_Type;
      Facility      :        String;
      Key           :        String;
      Locale        :        Locale_Type;
      File_Name     :        String;
      Current_Line  :        Natural;
      Previous_Line :        Natural);
   --  Call back used to report a duplicate key error.

   overriding procedure Invalid_Character
     (Handler      : in out ZBMC_Handler_Type;
      Facility     :        String;
      File_Name    :        String;
      Current_Line :        Natural;
      Ch           :        Character);
   --  Call back used to report an invalid character, non-ISO-646, in the
   --  source properties file.

   overriding procedure Invalid_Definition
     (Handler         : in out ZBMC_Handler_Type;
      Facility        :        String;
      Locale          :        Locale_Type;
      File_Name       :        String;
      Current_Line    :        Natural;
      Additional_Info :        String);
   --  Call back used to report an invalid .properties file line error.

   procedure Message_Iterate
     (Handler  : ZBMC_Handler_Type;
      Facility : String;
      Callback : not null access procedure
        (Catalog  : Catalog_Type;
         Facility : String;
         Key      : String;
         Locales  : Locale_Definitions_Map));
   --  Iterate over the messages defined for a facility by message key.  The
   --  Locale_Info vector gives information on whether or not a key is defined
   --  for a particular locale index and, if defined, the number of arguments
   --  the message expects.

   function Facility_Defines_Locale
     (Handler  : ZBMC_Handler_Type;
      Facility : String;
      Locale   : String)
      return Boolean;
   --  Was the given locale loaded for the given facility?

end ZBMCompile.Parser_Handler;