wisitoken_4.2.1_dc778486/wisitoken-gen_token_enum.adb

  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
--  Abstract :
--
--  See spec
--
--  Copyright (C) 2017, 2018, 2020, 2021 Free Software Foundation, Inc.
--
--  This library is free software;  you can redistribute it and/or modify it
--  under terms of the  GNU General Public License  as published by the Free
--  Software  Foundation;  either version 3,  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 MERCHAN-
--  TABILITY or FITNESS FOR A PARTICULAR PURPOSE.

--  As a special exception under Section 7 of GPL version 3, you are granted
--  additional permissions described in the GCC Runtime Library Exception,
--  version 3.1, as published by the Free Software Foundation.

pragma License (GPL);

with Ada.Characters.Handling;
with WisiToken.Wisi_Ada;
package body WisiToken.Gen_Token_Enum is

   function Token_Enum_Image return Token_ID_Array_String
   is
      use Ada.Characters.Handling;
      Result : Token_ID_Array_String (Token_ID'First .. +SOI_ID);
   begin
      for I in Token_Enum_ID loop
         if I <= Last_Terminal then
            Result (+I) := new String'(Token_Enum_ID'Image (I));
         else
            Result (+I) := new String'(To_Lower (Token_Enum_ID'Image (I)));
         end if;
      end loop;
      return Result;
   end Token_Enum_Image;

   function To_Syntax (Item : in Enum_Syntax) return WisiToken.Lexer.Regexp.Syntax
   is
      Result : WisiToken.Lexer.Regexp.Syntax (Token_ID'First .. +Last_Terminal);
      --  SOI_ID is _not_ returned by lexer;
   begin
      for I in Result'Range loop
         Result (I) := Item (-I);
      end loop;
      return Result;
   end To_Syntax;

   function "&" (Left, Right : in Token_Enum_ID) return Token_ID_Arrays.Vector
   is begin
      return Result : Token_ID_Arrays.Vector do
         Result.Append (+Left);
         Result.Append (+Right);
      end return;
   end "&";

   function "&"
     (Left  : in Token_ID_Arrays.Vector;
      Right : in Token_Enum_ID)
     return Token_ID_Arrays.Vector
   is begin
      return Result : Token_ID_Arrays.Vector := Left do
         Result.Append (+Right);
      end return;
   end "&";

   function "+"
     (Left  : in Token_Enum_ID;
      Right : in WisiToken.Syntax_Trees.Post_Parse_Action)
     return WisiToken.Productions.Right_Hand_Side
   is begin
      return WisiToken.Wisi_Ada."+" (+Left, Right);
   end "+";

   function "<="
     (Left  : in Token_Enum_ID;
      Right : in WisiToken.Productions.Right_Hand_Side)
     return WisiToken.Productions.Instance
   is begin
      return WisiToken.Wisi_Ada."<=" (+Left, Productions.RHS_Arrays.To_Vector (Right, 1));
   end "<=";

   function To_Nonterminal_Array_Token_Set
     (Item : in Nonterminal_Array_Token_Set)
     return WisiToken.Token_Array_Token_Set
   is
      Result : Token_Array_Token_Set :=
        (LR1_Descriptor.First_Nonterminal .. LR1_Descriptor.Last_Nonterminal =>
           (LR1_Descriptor.First_Terminal .. LR1_Descriptor.Last_Nonterminal => False));
   begin
      for I in Item'Range (1) loop
         for J in Item'Range (2) loop
            Result (+I, +J) := Item (I, J);
         end loop;
      end loop;
      return Result;
   end To_Nonterminal_Array_Token_Set;

   function To_Nonterminal_Array_Terminal_Set
     (Item : in Nonterminal_Array_Terminal_Set)
     return WisiToken.Token_Array_Token_Set
   is
      Result : Token_Array_Token_Set :=
        (LR1_Descriptor.First_Nonterminal .. LR1_Descriptor.Last_Nonterminal =>
           (LR1_Descriptor.First_Terminal .. LR1_Descriptor.Last_Terminal => False));
   begin
      for I in Item'Range (1) loop
         for J in Item'Range (2) loop
            Result (+I, +J) := Item (I, J);
         end loop;
      end loop;
      return Result;
   end To_Nonterminal_Array_Terminal_Set;

   function "+" (Item : in Token_Array) return WisiToken.Generate.LR1_Items.Lookahead
   is
      use Generate.LR1_Items;
      Result : Lookahead := Null_Lookahead;
   begin
      for I in Item'Range loop
         Result (+Item (I)) := True;
      end loop;
      return Result;
   end "+";

   function "+" (Item : in Token_Enum_ID) return WisiToken.Generate.LR1_Items.Lookahead
   is begin
      return +Token_Array'(1 => Item);
   end "+";

begin
   LR1_Descriptor.Image := Token_Enum_Image;
   LALR_Descriptor.Image := LR1_Descriptor.Image;
end WisiToken.Gen_Token_Enum;