adayaml_0.3.0_ab19e387/Parser_Tools/src/implementation/lexer-source-text_io.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
--  part of ParserTools, (c) 2017 Felix Krause
--  released under the terms of the MIT license, see the file "copying.txt"

package body Lexer.Source.Text_IO is
   procedure Read_Data (S : in out Instance; Buffer : out String;
                        Length : out Natural) is
   begin
      Length := Buffer'First;
      loop
         Ada.Text_IO.Get_Line (S.File_Pointer.all,
                               Buffer (Length .. Buffer'Last - 1), Length);
         if Ada.Text_IO.End_Of_File (S.File_Pointer.all) then
            Buffer (Length) := Character'Val (4);
            exit;
         end if;
         Ada.Text_IO.Get_Line (S.File_Pointer.all,
                               Buffer (Length .. Buffer'Last), Length);
         exit when Length = Buffer'Last;
         Buffer (Length + 1) := Character'Val (10);
         Length := Length + 2;
         exit when Length > Buffer'Last;
      end loop;
   end Read_Data;

   function As_Source (File : Ada.Text_IO.File_Access) return Pointer is
     (Pointer'(new Instance'(Source.Instance with File_Pointer => File)));
end Lexer.Source.Text_IO;