Skip to content

Commit

Permalink
library: decouple reading file from computing filename
Browse files Browse the repository at this point in the history
  • Loading branch information
Octachron committed Oct 14, 2024
1 parent 3aef146 commit 7a61c7a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
8 changes: 4 additions & 4 deletions core/single.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ let to_m2l policy sig_only (k,f,_n) =
| None -> None
| Some k ->
match Read.file k f with
| _name, Ok x ->
| Ok x ->
if sig_only then Some (k, M2l.Sig_only.filter x) else Some (k,x)
| _, Error (Ocaml (Syntax msg)) ->
| Error (Ocaml (Syntax msg)) ->
Fault.raise policy Standard_faults.syntaxerr msg;
Some(k, approx f)
| _, Error (Ocaml (Lexer msg)) ->
| Error (Ocaml (Lexer msg)) ->
Fault.raise policy Standard_faults.lexerr (!Location.input_name,msg);
Some(k, approx f)
| _, Error (Serialized e) ->
| Error (Serialized e) ->
Standard_faults.schematic_errors policy (f,"m2l",e); None

let approx_file _ _ ppf _param (_,f,_) =
Expand Down
2 changes: 0 additions & 2 deletions lib/read.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ let source_file kind filename =
code

let file {format;kind} filename =
let name = name filename in
name,
match format with
| Src | Parsetree -> source_file kind filename
| M2l ->
Expand Down
3 changes: 1 addition & 2 deletions lib/read.mli
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ type error = Ocaml of ocaml_parsing_error | Serialized of Schematic.Ext.error
val name: string -> Unitname.t
(** [name filename] gives the module name corresponding to filename *)

val file: kind -> string ->
Unitname.t * (M2l.t, error) result
val file: kind -> string -> (M2l.t, error) result
15 changes: 8 additions & 7 deletions tests/step_by_step.ml
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,21 @@ let pp file name deps =
Format.printf "%a@." pp {dependencies;local; library; unknown}

let () =
let file = Sys.argv.(1) in
let name, res =
Read.file {Read.format=Read.Src; kind=M2l.Structure} file in
let filename = Sys.argv.(1) in
let modname = Read.name filename in
let res =
Read.file {Read.format=Read.Src; kind=M2l.Structure} filename in
let m2l =
match res with
| Error (Ocaml _) -> Format.eprintf "Error when parsing source %a.@." Unitname.pp name; exit 2
| Error (Serialized _) -> Format.eprintf "Error when parsing m2l %a.@." Unitname.pp name; exit 2
| Error (Ocaml _) -> Format.eprintf "Error when parsing source %a.@." Unitname.pp modname; exit 2
| Error (Serialized _) -> Format.eprintf "Error when parsing m2l %a.@." Unitname.pp modname; exit 2
| Ok x -> x in
let env = Envt.start ~open_approximation:true
~libs:[]
~namespace:[]
~implicits:[["Stdlib"], Bundle.stdlib ]
Module.Dict.empty in
let pkg = (Pkg.local file) in
let pkg = (Pkg.local filename) in
let rec loop guard res = match O.next env res ~pkg with
| Error zipper ->
if guard = 0 then
Expand All @@ -73,4 +74,4 @@ let () =
loop (guard-1) zipper
| Ok (_sig, deps) -> deps in
let deps = loop 1_000_000 (O.initial m2l) in
pp file (Modname.to_string (Unitname.modname name)) deps
pp filename (Modname.to_string (Unitname.modname modname)) deps

0 comments on commit 7a61c7a

Please sign in to comment.