home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #4 / amigaacscoverdisc1998-041998.iso / utilities / shareware / dev / ppcsmalleiffel / lib_se / comment.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  4.1 KB  |  193 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  4. --                       http://www.loria.fr/SmallEiffel
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it 
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later 
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License 
  11. -- for  more  details.  You  should  have  received a copy of the GNU General 
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class COMMENT
  17.    --
  18.    -- To store a comment (of one or more lines).
  19.    --
  20.    -- Note : for pretty printing, the original text source is stored.
  21.    --
  22.    
  23. inherit GLOBALS;
  24.  
  25. creation {EIFFEL_PARSER}
  26.    make
  27.    
  28. feature {ANY}
  29.    
  30.    start_position: POSITION;
  31.    
  32. feature {COMMENT}
  33.    
  34.    list: ARRAY[STRING];
  35.      -- The contents of the comment.
  36.    
  37. feature {EIFFEL_PARSER}
  38.    
  39.    make(sp: like start_position; l: like list) is
  40.       require
  41.      sp /= Void;
  42.      not l.empty;
  43.      l.lower = 1;
  44.       do
  45.      start_position := sp;
  46.      list := l;
  47.       ensure
  48.      start_position = sp;
  49.      list = l;
  50.       end;
  51.    
  52.    add_last(l: STRING) is
  53.       require
  54.      l /= Void
  55.       do
  56.      list.add_last(l);
  57.       ensure
  58.      count = 1 + old count
  59.       end;
  60.    
  61.    append(other: like Current) is
  62.       require
  63.      other /= Void
  64.       local
  65.      i: INTEGER;
  66.       do
  67.      from
  68.         i := 1;
  69.      until
  70.         i > other.list.upper
  71.      loop
  72.         add_last(other.list.item(i));
  73.         i := i + 1;
  74.      end;
  75.       end;
  76.  
  77. feature
  78.    
  79.    short(h1, r1, h2, r2: STRING) is
  80.       local
  81.      i, j: INTEGER;
  82.      l: STRING;
  83.      c: CHARACTER;
  84.      open_quote: BOOLEAN;
  85.       do
  86.      from
  87.         i := list.lower;
  88.      until
  89.         i > list.upper
  90.      loop
  91.         short_print.hook_or(h1,r1);
  92.         short_print.hook("BECL");
  93.         l := list.item(i);
  94.         from
  95.            j := 1;
  96.         until
  97.            j > l.count
  98.         loop
  99.            c := l.item(j);
  100.            inspect
  101.           c
  102.            when '_' then
  103.           short_print.hook_or("Ucomment","_");
  104.            when '`' then
  105.           open_quote := true;
  106.           short_print.hook_or("op_quote","`");
  107.            when '%'' then
  108.           if open_quote then
  109.              open_quote := false;
  110.              short_print.hook_or("cl_quote","'");
  111.           else
  112.              short_print.a_character(c);
  113.           end;
  114.            else
  115.           short_print.a_character(c);
  116.            end;
  117.            j := j + 1;
  118.         end;
  119.         short_print.hook("AECL");
  120.         short_print.hook_or(h2,r2);
  121.         i := i + 1;
  122.      end;
  123.       end;
  124.  
  125.    dummy: BOOLEAN is
  126.      -- Thus this comment can be dropped :-)
  127.       local
  128.      str: STRING;
  129.       do
  130.      if list.count = 1 then
  131.         str := list.first;
  132.         Result := str.count < 10;
  133.      end;
  134.       end;
  135.    
  136.    pretty_print is
  137.       -- Print the comment, and indent.
  138.       local
  139.      i, column: INTEGER;
  140.       do
  141.      if fmt.column > 1 and fmt.last_character /= ' ' then
  142.         fmt.put_character(' ');
  143.      end;
  144.      from
  145.         column := fmt.column;
  146.         i := list.lower;
  147.      until
  148.         i > list.upper
  149.      loop
  150.         fmt.put_string("--");
  151.         fmt.put_string(list.item(i));
  152.         i := i + 1;
  153.         if i <= list.upper then
  154.            from  
  155.           fmt.put_character('%N');
  156.            until
  157.           fmt.column = column
  158.            loop
  159.           fmt.put_character(' ');
  160.            end;
  161.         end;
  162.      end;
  163.      fmt.put_character('%N');
  164.      fmt.indent;
  165.       ensure
  166.      fmt.indent_level = old fmt.indent_level
  167.       end;
  168.    
  169.    count: INTEGER is
  170.      -- Number of lines of the comment.
  171.       do
  172.      Result := list.count;
  173.       end;
  174.  
  175.    good_end(name: CLASS_NAME) is
  176.       do
  177.      if not list.item(1).has_string(name.to_string) then
  178.         eh.add_position(name.start_position);
  179.         warning(start_position,"Bad comment to end a class.");
  180.      end;
  181.       end;
  182.  
  183. invariant
  184.    
  185.    start_position /= Void;
  186.    
  187.    not list.empty;
  188.  
  189.    list.lower = 1;
  190.    
  191. end -- COMMENT
  192.  
  193.