Commit 17b07559 authored by POTTIER Francois's avatar POTTIER Francois

Moved [chunk] from Lexer to InputFile.

[InputFile.get_file_contents] is no longer published.
parent eec2d30d
...@@ -94,3 +94,12 @@ let with_file_contents contents f = ...@@ -94,3 +94,12 @@ let with_file_contents contents f =
let result = f() in let result = f() in
file_contents := None; (* avoid memory leak *) file_contents := None; (* avoid memory leak *)
result result
open Lexing
let chunk (pos1, pos2) =
let ofs1 = pos1.pos_cnum
and ofs2 = pos2.pos_cnum in
let contents = get_file_contents() in
let len = ofs2 - ofs1 in
String.sub contents ofs1 len
...@@ -53,7 +53,11 @@ val compare_input_files: input_file -> input_file -> int ...@@ -53,7 +53,11 @@ val compare_input_files: input_file -> input_file -> int
(* [with_file_contents contents f] records that the contents of the current (* [with_file_contents contents f] records that the contents of the current
input file is [contents] while the action [f] runs. The function [f] can input file is [contents] while the action [f] runs. The function [f] can
then call [get_file_contents()] to retrieve [contents]. *) then call [chunk] (below) to retrieve certain segments of [contents]. *)
val with_file_contents: string -> (unit -> 'a) -> 'a val with_file_contents: string -> (unit -> 'a) -> 'a
val get_file_contents: unit -> string
(* [chunk pos1 pos2] extracts a chunk out of the current input file, delimited
by the positions [pos1] and [pos2]. *)
val chunk: (Lexing.position * Lexing.position) -> string
...@@ -42,17 +42,6 @@ let savestart lexbuf f = ...@@ -42,17 +42,6 @@ let savestart lexbuf f =
(* ------------------------------------------------------------------------ *) (* ------------------------------------------------------------------------ *)
(* Extracts a chunk out of the source file. *)
let chunk pos1 pos2 =
let ofs1 = pos1.pos_cnum
and ofs2 = pos2.pos_cnum in
let contents = InputFile.get_file_contents() in
let len = ofs2 - ofs1 in
String.sub contents ofs1 len
(* ------------------------------------------------------------------------ *)
(* Overwrites an old character with a new one at a specified (* Overwrites an old character with a new one at a specified
offset in a [bytes] buffer. *) offset in a [bytes] buffer. *)
...@@ -234,7 +223,7 @@ let no_monsters monsters = ...@@ -234,7 +223,7 @@ let no_monsters monsters =
let mk_stretch pos1 pos2 parenthesize monsters = let mk_stretch pos1 pos2 parenthesize monsters =
(* Read the specified chunk of the file. *) (* Read the specified chunk of the file. *)
let raw_content : string = chunk pos1 pos2 in let raw_content : string = InputFile.chunk (pos1, pos2) in
(* Transform the monsters, if there are any. (This explicit test (* Transform the monsters, if there are any. (This explicit test
allows saving one string copy and keeping just one live copy.) *) allows saving one string copy and keeping just one live copy.) *)
let content : string = let content : string =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment