DEFINITION MODULE scan;	

(* 
                           * SCAN * 

                           by - Greg Mumm

   This module reads multiple symbols one by one on a per line basis.
   Look-Ahead is possible and it can handle multiple files.
*)

FROM FileSystem    IMPORT File;


CONST  
      StringMax    =  161 ;       (*  160 column support  ( 2 lines )  *)
      SPACE        = ' '  ;
      TAB          = 11C  ;
      EOLN         = 12C  ;
      Q1           = "'"  ; (* single quote string *)
      Q2           = '"'  ; (* double quote string *)
      LPAR         = "("  ;
      RPAR         = ")"  ;
      
TYPE 
      STRING        =  ARRAY [ 0 .. StringMax ]   OF CHAR;
      StringPtrType =  POINTER TO STRING;
      NameString    =  ARRAY [ 0 .. 255       ]   OF CHAR; (*  FileName  *)

      SymbolType    =  ( number,  identifier, end, literal, blanks, other, 
                         nothing );    

       (* This holds left margin information contained in the invisible
          space before the first symbol. 
       *)
      IndentArray   =  ARRAY [ 1..StringMax ] OF  CHAR ;


  (* Set 'DeleteFile' to TRUE if you want to automatically delete a file
     if present. ( eg. when WRITING to a file ).
     Set 'DeleteFile' to FALSE for  normal READ operations.
   *)
PROCEDURE OpenInFile    (     FileName        : NameString  ;
                              DeleteFile      : BOOLEAN     ;
                          VAR successful      : BOOLEAN    );
PROCEDURE OpenOutFile   (     FileName        : NameString  ;
                              DeleteFile      : BOOLEAN     ;
                          VAR successful      : BOOLEAN    );
PROCEDURE CloseAllFiles ();


PROCEDURE eof           () : BOOLEAN;

PROCEDURE eoln          () : BOOLEAN;

  (* The following two procedures are used to detect eof and eoln
     conditions WHEN READING AHEAD. Do NOT use the above procedures
     when reading ahead. 
  *)
PROCEDURE EofAhead      () : BOOLEAN;

PROCEDURE EolnAhead     () : BOOLEAN;


 (* eof OR eoln
 *)
PROCEDURE HitABrickWall () : BOOLEAN;



 (* Look-ahead buffer is full if this is set
 *)
PROCEDURE TooFar          () : BOOLEAN;

 (* Normally after reading ahead, the following read-ahead will return NEW
    unanalized data. ( Previous access is stored ). This proceedure will
    allow the 2'nd read-ahead to read the same data read the first time.
    A FastForward  does the opposite of above. It will automatically signal 
    the next ReadAhead procedure to use new data regardless of whether the
    previous access was a ReadAhead or just a Read.
 *)
PROCEDURE rewind          ();

PROCEDURE FastForward     ();


PROCEDURE ReadLine (VAR indent                : IndentArray ) : BOOLEAN;

PROCEDURE ReadAheadLine ( VAR indent          : IndentArray ) : BOOLEAN;

 


PROCEDURE ReadSymbol ( VAR symbol           : STRING;
                       VAR SymbolClass      : SymbolType ) ;
           
PROCEDURE ReadAheadSymbol ( VAR symbol           : STRING;
                            VAR SymbolClass      : SymbolType );  

 (* Print currently processing line number to screen.
 *)
PROCEDURE PrintLineNumber ();

PROCEDURE write (char : CHAR) ;



(* DEBUG *)
   
  (* Print input line after we read it in.
  *)
PROCEDURE DebugPrintLine ( Indent : IndentArray );

  (* Print everything going to a file (write procedure above) to standard
     output too. 
  *)
PROCEDURE DebugOutputToggle ();

END scan.
