home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / parser_buffer.e < prev    next >
Text File  |  1999-06-05  |  3KB  |  122 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 PARSER_BUFFER
  17.  
  18. inherit GLOBALS;
  19.  
  20. creation make
  21.  
  22. feature
  23.  
  24.    path: STRING;
  25.          -- When `is_ready', gives the `path' of the corresponding
  26.          -- buffered file.
  27.  
  28.    count: INTEGER;
  29.          -- Number of lines in the source file.
  30.  
  31.    is_ready: BOOLEAN is
  32.       do
  33.          Result := path /= Void;
  34.       end;
  35.  
  36. feature {SMALL_EIFFEL,EIFFEL_PARSER}
  37.  
  38.    load_file(a_path: STRING) is
  39.          -- Try to load `a_path' and set `is_ready' when corresponding
  40.          -- file has been loaded.
  41.       local
  42.          i: INTEGER;
  43.       do
  44.          tmp_file_read.connect_to(a_path);
  45.          if tmp_file_read.is_connected then
  46.             path := a_path;
  47.             from
  48.                if get_line(0) /= Void then
  49.                   -- unused line.
  50.                end;
  51.                i := 1;
  52.                tmp_file_read.read_line_in(get_line(i));
  53.             until
  54.                tmp_file_read.end_of_input
  55.             loop
  56.                i := i + 1;
  57.                tmp_file_read.read_line_in(get_line(i));
  58.             end;
  59.             if text.item(i).empty then
  60.                count := i - 1;
  61.             else
  62.                count := i;
  63.             end;
  64.             tmp_file_read.disconnect;
  65.          else
  66.             path := Void;
  67.          end;
  68.       end;
  69.  
  70.    unset_is_ready is
  71.       do
  72.          path := Void;
  73.       end;
  74.  
  75. feature {EIFFEL_PARSER}
  76.  
  77.    item(line: INTEGER): STRING is
  78.       require
  79.          is_ready;
  80.          1 <= line;
  81.          line <= count
  82.       do
  83.          Result := text.item(line);
  84.       ensure
  85.          Result /= Void
  86.       end;
  87.  
  88. feature {NONE}
  89.  
  90.    make is
  91.       do
  92.       end;
  93.  
  94.    text: FIXED_ARRAY[STRING] is
  95.          -- To store the complete file to parse. Each line
  96.          -- is one STRING without the '%N' end-of-line mark.
  97.       once
  98.          !!Result.with_capacity(4096);
  99.       end;
  100.  
  101.    get_line(i: INTEGER): STRING is
  102.       require
  103.          i >= 0
  104.       do
  105.          if i <= text.upper then
  106.             Result := text.item(i);
  107.             Result.clear;
  108.          else
  109.             !!Result.make(medium_line_size);
  110.             text.add_last(Result);
  111.          end;
  112.       ensure
  113.          Result.empty;
  114.          Result.capacity >= medium_line_size;
  115.          text.item(i) = Result
  116.       end;
  117.  
  118.    medium_line_size: INTEGER is 80;
  119.  
  120. end -- PARSER_BUFFER
  121.  
  122.