comparison lib/source.ml @ 0:bfdcc3820b32

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