-- $Date: 2004/02/14 02:36:29 $
-- $Revision: 1.3 $
-- $Author: jcrocholl $

with Ada.Unchecked_Deallocation;

with Messages; use Messages;
with Integer_Strings; use Integer_Strings;
with Real_Strings; use Real_Strings;

package body Token_Readers is

   -----------------
   -- Initialization
   -----------------

   -- Initialize a newly created reader instance.
   procedure Initialize_Token_Reader
     (This : access Token_Reader'Class) is
   begin
      Initialize_Reader(This);
   end Initialize_Token_Reader;

   -- Initialize a newly created reader instance with a file to read.
   procedure Initialize_Token_Reader
     (This     : access Token_Reader'Class;
      Filename : in String) is -- Open this file for reading.
   begin
      Initialize_Reader(This, Filename);
   end Initialize_Token_Reader;

   -- Close the input file.
   procedure Finalize_Token_Reader
     (This : access Token_Reader'Class) is -- Object instance.
   begin
      Finalize_Reader(This);
      Free(This.Token);
   end Finalize_Token_Reader;

   -------------------
   -- Creating readers
   -------------------

   -- Create an Token reader for current input (stdin).
   function Current_Input
     return Token_Reader_Access -- The newly created token reader instance.
   is
      Result : Token_Reader_Access := new Token_Reader;
   begin
      Initialize_Token_Reader(Result);
      return Result;
   end Current_Input;

   -- Create an Token reader for file input.
   function Open
     (Filename : in String)     -- Open this file.
     return Token_Reader_Access -- The newly created token reader instance.
   is
      Result : Token_Reader_Access := new Token_Reader;
   begin
      Initialize_Token_Reader(Result, Filename);
      return Result;
   end Open;