Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions bin/camelot.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ let set_lint_file : string -> unit = fun s ->

let fail msg = prerr_endline msg; exit 1

let safe_open src =
try src, open_in src
with Sys_error msg -> fail msg

let lex_src file =
let src, f = safe_open file in
src, Lexing.from_channel f

let parse_src (src, lexbuf) =
src, Parse.implementation lexbuf
let parse_src file =
try
let ch = open_in file in
let lexbuf = Lexing.from_channel ch in
let tree = Parse.implementation lexbuf in
close_in ch;
tree
with
| Sys_error msg -> fail (Printf.sprintf "error when parsing %s: %s" file msg)
| _ -> fail (Printf.sprintf "unknown error when parsing %s" file)

let sanitize_dir d =
if d.[String.length d - 1] = '/' then d
Expand Down Expand Up @@ -82,8 +82,8 @@ let parse_sources_in dirname : (string * Parsetree.structure) list =
files_to_lint |>
List.filter (fun f -> not (is_directory f)) |> (* remove directories *)
List.filter (fun f -> Filename.check_suffix f ".ml") |> (* only want to lint *.ml files *)
List.map (lex_src) |> (* Lex the files *)
List.map (parse_src) (* Parse the files *) in
List.map (fun f -> f, parse_src f) (* Parse the files *)
in
to_lint

let usage_msg =
Expand Down
6 changes: 4 additions & 2 deletions lib/traverse/find.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ let pass_structures (store: Hint.hint list ref) (f: string) (structure : Parsetr


let pass_file (store: Hint.hint list ref) (f: string) (_payload: Parsetree.structure) : unit =
let pc = Pctxt.ctxt_for_lexical f (open_in f) in
let ch = open_in f in
let pc = Pctxt.ctxt_for_lexical f ch in
let checks =
Style.Checkers.lexical_checks |> Arthur.extract (Lazy.force cfg) in
List.iter (fun (_, check) -> check store pc) checks
List.iter (fun (_, check) -> check store pc) checks;
close_in ch