Skip to content

Commit

Permalink
Temporarily disable the EXEC SQL scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
nberth committed Jul 12, 2024
1 parent 7a96336 commit 1c10411
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 47 deletions.
5 changes: 4 additions & 1 deletion src/lsp/superbol_preprocs/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ module EXEC_MAP = Cobol_preproc.Options.EXEC_MAP
let exec_scanners =
Cobol_parser.Options.{
exec_scanner_fallback = Generic.scanner; (* for now; TODO: Call.scanner? *)
exec_scanners = Cobol_preproc.Options.EXEC_MAP.singleton "SQL" Esql.scanner;
(* NB: Kept empty for now (the LSP does not yet benefit from this
preprocessor) *)
exec_scanners = Cobol_preproc.Options.EXEC_MAP.empty;
(* exec_scanners = Cobol_preproc.Options.EXEC_MAP.singleton "SQL" Esql.scanner; *)
}

let more scanners =
Expand Down
13 changes: 11 additions & 2 deletions test/cobol_parsing/exec_blocks.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@
(* *)
(**************************************************************************)

let exec_scanners =
Superbol_preprocs.more [
"SQL", Superbol_preprocs.Esql.scanner;
]

let%expect_test "exec-block-with-cobol-separators" =
Parser_testing.show_parsed_tokens {|
Parser_testing.show_parsed_tokens
~parser_options:(Parser_testing.options ~exec_scanners ()) @@
{|
PROGRAM-ID. prog.
PROCEDURE DIVISION.
EXEC SQL
Expand All @@ -35,7 +42,9 @@ let%expect_test "exec-block-with-invalid-percentage-character" =
"NO-%", Superbol_preprocs.No_percentage_toy.scanner;
]
in
Parser_testing.show_diagnostics ~exec_scanners {|
Parser_testing.show_diagnostics
~parser_options:(Parser_testing.options ~exec_scanners ()) @@
{|
PROGRAM-ID. prog.
PROCEDURE DIVISION.
EXEC NO-%
Expand Down
61 changes: 26 additions & 35 deletions test/cobol_parsing/parser_testing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,47 +27,36 @@ let preproc
source_format
}

let default_parser_options =
Cobol_parser.Options.default
~exec_scanners: Superbol_preprocs.exec_scanners
let options
?(verbose = false)
?(exec_scanners = Superbol_preprocs.exec_scanners) () =
{
(Cobol_parser.Options.default ~exec_scanners) with
verbose;
recovery = EnableRecovery { silence_benign_recoveries = true }
}

let show_parsed_tokens ?(verbose = false) ?(with_locations = false)
?source_format ?filename contents =

let show_parsed_tokens ?(parser_options = options ())
?(with_locations = false) ?source_format ?filename contents =
let { result = WithArtifacts (_, { tokens; _ }); _ } =
preproc ?source_format ?filename contents |>
Cobol_parser.parse_with_artifacts
~options: {
default_parser_options with
verbose;
recovery = EnableRecovery { silence_benign_recoveries = true };
}
Cobol_parser.parse_with_artifacts ~options:parser_options
in
(if with_locations
then Cobol_parser.INTERNAL.pp_tokens' ~fsep:"@\n"
else Cobol_parser.INTERNAL.pp_tokens) Fmt.stdout (Lazy.force tokens)

let show_diagnostics ?(verbose = false) ?source_format ?filename
?(exec_scanners = Superbol_preprocs.exec_scanners) contents =
let show_diagnostics ?(parser_options = options ())
?source_format ?filename contents =
preproc ?source_format ?filename contents |>
Cobol_parser.parse_simple
~options: {
default_parser_options with
verbose;
exec_scanners;
recovery = EnableRecovery { silence_benign_recoveries = true };
} |>
Cobol_parser.parse_simple ~options:parser_options |>
Cobol_parser.Outputs.sink_result ~set_status:false ~ppf:Fmt.stdout

let just_parse ?(verbose = false) ?source_format ?filename
?(exec_scanners = Superbol_preprocs.exec_scanners) contents =
let just_parse ?(parser_options = options ())
?source_format ?filename contents =
preproc ?source_format ?filename contents |>
Cobol_parser.parse_simple
~options: {
default_parser_options with
verbose;
exec_scanners;
recovery = EnableRecovery { silence_benign_recoveries = true };
} |>
Cobol_parser.parse_simple ~options:parser_options |>
ignore

(* --- *)
Expand Down Expand Up @@ -158,7 +147,7 @@ let triplewise positions =
(** Note: won't show detailed source locations as the openned file is neither
actually on disk nor registered via {!Srcloc.register_file_contents}. *)
let rewindable_parse
?(verbose = false)
?(parser_options = options ())
?(source_format = Cobol_config.(SF SFFixed))
?config
prog
Expand All @@ -167,16 +156,17 @@ let rewindable_parse
String { filename = "prog.cob"; contents = prog } |>
Cobol_preproc.preprocessor
~options:Cobol_preproc.Options.{
verbose; libpath = []; source_format;
verbose = parser_options.verbose;
libpath = []; source_format;
exec_preprocs = EXEC_MAP.empty;
env = Cobol_preproc.Env.empty;
config = Option.value config ~default:default.config;
} |>
Cobol_parser.rewindable_parse_simple
~options: {
default_parser_options with
verbose; recovery = DisableRecovery;
config = Option.value config ~default:default_parser_options.config;
parser_options with
recovery = DisableRecovery;
config = Option.value config ~default:parser_options.config;
}
in
ptree, diags, rewinder
Expand Down Expand Up @@ -289,7 +279,8 @@ let iteratively_append_chunks_stuttering ?config ~f
let simulate_cut_n_paste ?config ~f0 ~f ?verbose ?(repeat = 1)
(prog, positions) =
Random.init 42;
let ptree0, diags, rewinder = rewindable_parse ?verbose ?config prog in
let parser_options = options ?verbose () in
let ptree0, diags, rewinder = rewindable_parse ~parser_options ?config prog in
f0 ~ptree0 diags;
let positions = Array.of_list positions.pos_anonymous in
let num_chunks = Array.length positions - 1 in
Expand Down
2 changes: 1 addition & 1 deletion test/cobol_parsing/tokens.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ let%expect_test "tokens-after-syntax-errors" =

let%expect_test "token-locations" =
Parser_testing.show_parsed_tokens ~source_format:Auto ~with_locations:true
~verbose:true
~parser_options:(Parser_testing.options ~verbose:true ())
{|(TMP:1)|};
[%expect {|
Tks: (, WORD[TMP], :, DIGITS[1], ), EOF
Expand Down
10 changes: 3 additions & 7 deletions test/cobol_typeck/typeck_testing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@ open Parser_testing

module DIAGS = Cobol_common.Diagnostics

let show_diagnostics ?(show_data = false) ?(verbose = false)
let show_diagnostics ?(show_data = false)
?(parser_options = Parser_testing.options ())
?source_format ?filename contents =
preproc ?source_format ?filename contents |>
Cobol_parser.parse_simple
~options: {
default_parser_options with
verbose;
recovery = EnableRecovery { silence_benign_recoveries = true };
} |>
Cobol_parser.parse_simple ~options:parser_options |>
Cobol_parser.Outputs.translate_diags |>
DIAGS.map_result ~f:Cobol_typeck.compilation_group |>
DIAGS.more_result ~f:Cobol_typeck.Results.translate_diags |>
Expand Down
7 changes: 6 additions & 1 deletion test/output-tests/reparse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ open FileString.OP
open Testsuite_utils

let default_parser_options =
let exec_scanners =
Superbol_preprocs.more [
"SQL", Superbol_preprocs.Esql.scanner;
]
in
Cobol_parser.Options.{
(default ~exec_scanners: Superbol_preprocs.exec_scanners) with
(default ~exec_scanners) with
recovery = DisableRecovery
}

Expand Down

0 comments on commit 1c10411

Please sign in to comment.