parser_utils.ads 2.86 KB
Newer Older
1
--  *************************** taste aadl parser ***********************  --
Maxime Perrotin's avatar
Maxime Perrotin committed
2
3
4
--  (c) 2017 European Space Agency - maxime.perrotin@esa.int
--  LGPL license, see LICENSE file

5
--  Set of helper functions for the parser
Maxime Perrotin's avatar
Maxime Perrotin committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
with Ocarina,
     Ocarina.Types,
     Ocarina.Namet,
     Ada.Containers.Indefinite_Ordered_Maps,
     Ada.Containers.Indefinite_Vectors,
     Ocarina.ME_AADL.AADL_Tree.Nodes,
     Ocarina.ME_AADL.AADL_Instances.Nodes,
     Ada.Strings.Unbounded,
     Option_Type;

use Ocarina,
    Ocarina.Types,
    Ocarina.Namet,
    Ocarina.ME_AADL.AADL_Tree.Nodes,
    Ocarina.ME_AADL.AADL_Instances.Nodes,
    Ada.Containers,
    Ada.Strings.Unbounded;

24
package Parser_Utils is
Maxime Perrotin's avatar
Maxime Perrotin committed
25
26
27
28
29
30

   package ATN renames Ocarina.ME_AADL.AADL_Tree.Nodes;
   package AIN renames Ocarina.ME_AADL.AADL_Instances.Nodes;
   function US (Source : String) return Unbounded_String renames
       To_Unbounded_String;

Maxime Perrotin's avatar
Maxime Perrotin committed
31
32
33
34
35
36
   Yellow_Bold : constant String := ASCII.ESC & "[33m" & ASCII.ESC & "[1m";
   White       : constant String := ASCII.ESC & "[37m";
   Red_Bold    : constant String := ASCII.ESC & "[31m" & ASCII.ESC & "[1m";
   Underscore  : constant String := ASCII.ESC & "[4m";
   No_Color    : constant String := ASCII.ESC & "[0m";

Maxime Perrotin's avatar
Maxime Perrotin committed
37
38
39
40
   procedure Banner;

   procedure Usage;

41
42
   AADL_Parser_Error : exception;

Maxime Perrotin's avatar
Maxime Perrotin committed
43
44
45
46
   procedure Exit_On_Error (Error : Boolean; Reason : String);

   function Get_APLC_Binding (E : Node_Id) return List_Id;

47
   --  Record to store properties
48
49
50
51
52
53
54
   type User_Property is
      record
         Name  : Unbounded_String;
         Value : Unbounded_String;
      end record;
   package Property_Maps is new Indefinite_Ordered_Maps (String,
                                                         User_Property);
Maxime Perrotin's avatar
Maxime Perrotin committed
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
   use Property_Maps;
   package String_Vectors is new Indefinite_Vectors (Natural, String);
   function Get_Properties_Map (D : Node_Id) return Property_Maps.Map;

   --  Shortcut to read an identifier from the parser, in lowercase
   function ATN_Lower (N : Node_Id) return String is
       (Get_Name_String (ATN.Name (ATN.Identifier (N))));

   --  Shortcut to read an identifier from the parser, with original case
   function ATN_Case (N : Node_Id) return String is
       (Get_Name_String (ATN.Display_Name (ATN.Identifier (N))));

   --  Shortcut to read an identifier from the parser, in lowercase
   function AIN_Lower (N : Node_Id) return String is
       (Get_Name_String (AIN.Name (AIN.Identifier (N))));

   --  Shortcut to read an identifier from the parser, with original case
   function AIN_Case (N : Node_Id) return String is
       (Get_Name_String (AIN.Display_Name (AIN.Identifier (N))));

   package Option_UString is new Option_Type (Unbounded_String);
   use Option_UString;
   subtype Optional_Unbounded_String is Option_UString.Option;
   package Option_ULL is new Option_Type (Unsigned_Long_Long);
   use Option_ULL;
   subtype Optional_Long_Long is Option_ULL.Option;

82
end Parser_Utils;