home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / comment.e < prev    next >
Text File  |  1999-06-05  |  5KB  |  203 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://SmallEiffel.loria.fr
  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 make
  26.  
  27. feature 
  28.  
  29.    start_position: POSITION;
  30.  
  31. feature
  32.  
  33.    short(h1, r1, h2, r2: STRING) is
  34.       local
  35.          i, j: INTEGER;
  36.          l: STRING;
  37.          c: CHARACTER;
  38.          open_quote: BOOLEAN;
  39.       do
  40.          from
  41.             i := list.lower;
  42.          until
  43.             i > list.upper
  44.          loop
  45.             short_print.hook_or(h1,r1);
  46.             short_print.hook("BECL");
  47.             l := list.item(i);
  48.             from
  49.                j := 1;
  50.             until
  51.                j > l.count
  52.             loop
  53.                c := l.item(j);
  54.                inspect
  55.                   c
  56.                when '_' then
  57.                   short_print.hook_or("Ucomment","_");
  58.                when '`' then
  59.                   open_quote := true;
  60.                   short_print.hook_or("op_quote","`");
  61.                when '%'' then
  62.                   if open_quote then
  63.                      open_quote := false;
  64.                      short_print.hook_or("cl_quote","'");
  65.                   else
  66.                      short_print.a_character(c);
  67.                   end;
  68.                else
  69.                   short_print.a_character(c);
  70.                end;
  71.                j := j + 1;
  72.             end;
  73.             short_print.hook("AECL");
  74.             short_print.hook_or(h2,r2);
  75.             i := i + 1;
  76.          end;
  77.       end;
  78.  
  79.    pretty_print is
  80.       -- Print the comment, and indent.
  81.       local
  82.          i, column: INTEGER;
  83.       do
  84.          if fmt.column > 1 and fmt.last_character /= ' ' then
  85.             fmt.put_character(' ');
  86.          end;
  87.          from
  88.             column := fmt.column;
  89.             i := list.lower;
  90.          until
  91.             i > list.upper
  92.          loop
  93.             fmt.put_string("--");
  94.             fmt.put_string(list.item(i));
  95.             i := i + 1;
  96.             if i <= list.upper then
  97.                from
  98.                   fmt.put_character('%N');
  99.                until
  100.                   fmt.column = column
  101.                loop
  102.                   fmt.put_character(' ');
  103.                end;
  104.             end;
  105.          end;
  106.          fmt.put_character('%N');
  107.          fmt.indent;
  108.       ensure
  109.          fmt.indent_level = old fmt.indent_level
  110.       end;
  111.  
  112.    count: INTEGER is
  113.          -- Number of lines of the comment.
  114.       do
  115.          Result := list.count;
  116.       end;
  117.  
  118.    dummy: BOOLEAN is
  119.          -- Thus this comment can be dropped :-)
  120.       local
  121.          first_line: STRING;
  122.          c: INTEGER;
  123.       do
  124.          if list.count = 1 then
  125.             first_line := list.first;
  126.             c := first_line.count;
  127.             if c < 40 then
  128.                if first_line.index_of_string(" end ") < c then
  129.                   Result := true;
  130.                elseif first_line.index_of_string(" class ") < c then
  131.                   Result := true;
  132.                end;
  133.             end;
  134.          end;
  135.       end;
  136.  
  137. feature {BASE_CLASS}
  138.  
  139.    good_end(name: CLASS_NAME) is
  140.       do
  141.          if not list.item(1).has_string(name.to_string) then
  142.             eh.add_position(name.start_position);
  143.             warning(start_position,"Bad comment to end a class.");
  144.          end;
  145.       end;
  146.  
  147. feature {COMMENT}
  148.  
  149.    list: ARRAY[STRING];
  150.          -- The contents of the comment.
  151.  
  152. feature {EIFFEL_PARSER}
  153.  
  154.    add_last(l: STRING) is
  155.       require
  156.          l /= Void
  157.       do
  158.          list.add_last(l);
  159.       ensure
  160.          count = 1 + old count
  161.       end;
  162.  
  163.    append(other: like Current) is
  164.       require
  165.          other /= Void
  166.       local
  167.          i: INTEGER;
  168.       do
  169.          from
  170.             i := 1;
  171.          until
  172.             i > other.list.upper
  173.          loop
  174.             add_last(other.list.item(i));
  175.             i := i + 1;
  176.          end;
  177.       end;
  178.  
  179. feature {NONE}
  180.  
  181.    make(sp: like start_position; l: like list) is
  182.       require
  183.          sp /= Void;
  184.          not l.empty;
  185.          l.lower = 1;
  186.       do
  187.          start_position := sp;
  188.          list := l;
  189.       ensure
  190.          start_position = sp;
  191.          list = l;
  192.       end;
  193.  
  194. invariant
  195.  
  196.    start_position /= Void;
  197.  
  198.    not list.empty;
  199.  
  200.    list.lower = 1;
  201.  
  202. end -- COMMENT
  203.