diff --git a/src/lsp/cobol_indent/indent_main.ml b/src/lsp/cobol_indent/indent_main.ml index a965fbbe7..507bab36b 100644 --- a/src/lsp/cobol_indent/indent_main.ml +++ b/src/lsp/cobol_indent/indent_main.ml @@ -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 diff --git a/src/lsp/cobol_lsp/document.ml b/src/lsp/cobol_lsp/document.ml index e99e1b7d2..3f91a5dc1 100644 --- a/src/lsp/cobol_lsp/document.ml +++ b/src/lsp/cobol_lsp/document.ml @@ -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; @@ -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. *) diff --git a/src/lsp/cobol_parser/main.ml b/src/lsp/cobol_parser/main.ml index fea41c2c9..5be32258c 100644 --- a/src/lsp/cobol_parser/main.ml +++ b/src/lsp/cobol_parser/main.ml @@ -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 @@ -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; } @@ -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) @@ -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) @@ -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 *) @@ -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 -> @@ -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 | [] -> @@ -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 = @@ -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 @@ -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 diff --git a/src/lsp/cobol_parser/main.mli b/src/lsp/cobol_parser/main.mli index 015c772d7..7fa5e18d0 100644 --- a/src/lsp/cobol_parser/main.mli +++ b/src/lsp/cobol_parser/main.mli @@ -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 @@ -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 @@ -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 *) diff --git a/src/lsp/cobol_preproc/preprocess.ml b/src/lsp/cobol_preproc/main.ml similarity index 100% rename from src/lsp/cobol_preproc/preprocess.ml rename to src/lsp/cobol_preproc/main.ml diff --git a/src/lsp/cobol_preproc/preprocess.mli b/src/lsp/cobol_preproc/main.mli similarity index 100% rename from src/lsp/cobol_preproc/preprocess.mli rename to src/lsp/cobol_preproc/main.mli diff --git a/src/lsp/superbol_free_lib/command_pp.ml b/src/lsp/superbol_free_lib/command_pp.ml index 2c4182f98..2651b0322 100644 --- a/src/lsp/superbol_free_lib/command_pp.ml +++ b/src/lsp/superbol_free_lib/command_pp.ml @@ -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 @@ -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 = diff --git a/test/cobol_parsing/parser_testing.ml b/test/cobol_parsing/parser_testing.ml index fbf9eb373..9ad7b88d8 100644 --- a/test/cobol_parsing/parser_testing.ml +++ b/test/cobol_parsing/parser_testing.ml @@ -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 = []; @@ -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; @@ -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) @@ -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 @@ -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 @@ -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 diff --git a/test/cobol_preprocessing/preproc_testing.ml b/test/cobol_preprocessing/preproc_testing.ml index 48eaafd54..0e0b892f4 100644 --- a/test/cobol_preprocessing/preproc_testing.ml +++ b/test/cobol_preprocessing/preproc_testing.ml @@ -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 } @@ -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 } @@ -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; @@ -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; @@ -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 diff --git a/test/output-tests/gnucobol.ml b/test/output-tests/gnucobol.ml index 4a4251ba8..d2ba6d1a4 100644 --- a/test/output-tests/gnucobol.ml +++ b/test/output-tests/gnucobol.ml @@ -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 diff --git a/test/output-tests/preproc.ml b/test/output-tests/preproc.ml index 960476584..e509ee9ed 100644 --- a/test/output-tests/preproc.ml +++ b/test/output-tests/preproc.ml @@ -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 diff --git a/test/output-tests/reparse.ml b/test/output-tests/reparse.ml index 02cf9bfe2..bb1ef1b98 100644 --- a/test/output-tests/reparse.ml +++ b/test/output-tests/reparse.ml @@ -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 = [];