annotate lib/source.ml @ 1:b5139af1a420 tip basis

Fixed permissions on compile scripts
author Mike Spivey <mike@cs.ox.ac.uk>
date Fri, 13 Oct 2017 17:27:58 +0100
parents bfdcc3820b32
children
rev   line source
mike@0 1 (* lib/source.ml *)
mike@0 2 (* Copyright (c) 2017 J. M. Spivey *)
mike@0 3
mike@0 4 open Print
mike@0 5
mike@0 6 let filename = ref ""
mike@0 7 let chan = ref stdin
mike@0 8 let linetab = Hashtbl.create 100
mike@0 9
mike@0 10 let note_line n lexbuf =
mike@0 11 Hashtbl.add linetab n (Lexing.lexeme_end lexbuf)
mike@0 12
mike@0 13 let get_line n =
mike@0 14 let pos0 = pos_in !chan in
mike@0 15 let line =
mike@0 16 try seek_in !chan (Hashtbl.find linetab n); input_line !chan with
mike@0 17 Not_found -> ""
mike@0 18 | End_of_file -> "" in
mike@0 19 seek_in !chan pos0;
mike@0 20 line
mike@0 21
mike@0 22 let init fn ch =
mike@0 23 filename := fn; chan := ch;
mike@0 24 Hashtbl.add linetab 1 0
mike@0 25
mike@0 26 let err_message fmt args ln =
mike@0 27 fprintf stderr "\"$\", line $: $\n"
mike@0 28 [fStr !filename; fNum ln; fMeta fmt args];
mike@0 29 flush stderr
mike@0 30