File:  [Research Unix] / researchv10no / cmd / sml / src / lex / hookup.sml
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:21:35 2018 UTC (8 years, 1 month ago) by root
Branches: belllabs, MAIN
CVS tags: researchv10, HEAD
researchv10 Norman

(* Copyright 1989 by AT&T Bell Laboratories *)
signature LEX = sig
    type lexer
    val mkLex : {stream : instream, interactive : bool} -> 
                {nextToken : Token.token ref,
                 prompt : string ref,
                 advance : unit -> unit}
end

structure Lex : LEX =
struct
 type lexer ={nextToken : Token.token ref,
                 prompt : string ref,
                 advance : unit -> unit}

 fun mkLex{stream,interactive} =
  let val prompt = ref ""
      val lexarg = {comLevel = ref 0, lineNum = ErrorMsg.lineNum,
                      complain = ErrorMsg.complain}

      val nextToken = ref Token.SEMICOLON

      val doprompt = ref true

      fun getline _ =(if !doprompt then (output std_out (!prompt);
					 flush_out std_out;
					 doprompt := false)
				   else ();
		      let val s = input_line stream
		      in doprompt := (ordof(s,size s - 1)=ord("\n")
				     handle Ord => false);
		         s
		      end)

     val get = Mlex.makeLexer(if interactive then getline else input stream)
		lexarg
     fun advance() = nextToken := get()

  in {nextToken=nextToken, prompt=prompt, advance=advance}
 end
    
end

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.