matreshka_league_21.0.0_0c8f4d47/tools/aflex/src/ccl.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
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
-- Copyright (c) 1990 Regents of the University of California.
-- All rights reserved.
--
-- This software was developed by John Self of the Arcadia project
-- at the University of California, Irvine.
--
-- Redistribution and use in source and binary forms are permitted
-- provided that the above copyright notice and this paragraph are
-- duplicated in all such forms and that any documentation,
-- advertising materials, and other materials related to such
-- distribution and use acknowledge that the software was developed
-- by the University of California, Irvine.  The name of the
-- University may not be used to endorse or promote products derived
-- from this software without specific prior written permission.
-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
-- IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
-- WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.

-- TITLE character classes routines
-- AUTHOR: John Self (UCI)
-- DESCRIPTION routines for character classes like [abc]
-- $Header: /dc/uc/self/arcadia/aflex/ada/src/RCS/cclB.a,v 1.7 1993/04/27 23:17:15 self Exp $
with Ada.Characters.Conversions;
with Ada.Strings.Unbounded;
with Ada.Strings.Wide_Wide_Maps;

with Misc;

package body CCL is

   use Ada.Characters.Conversions;
   use Ada.Strings.Unbounded;
   use Ada.Strings.Wide_Wide_Maps;
   use Ada.Wide_Wide_Text_IO;

   -- ccladd - add a single character to a ccl

   ------------
   -- CCLADD --
   ------------

   procedure CCL_Add
    (CCLP : Integer;
     Ch   : Unicode.Unicode_Character)
   is
      IND, LEN, NEWPOS : INTEGER;

   begin
      --  Check to see if the character is already in the ccl.

      if Is_In (Ch, CCL_Sets (CCLP)) then
         return;
      end if;

      CCL_Sets (CCLP) := CCL_Sets (CCLP) or To_Set (Ch);

      LEN := CCLLEN(CCLP);
      IND := CCLMAP(CCLP);

      NEWPOS := IND + LEN;

      if (NEWPOS >= Current_Max_CCL_Table_Size) then
         Current_Max_CCL_Table_Size := Current_Max_CCL_Table_Size +
           MAX_CCL_TBL_SIZE_INCREMENT;

         NUM_REALLOCS := NUM_REALLOCS + 1;

         Reallocate_Unicode_Character_Array
           (CCLTBL, Current_Max_CCL_Table_Size);
      end if;

      CCLLEN(CCLP) := LEN + 1;
      CCLTBL(NEWPOS) := CH;

   end CCL_Add;

  -- cclinit - make an empty ccl

  function CCLINIT return INTEGER is
  begin
    LASTCCL := LASTCCL + 1;
    if (LASTCCL >= CURRENT_MAXCCLS) then
      CURRENT_MAXCCLS := CURRENT_MAXCCLS + MAX_CCLS_INCREMENT;

      NUM_REALLOCS := NUM_REALLOCS + 1;

      REALLOCATE_INTEGER_ARRAY(CCLMAP, CURRENT_MAXCCLS);
      REALLOCATE_INTEGER_ARRAY(CCLLEN, CURRENT_MAXCCLS);
      REALLOCATE_INTEGER_ARRAY(CCLNG, CURRENT_MAXCCLS);
         Reallocate_Wide_Wide_Character_Set_Array (CCL_Sets, CURRENT_MAXCCLS);
    end if;

    if (LASTCCL = 1) then

      -- we're making the first ccl
      CCLMAP(LASTCCL) := 0;

    else

      -- the new pointer is just past the end of the last ccl.  Since
      -- the cclmap points to the \first/ character of a ccl, adding the
      -- length of the ccl to the cclmap pointer will produce a cursor
      -- to the first free space
      CCLMAP(LASTCCL) := CCLMAP(LASTCCL - 1) + CCLLEN(LASTCCL - 1);
    end if;

    CCLLEN(LASTCCL) := 0;
    CCLNG(LASTCCL) := 0;

    -- ccl's start out life un-negated
    return LASTCCL;
  end CCLINIT;

  -- cclnegate - negate a ccl

  procedure CCLNEGATE(CCLP : in INTEGER) is
  begin
    CCLNG(CCLP) := 1;
  end CCLNEGATE;

   ------------------------
   -- List_Character_Set --
   ------------------------

   -- list_character_set - list the members of a set of characters in CCL form
   --
   -- writes to the given file a character-class representation of those
   -- characters present in the given set.  A character is present if it
   -- has a non-zero value in the set array.

   procedure List_Character_Set
     (File : Ada.Wide_Wide_Text_IO.File_Type;
      CSET : C_SIZE_BOOL_ARRAY)
   is
      I, START_CHAR : INTEGER;

   begin
      PUT (File, '[');

      I := 1;

      while I <= CSIZE loop
         if CSET (I) then
            START_CHAR := I;

            PUT (File, ' ');

            PUT
              (File,
               To_Wide_Wide_String
                 (To_String
                    (MISC.Readable_Form (Wide_Wide_Character'Val (I)))));

            I := I + 1;

            while I <= CSIZE and then CSET(I) loop
               I := I + 1;
            end loop;

            if (I - 1 > START_CHAR) then
               -- this was a run

               PUT (File, "-");
               PUT
                 (File,
                  To_Wide_Wide_String
                    (To_String
                       (MISC.Readable_Form (Wide_Wide_Character'Val (I - 1)))));
            end if;

            PUT (File, ' ');
         end if;

         I := I + 1;
      end loop;

      PUT (File, ']');
   end List_Character_Set;

end CCL;