Skip to content

Commit

Permalink
Rename cobol_preproc/preprocess.ml into cobol_preproc/main.ml
Browse files Browse the repository at this point in the history
  • Loading branch information
lefessan committed Feb 1, 2024
1 parent 57ea08e commit f87c264
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/lsp/cobol_indent/indent_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let indent_range ~dialect ~source_format ~indent_config ~range ~filename ~conten
Cobol_preproc.Src_format.from_config SFFixed
in
let state =
Cobol_preproc.Preprocess.fold_source_lines ~dialect ~source_format
Cobol_preproc.Main.fold_source_lines ~dialect ~source_format
~on_initial_source_format:(fun src_format st -> { st with src_format })
~on_compiler_directive:(fun _ { payload = cd; _} st ->
match cd with
Expand Down
4 changes: 2 additions & 2 deletions src/lsp/cobol_lsp/document.ml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ let rewindable_parse ({ project; textdoc; _ } as doc) =
recovery = EnableRecovery { silence_benign_recoveries = true };
config = project.config.cobol_config;
} @@
Cobol_preproc.Preprocess.preprocessor
Cobol_preproc.Main.preprocessor
~options:Cobol_preproc.Options.{
default with
libpath = Project.libpath_for ~uri:(uri doc) project;
Expand Down Expand Up @@ -116,7 +116,7 @@ let reparse_and_analyze ?position ({ copybook; rewinder; textdoc; _ } as doc) =
| Some position, Some rewinder ->
check doc @@
Cobol_parser.Main.rewind_and_parse rewinder ~position @@
Cobol_preproc.Preprocess.reset_preprocessor_for_string @@
Cobol_preproc.Main.reset_preprocessor_for_string @@
Lsp.Text_document.text textdoc

(** Creates a record for a document that is not yet parsed or analyzed. *)
Expand Down
36 changes: 18 additions & 18 deletions src/lsp/cobol_parser/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ type 'x rewinder =
('x * ('x rewinder)) with_diags;
}
and preprocessor_rewind =
?new_position: Lexing.position -> (Cobol_preproc.Preprocess.preprocessor as 'r) -> 'r
?new_position: Lexing.position -> (Cobol_preproc.Main.preprocessor as 'r) -> 'r
and position =
| Lexing of Lexing.position
| Indexed of { line: int; char: int } (* all starting at 0 *)

type 'm simple_parsing
= ?options:parser_options
-> Cobol_preproc.Preprocess.preprocessor
-> Cobol_preproc.Main.preprocessor
-> (Cobol_ptree.Types.compilation_group option, 'm) output DIAGS.with_diags

type 'm rewindable_parsing
= ?options:parser_options
-> Cobol_preproc.Preprocess.preprocessor
-> Cobol_preproc.Main.preprocessor
-> (((Cobol_ptree.Types.compilation_group option, 'm) output as 'x) *
'x rewinder) DIAGS.with_diags

Expand Down Expand Up @@ -78,7 +78,7 @@ type 'm state =
basis (mostly the pre-processor and tokenizer's states). *)
and 'm preproc =
{
pp: Cobol_preproc.Preprocess.t; (* also holds diagnostics *)
pp: Cobol_preproc.Main.preprocessor; (* also holds diagnostics *)
tokzr: 'm Tokzr.state;
persist: 'm persist;
}
Expand Down Expand Up @@ -130,21 +130,21 @@ and update_tokzr ps tokzr =
else { ps with preproc = { ps.preproc with tokzr } }

let add_diag diag ({ preproc = { pp; _ }; _ } as ps) =
update_pp ps (Cobol_preproc.Preprocess.add_diag pp diag)
update_pp ps (Cobol_preproc.Main.add_diag pp diag)
let add_diags diags ({ preproc = { pp; _ }; _ } as ps) =
update_pp ps (Cobol_preproc.Preprocess.add_diags pp diags)
update_pp ps (Cobol_preproc.Main.add_diags pp diags)

let all_diags { preproc = { pp; tokzr; _ }; _ } =
DIAGS.Set.union (Cobol_preproc.Preprocess.diags pp) @@ Tokzr.diagnostics tokzr
DIAGS.Set.union (Cobol_preproc.Main.diags pp) @@ Tokzr.diagnostics tokzr

(* --- *)

let rec produce_tokens (ps: _ state as 's) : 's * Text_tokenizer.tokens =
let text, pp = Cobol_preproc.Preprocess.next_chunk ps.preproc.pp in
let text, pp = Cobol_preproc.Main.next_chunk ps.preproc.pp in
let { preproc = { pp; tokzr; _ }; _ } as ps = update_pp ps pp in
assert (text <> []);
(* Note: this is the source format in use at the end of the sentence. *)
let source_format = Cobol_preproc.Preprocess.source_format pp in
let source_format = Cobol_preproc.Main.source_format pp in
match Tokzr.tokenize_text ~source_format tokzr text with
| Error `MissingInputs, tokzr ->
produce_tokens (update_tokzr ps tokzr)
Expand Down Expand Up @@ -396,7 +396,7 @@ let on_exn ps e =
let first_stage (ps: 'm state) ~make_checkpoint : ('a, 'm) stage =
let ps, tokens = produce_tokens ps in
let first_pos = match tokens with
| [] -> Cobol_preproc.Preprocess.position ps.preproc.pp
| [] -> Cobol_preproc.Main.position ps.preproc.pp
| t :: _ -> Cobol_common.Srcloc.start_pos ~@t
in
normal ps tokens (make_checkpoint first_pos)
Expand All @@ -419,9 +419,9 @@ let aggregate_output (type m) (ps: m state) res
| Eidetic ->
let artifacts =
{ tokens = Tokzr.parsed_tokens ps.preproc.tokzr;
pplog = Cobol_preproc.Preprocess.rev_log ps.preproc.pp;
rev_comments = Cobol_preproc.Preprocess.rev_comments ps.preproc.pp;
rev_ignored = Cobol_preproc.Preprocess.rev_ignored ps.preproc.pp } in
pplog = Cobol_preproc.Main.rev_log ps.preproc.pp;
rev_comments = Cobol_preproc.Main.rev_comments ps.preproc.pp;
rev_ignored = Cobol_preproc.Main.rev_ignored ps.preproc.pp } in
WithArtifacts (res, artifacts)

(** Simple parsing *)
Expand Down Expand Up @@ -469,7 +469,7 @@ let init_rewindable_parse ps ~make_checkpoint =

(** Stores a stage as part of the memorized rewindable history events. *)
let save_interim_stage (ps, _, env) (store: _ rewindable_history) =
let preproc_position = Cobol_preproc.Preprocess.position ps.preproc.pp in
let preproc_position = Cobol_preproc.Main.position ps.preproc.pp in
match store with
| store'
when preproc_position.pos_cnum <> preproc_position.pos_bol ->
Expand Down Expand Up @@ -516,7 +516,7 @@ let find_history_event_preceding ~position ({ store; _ } as rwps) =
pos
| Indexed { line; char } ->
let ps = rewindable_parser_state rwps in
Cobol_preproc.Preprocess.position_at ~line ~char ps.preproc.pp
Cobol_preproc.Main.position_at ~line ~char ps.preproc.pp
in
let rec aux = function
| [] ->
Expand Down Expand Up @@ -560,7 +560,7 @@ let rec rewind_n_parse

let rewindable_parse
: options:_ -> memory:'m memory -> make_checkpoint:_
-> Cobol_preproc.Preprocess.preprocessor
-> Cobol_preproc.Main.preprocessor
-> ((('a option, 'm) output as 'x) * 'x rewinder) with_diags =
fun ~options ~memory ~make_checkpoint pp ->
let res, rwps =
Expand All @@ -581,7 +581,7 @@ let parse
(type m)
~(memory: m memory)
?(options = Options.default)
: Cobol_preproc.Preprocess.t ->
: Cobol_preproc.Main.t ->
(Cobol_ptree.Types.compilation_group option, m) output with_diags =
parse_once ~options ~memory
~make_checkpoint:Grammar.Incremental.compilation_group
Expand All @@ -593,7 +593,7 @@ let rewindable_parse
(type m)
~(memory: m memory)
?(options = Options.default)
: Cobol_preproc.Preprocess.t ->
: Cobol_preproc.Main.t ->
(((Cobol_ptree.Types.compilation_group option, m) output as 'x) * 'x rewinder)
with_diags =
rewindable_parse ~options ~memory
Expand Down
6 changes: 3 additions & 3 deletions src/lsp/cobol_parser/main.mli
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ open Outputs
(** Simple parsing functions traverse the inputs once to produce a result. *)
type 'm simple_parsing
= ?options:Options.parser_options
-> Cobol_preproc.Preprocess.t
-> Cobol_preproc.Main.preprocessor
-> (Cobol_ptree.Types.compilation_group option, 'm) output
Cobol_common.Diagnostics.with_diags

Expand All @@ -60,7 +60,7 @@ val parse_with_artifacts
{!rewinder} that may then be given to {!rewind_and_parse}. *)
type 'm rewindable_parsing
= ?options:parser_options
-> Cobol_preproc.Preprocess.preprocessor
-> Cobol_preproc.Main.preprocessor
-> (((Cobol_ptree.Types.compilation_group option, 'm) output as 'x) * 'x rewinder)
Cobol_common.Diagnostics.with_diags

Expand All @@ -74,7 +74,7 @@ and 'x rewinder
of the input. *)
and preprocessor_rewind =
?new_position:Lexing.position ->
(Cobol_preproc.Preprocess.t as 'r) -> 'r
(Cobol_preproc.Main.t as 'r) -> 'r

(* val rewindable_parse *)
(* : memory:'m memory -> 'm rewindable_parsing *)
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/lsp/superbol_free_lib/command_pp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ let cmd =
~default: common.preproc_options.source_format }
in
input |>
Cobol_preproc.Preprocess.preprocessor ~options:preproc_options |>
Cobol_preproc.Main.preprocessor ~options:preproc_options |>
Cobol_parser.Main.parse_simple ~options:common.parser_options
in
let my_text = Cobol_preproc.Src_input.from ~filename:file ~f:parse in
Expand Down Expand Up @@ -96,7 +96,7 @@ let cmd =
let text =
let common = common_get () in
Cobol_common.Diagnostics.show_n_forget @@
Cobol_preproc.Preprocess.text_of_file file
Cobol_preproc.Main.text_of_file file
~options:common.preproc_options
in
let s =
Expand Down
14 changes: 7 additions & 7 deletions test/cobol_parsing/parser_testing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let preproc
=
Cobol_common.Srcloc.TESTING.register_file_contents ~filename contents;
String { filename; contents } |>
Cobol_preproc.Preprocess.preprocessor
Cobol_preproc.Main.preprocessor
~options:Cobol_preproc.Options.{
default with
libpath = [];
Expand Down Expand Up @@ -149,7 +149,7 @@ let rewindable_parse
=
let DIAGS.{ result = Only ptree, rewinder; diags } =
String { filename = "prog.cob"; contents = prog } |>
Cobol_preproc.Preprocess.preprocessor
Cobol_preproc.Main.preprocessor
~options:Cobol_preproc.Options.{
verbose; libpath = []; source_format;
config = Option.value config ~default:default.config;
Expand Down Expand Up @@ -198,7 +198,7 @@ let iteratively_append_chunks ?config ~f (prog, positions) =
Pretty.(to_string "%S" @@ EzString.after prog (pos.cnum - 1));
succ i,
rewind_n_parse ~f:(f i num_chunks) rewinder pos
(Cobol_preproc.Preprocess.reset_preprocessor_for_string prog)
(Cobol_preproc.Main.reset_preprocessor_for_string prog)
end (1, rewinder) (pairwise positions.pos_anonymous)


Expand Down Expand Up @@ -230,7 +230,7 @@ let iteratively_append_chunks_stuttering ?config ~f
Pretty.(to_string "%S" @@ EzString.after prog (pos.cnum - 1));
let rewinder =
rewind_n_parse ~f:(f i num_chunks) rewinder pos
(Cobol_preproc.Preprocess.reset_preprocessor_for_string prog)
(Cobol_preproc.Main.reset_preprocessor_for_string prog)
in
let rewinder =
if i < num_chunks then begin
Expand All @@ -241,7 +241,7 @@ let iteratively_append_chunks_stuttering ?config ~f
Fmt.(truncated ~max:30)
Pretty.(to_string "%S" @@ EzString.after prog' (pos.cnum - 1));
rewind_n_parse ~f:(f i num_chunks) rewinder next_pos_1
(Cobol_preproc.Preprocess.reset_preprocessor_for_string prog')
(Cobol_preproc.Main.reset_preprocessor_for_string prog')
end else rewinder
in
succ i, rewinder
Expand Down Expand Up @@ -280,13 +280,13 @@ let simulate_cut_n_paste ?config ~f0 ~f ?verbose ?(repeat = 1)
and prog_suffix = EzString.after prog (next_pos.cnum - 1) in
let rewinder =
rewind_n_parse ~f:(fun _ _ -> ()) rewinder pos @@
Cobol_preproc.Preprocess.reset_preprocessor_for_string @@
Cobol_preproc.Main.reset_preprocessor_for_string @@
prog_prefix ^ prog_suffix
in
Pretty.out "Putting it back@.";
let rewinder =
rewind_n_parse ~f:(f chunk_num num_chunks ~ptree0) rewinder pos @@
Cobol_preproc.Preprocess.reset_preprocessor_for_string prog
Cobol_preproc.Main.reset_preprocessor_for_string prog
in
loop (succ i) rewinder
end
Expand Down
16 changes: 8 additions & 8 deletions test/cobol_preprocessing/preproc_testing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let preprocess
?(source_format = Cobol_config.Types.(SF SFFixed))
contents =
DIAGS.show_n_forget ~ppf:Fmt.stdout @@
Cobol_preproc.Preprocess.preprocess_input
Cobol_preproc.Main.preprocess_input
~options:Cobol_preproc.Options.{ default with verbose; libpath = [];
source_format } @@
Cobol_preproc.Src_input.String { filename; contents }
Expand All @@ -36,7 +36,7 @@ let show_text
contents =
let text =
DIAGS.show_n_forget ~ppf:Fmt.stdout @@
Cobol_preproc.Preprocess.text_of_input
Cobol_preproc.Main.text_of_input
~options:Cobol_preproc.Options.{ default with verbose; libpath = [];
source_format } @@
Cobol_preproc.Src_input.String { filename; contents }
Expand All @@ -53,7 +53,7 @@ let show_source_lines
contents
=
DIAGS.show_n_forget ~ppf:Fmt.stdout @@
Cobol_preproc.Preprocess.fold_source_lines ~dialect ~source_format
Cobol_preproc.Main.fold_source_lines ~dialect ~source_format
~f:begin fun lnum line () ->
if with_line_numbers then Pretty.out "@\n%u: " lnum else Pretty.out "@\n";
Pretty.out "%a" Cobol_preproc.Text.pp_text line;
Expand All @@ -71,10 +71,10 @@ let show_source_lines
end

let rec show_all_text pp =
match Cobol_preproc.Preprocess.next_chunk pp with
match Cobol_preproc.Main.next_chunk pp with
| { payload = Cobol_preproc.Text.Eof; _ } :: _, _ ->
Cobol_common.Diagnostics.Set.pp Fmt.stdout
(Cobol_preproc.Preprocess.diags pp);
(Cobol_preproc.Main.diags pp);
pp
| text, pp ->
Pretty.out "%a@\n" Cobol_preproc.Text.pp_text text;
Expand All @@ -98,12 +98,12 @@ let preprocess_n_then_cut_n_paste_right_of_indicator
Pretty.out "fixed: %a@." show_lines fixed_lines;
Pretty.out " free: %a@." show_lines free_lines;
Cobol_preproc.Src_input.string ~filename fixed_format_contents |>
Cobol_preproc.Preprocess.preprocessor
Cobol_preproc.Main.preprocessor
~options:Cobol_preproc.Options.{ default with verbose; libpath = [];
source_format } |>
show_all_text |>
Cobol_preproc.Preprocess.reset_preprocessor_for_string free_format_contents |>
Cobol_preproc.Main.reset_preprocessor_for_string free_format_contents |>
show_all_text |>
Cobol_preproc.Preprocess.reset_preprocessor_for_string fixed_format_contents |>
Cobol_preproc.Main.reset_preprocessor_for_string fixed_format_contents |>
show_all_text |>
ignore
2 changes: 1 addition & 1 deletion test/output-tests/gnucobol.ml
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ let do_check_parse (test_filename, contents, _, { check_loc;
let source_format = guess_source_format ~filename ~command:check_command in
let parse_simple input =
input |>
Cobol_preproc.Preprocess.preprocessor
Cobol_preproc.Main.preprocessor
~options:Cobol_preproc.Options.{ default with source_format } |>
Cobol_parser.Main.parse_simple
in
Expand Down
2 changes: 1 addition & 1 deletion test/output-tests/preproc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ open Testsuite_utils

let preprocess_file ~source_format ~config filename =
Cobol_common.Diagnostics.show_n_forget ~min_level:Error @@
Cobol_preproc.Preprocess.preprocess_file filename
Cobol_preproc.Main.preprocess_file filename
~options:Cobol_preproc.Options.{ source_format; config;
verbose = false; libpath = [] }
~ppf:std_formatter
Expand Down
2 changes: 1 addition & 1 deletion test/output-tests/reparse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let reparse_file ~source_format ~config filename =
default with
recovery = DisableRecovery
} @@
Cobol_preproc.Preprocess.preprocessor
Cobol_preproc.Main.preprocessor
~options:Cobol_preproc.Options.{
default with
libpath = [];
Expand Down

0 comments on commit f87c264

Please sign in to comment.