diff --git a/src/lsp/superbol_free_lib/common_args.ml b/src/lsp/superbol_free_lib/common_args.ml index f96f4c1d2..a634bc843 100644 --- a/src/lsp/superbol_free_lib/common_args.ml +++ b/src/lsp/superbol_free_lib/common_args.ml @@ -49,13 +49,20 @@ let iter_comma_separated_spec ~showable ~option_name ~f spec = (StringSet.elements unknowns)) let get () = - let conf = ref "" in (* Fixed by default *) + let conf = ref "" in let dialect = ref None in let strict = ref false in let format = ref Cobol_config.Auto in (* Fixed by default *) let formats = ["free"; "Free"; "FREE"; "fixed"; "Fixed"; "FIXED"; - "cobolx"; "Cobolx"; "CobolX"; "COBOLX"] in + "cobol85"; "COBOL85"; + "variable"; "VARIABLE"; + "xopen"; "XOPEN"; "XOpen"; + "xcard"; "xCard"; "XCARD"; + "crt"; "CRT"; + "terminal"; "Terminal"; "TERMINAL"; + "cobolx"; "Cobolx"; "CobolX"; "COBOLX"; + "auto"; "AUTO"] in let libpath = ref ["."] in let recovery = ref true in let show = ref [`Pending] in (* default *) @@ -80,9 +87,15 @@ let get () = ["source-format"], Arg.Symbol (formats, fun f -> format := match String.uppercase_ascii f with - | "FIXED" -> Cobol_config.SF Cobol_config.SFFixed + | "FIXED" | "COBOL85" -> Cobol_config.SF Cobol_config.SFFixed | "FREE" -> SF SFFree + | "VARIABLE" -> SF SFVariable + | "XOPEN" -> SF SFXOpen + | "XCARD" -> SF SFxCard + | "CRT" -> SF SFCRT + | "TERMINAL" -> SF SFTrm | "COBOLX" -> SF SFCOBOLX + | "AUTO" -> Auto | _ -> Cobol_common.Diagnostics.Now.warn Fmt.stderr diff --git a/test/output-tests/gnucobol.ml b/test/output-tests/gnucobol.ml index df858cad9..4013a52a5 100644 --- a/test/output-tests/gnucobol.ml +++ b/test/output-tests/gnucobol.ml @@ -137,7 +137,40 @@ let setup_input ~filename contents = let delete_file ~filename = Ez_file.FileString.remove filename -let free_format_regexp = Str.regexp {re|\(^-free\|[ \t]-free\b\)|re} +let free_flag_regexp = Str.regexp {re|\(^-free\|[ \t]-free\b\)|re} +let fixd_format_regexp = Str.regexp_string "-fformat=fixed" +let free_format_regexp = Str.regexp_string "-fformat=free" +let cb85_format_regexp = Str.regexp_string "-fformat=cobol85" +let vrbl_format_regexp = Str.regexp_string "-fformat=variable" +let xopn_format_regexp = Str.regexp_string "-fformat=xopen" +let xcrd_format_regexp = Str.regexp_string "-fformat=xcard" +let crt__format_regexp = Str.regexp_string "-fformat=crt" +let term_format_regexp = Str.regexp_string "-fformat=terminal" +let cblx_format_regexp = Str.regexp_string "-fformat=cobolx" +let auto_format_regexp = Str.regexp_string "-fformat=auto" + +let guess_source_format ~filename ~command = (* hackish detection of format *) + let filename_suffixp suffix = + EzString.ends_with ~suffix filename + and command_matchp regexp = + try ignore (Str.search_forward regexp command 0); true + with Not_found -> false + in + Option.value ~default:Cobol_config.(SF SFFixed) @@ + List.find_map (fun (p, f) -> if Lazy.force p then Some f else None) [ + lazy (filename_suffixp "free.cob"), Cobol_config.(SF SFFree); + lazy (command_matchp free_flag_regexp), Cobol_config.(SF SFFree); + lazy (command_matchp fixd_format_regexp), Cobol_config.(SF SFFixed); + lazy (command_matchp free_format_regexp), Cobol_config.(SF SFFree); + lazy (command_matchp cb85_format_regexp), Cobol_config.(SF SFFixed); + lazy (command_matchp vrbl_format_regexp), Cobol_config.(SF SFVariable); + lazy (command_matchp xopn_format_regexp), Cobol_config.(SF SFXOpen); + lazy (command_matchp xcrd_format_regexp), Cobol_config.(SF SFxCard); + lazy (command_matchp term_format_regexp), Cobol_config.(SF SFTrm); + lazy (command_matchp cblx_format_regexp), Cobol_config.(SF SFCOBOLX); + lazy (command_matchp auto_format_regexp), Cobol_config.Auto; + ] + let do_check_parse (test_filename, contents, _, { check_loc; check_command; _ }) = let filename = filename_for_loc test_filename check_loc in @@ -150,13 +183,7 @@ let do_check_parse (test_filename, contents, _, { check_loc; let loc = Autofonce_m4.M4Printer.string_of_location check_loc in Pretty.error "Considering: %a... " pp_relloc loc; Pretty.out "Considering: %a@\n" pp_relloc loc; - let source_format = (* hackish detection of format *) - if EzString.ends_with ~suffix:"free.cob" filename || - try ignore (Str.search_forward free_format_regexp check_command 0); true - with Not_found -> false - then Cobol_config.(SF SFFree) - else Cobol_config.(SF SFFixed) - in + let source_format = guess_source_format ~filename ~command:check_command in let parse_simple input = input |> Cobol_preproc.preprocessor diff --git a/test/output-tests/run_extensions.expected b/test/output-tests/run_extensions.expected index ece08c4f2..bfe9cd926 100644 --- a/test/output-tests/run_extensions.expected +++ b/test/output-tests/run_extensions.expected @@ -3454,432 +3454,25 @@ Considering: import/gnucobol/tests/testsuite.src/run_extensions.at:5065:0 Considering: import/gnucobol/tests/testsuite.src/run_extensions.at:5049:0 Considering: import/gnucobol/tests/testsuite.src/run_extensions.at:5101:0 Considering: import/gnucobol/tests/testsuite.src/run_extensions.at:5149:0 -run_extensions.at-5149-fit.cob:2.6-2.7: - 1 - 2 > * Sample program in X/Open format, and with longer lines and truncated literals. ----- ^ - 3 - 4 IDENTIFICATION DIVISION. ->> Error: Unexpected indicator: `l' - -run_extensions.at-5149-fit.cob:4.6-4.7: - 1 - 2 * Sample program in X/Open format, and with longer lines and truncated literals. - 3 - 4 > IDENTIFICATION DIVISION. ----- ^ - 5 PROGRAM-ID. fit. - 6 DATA DIVISION. ->> Error: Unexpected indicator: `F' - -run_extensions.at-5149-fit.cob:5.6-5.7: - 2 * Sample program in X/Open format, and with longer lines and truncated literals. - 3 - 4 IDENTIFICATION DIVISION. - 5 > PROGRAM-ID. fit. ----- ^ - 6 DATA DIVISION. - 7 WORKING-STORAGE SECTION. ->> Error: Unexpected indicator: `M' - -run_extensions.at-5149-fit.cob:7.6-7.7: - 4 IDENTIFICATION DIVISION. - 5 PROGRAM-ID. fit. - 6 DATA DIVISION. - 7 > WORKING-STORAGE SECTION. ----- ^ - 8 PROCEDURE DIVISION. - 9 DISPLAY ' 20 30 40 50 60 70 79' ->> Error: Unexpected indicator: `G' - -run_extensions.at-5149-fit.cob:8.6-8.7: - 5 PROGRAM-ID. fit. - 6 DATA DIVISION. - 7 WORKING-STORAGE SECTION. - 8 > PROCEDURE DIVISION. ----- ^ - 9 DISPLAY ' 20 30 40 50 60 70 79' - 10 D DISPLAY ' 20 30 40 50 60 70 79' ->> Error: Unexpected indicator: `U' - -run_extensions.at-5149-fit.cob:9.6-9.7: - 6 DATA DIVISION. - 7 WORKING-STORAGE SECTION. - 8 PROCEDURE DIVISION. - 9 > DISPLAY ' 20 30 40 50 60 70 79' ----- ^ - 10 D DISPLAY ' 20 30 40 50 60 70 79' - 11 STOP RUN. ->> Error: Unexpected indicator: `Y' - -run_extensions.at-5149-fit.cob:10.6-10.7: - 7 WORKING-STORAGE SECTION. - 8 PROCEDURE DIVISION. - 9 DISPLAY ' 20 30 40 50 60 70 79' - 10 > D DISPLAY ' 20 30 40 50 60 70 79' ----- ^ - 11 STOP RUN. ->> Error: Unexpected indicator: `L' - -run_extensions.at-5149-fit.cob:9.8-9.72: - 6 DATA DIVISION. - 7 WORKING-STORAGE SECTION. - 8 PROCEDURE DIVISION. - 9 > DISPLAY ' 20 30 40 50 60 70 79' ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 10 D DISPLAY ' 20 30 40 50 60 70 79' - 11 STOP RUN. ->> Error: Missing continuation of ` 20 30 40 50 60 70 ' - -run_extensions.at-5149-fit.cob:11.6-11.7: - 8 PROCEDURE DIVISION. - 9 DISPLAY ' 20 30 40 50 60 70 79' - 10 D DISPLAY ' 20 30 40 50 60 70 79' - 11 > STOP RUN. ----- ^ ->> Error: Unexpected indicator: `U' - -run_extensions.at-5149-fit.cob:10.10-10.72: - 7 WORKING-STORAGE SECTION. - 8 PROCEDURE DIVISION. - 9 DISPLAY ' 20 30 40 50 60 70 79' - 10 > D DISPLAY ' 20 30 40 50 60 70 79' ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 11 STOP RUN. ->> Error: Missing continuation of ` 20 30 40 50 60 70 ' - -run_extensions.at-5149-fit.cob:2.7-2.8: - 1 - 2 > * Sample program in X/Open format, and with longer lines and truncated literals. ----- ^ - 3 - 4 IDENTIFICATION DIVISION. ->> Error: Invalid syntax - Considering: import/gnucobol/tests/testsuite.src/run_extensions.at:5131:0 -run_extensions.at-5131-prog.cob:2.6-2.7: - 1 - 2 > * Sample program in X/Open free-form format. ----- ^ - 3 - 4 IDENTIFICATION DIVISION. ->> Error: Unexpected indicator: `l' - -run_extensions.at-5131-prog.cob:4.6-4.7: - 1 - 2 * Sample program in X/Open free-form format. - 3 - 4 > IDENTIFICATION DIVISION. ----- ^ - 5 PROGRAM-ID. prog. - 6 DATA DIVISION. ->> Error: Unexpected indicator: `F' - -run_extensions.at-5131-prog.cob:5.6-5.7: - 2 * Sample program in X/Open free-form format. - 3 - 4 IDENTIFICATION DIVISION. - 5 > PROGRAM-ID. prog. ----- ^ - 6 DATA DIVISION. - 7 WORKING-STORAGE SECTION. ->> Error: Unexpected indicator: `M' - -run_extensions.at-5131-prog.cob:7.6-7.7: - 4 IDENTIFICATION DIVISION. - 5 PROGRAM-ID. prog. - 6 DATA DIVISION. - 7 > WORKING-STORAGE SECTION. ----- ^ - 8 PROCEDURE DIVISION. - 9 / Beginning of the code ->> Error: Unexpected indicator: `G' - -run_extensions.at-5131-prog.cob:8.6-8.7: - 5 PROGRAM-ID. prog. - 6 DATA DIVISION. - 7 WORKING-STORAGE SECTION. - 8 > PROCEDURE DIVISION. ----- ^ - 9 / Beginning of the code - 10 DISPLAY "OK" NO ADVANCING ->> Error: Unexpected indicator: `U' - -run_extensions.at-5131-prog.cob:9.6-9.7: - 6 DATA DIVISION. - 7 WORKING-STORAGE SECTION. - 8 PROCEDURE DIVISION. - 9 > / Beginning of the code ----- ^ - 10 DISPLAY "OK" NO ADVANCING - 11 * If debug: ->> Error: Unexpected indicator: `n' - -run_extensions.at-5131-prog.cob:10.6-10.7: - 7 WORKING-STORAGE SECTION. - 8 PROCEDURE DIVISION. - 9 / Beginning of the code - 10 > DISPLAY "OK" NO ADVANCING ----- ^ - 11 * If debug: - 12 D DISPLAY "KO" NO ADVANCING ->> Error: Unexpected indicator: `Y' - -run_extensions.at-5131-prog.cob:11.6-11.7: - 8 PROCEDURE DIVISION. - 9 / Beginning of the code - 10 DISPLAY "OK" NO ADVANCING - 11 > * If debug: ----- ^ - 12 D DISPLAY "KO" NO ADVANCING - 13 STOP RUN. ->> Error: Unexpected indicator: `e' - -run_extensions.at-5131-prog.cob:12.6-12.7: - 9 / Beginning of the code - 10 DISPLAY "OK" NO ADVANCING - 11 * If debug: - 12 > D DISPLAY "KO" NO ADVANCING ----- ^ - 13 STOP RUN. ->> Error: Unexpected indicator: `L' - -run_extensions.at-5131-prog.cob:13.6-13.7: - 10 DISPLAY "OK" NO ADVANCING - 11 * If debug: - 12 D DISPLAY "KO" NO ADVANCING - 13 > STOP RUN. ----- ^ ->> Error: Unexpected indicator: `U' - -run_extensions.at-5131-prog.cob:2.7-2.8: - 1 - 2 > * Sample program in X/Open free-form format. ----- ^ - 3 - 4 IDENTIFICATION DIVISION. ->> Error: Invalid syntax - Considering: import/gnucobol/tests/testsuite.src/run_extensions.at:5231:0 -run_extensions.at-5231-fit.cob:2.6-2.7: - 1 - 2 > * Sample program in ACU terminal format, and with longer lines and truncated literals. ----- ^ - 3 - 4 IDENTIFICATION DIVISION. ->> Error: Unexpected indicator: `l' - -run_extensions.at-5231-fit.cob:4.6-4.7: - 1 - 2 * Sample program in ACU terminal format, and with longer lines and truncated literals. - 3 - 4 > IDENTIFICATION DIVISION. ----- ^ - 5 PROGRAM-ID. fit. - 6 DATA DIVISION. ->> Error: Unexpected indicator: `F' - -run_extensions.at-5231-fit.cob:5.6-5.7: - 2 * Sample program in ACU terminal format, and with longer lines and truncated literals. - 3 - 4 IDENTIFICATION DIVISION. - 5 > PROGRAM-ID. fit. ----- ^ - 6 DATA DIVISION. - 7 WORKING-STORAGE SECTION. ->> Error: Unexpected indicator: `M' - -run_extensions.at-5231-fit.cob:7.6-7.7: - 4 IDENTIFICATION DIVISION. - 5 PROGRAM-ID. fit. - 6 DATA DIVISION. - 7 > WORKING-STORAGE SECTION. ----- ^ - 8 PROCEDURE DIVISION. - 9 DISPLAY ' 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 319' ->> Error: Unexpected indicator: `G' - -run_extensions.at-5231-fit.cob:8.6-8.7: - 5 PROGRAM-ID. fit. - 6 DATA DIVISION. - 7 WORKING-STORAGE SECTION. - 8 > PROCEDURE DIVISION. ----- ^ - 9 DISPLAY ' 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 319' - 10 \D DISPLAY ' 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 319' ->> Error: Unexpected indicator: `U' - -run_extensions.at-5231-fit.cob:11.6-11.7: - 8 PROCEDURE DIVISION. - 9 DISPLAY ' 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 319' - 10 \D DISPLAY ' 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 319' - 11 > \D END-DISPLAY. ----- ^ - 12 DISPLAY ' 20 30 40 50 60 70 80 90 100 110 120 130 - 13 - ' 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 319' ->> Error: Unexpected indicator: `E' - -run_extensions.at-5231-fit.cob:14.6-14.7: - 11 \D END-DISPLAY. - 12 DISPLAY ' 20 30 40 50 60 70 80 90 100 110 120 130 - 13 - ' 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 319' - 14 > STOP RUN. ----- ^ ->> Error: Unexpected indicator: `S' - -run_extensions.at-5231-fit.cob:13.14-13.72: - 10 \D DISPLAY ' 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 319' - 11 \D END-DISPLAY. - 12 DISPLAY ' 20 30 40 50 60 70 80 90 100 110 120 130 - 13 > - ' 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 319' ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 14 STOP RUN. ->> Error: Missing continuation of ` 140 150 160 170 180 ' - -run_extensions.at-5231-fit.cob:2.7-2.8: - 1 - 2 > * Sample program in ACU terminal format, and with longer lines and truncated literals. ----- ^ - 3 - 4 IDENTIFICATION DIVISION. ->> Error: Invalid syntax - Considering: import/gnucobol/tests/testsuite.src/run_extensions.at:5188:0 -run_extensions.at-5188-prog.cob:2.6-2.7: - 1 - 2 > * Sample program in ACU terminal format. ----- ^ - 3 - 4 IDENTIFICATION DIVISION. ->> Error: Unexpected indicator: `l' - -run_extensions.at-5188-prog.cob:4.6-4.7: - 1 - 2 * Sample program in ACU terminal format. - 3 - 4 > IDENTIFICATION DIVISION. ----- ^ - 5 PROGRAM-ID. prog. - 6 AUTHOR. ->> Error: Unexpected indicator: `F' - -run_extensions.at-5188-prog.cob:5.6-5.7: - 2 * Sample program in ACU terminal format. - 3 - 4 IDENTIFICATION DIVISION. - 5 > PROGRAM-ID. prog. ----- ^ - 6 AUTHOR. - 7 Somebody. ->> Error: Unexpected indicator: `M' - -run_extensions.at-5188-prog.cob:6.6-6.7: +run_extensions.at-5188-prog.cob:6.0-9.20: 3 4 IDENTIFICATION DIVISION. 5 PROGRAM-ID. prog. 6 > AUTHOR. ----- ^ - 7 Somebody. - 8 \D Somebody else. ->> Error: Unexpected indicator: `.' - -run_extensions.at-5188-prog.cob:7.6-7.7: - 4 IDENTIFICATION DIVISION. - 5 PROGRAM-ID. prog. - 6 AUTHOR. +---- ^^^^^^^ 7 > Somebody. ----- ^ - 8 \D Somebody else. - 9 One last author. ->> Error: Unexpected indicator: `m' - -run_extensions.at-5188-prog.cob:8.6-8.7: - 5 PROGRAM-ID. prog. - 6 AUTHOR. - 7 Somebody. +---- ^^^^^^^^^^^^^^ 8 > \D Somebody else. ----- ^ - 9 One last author. - 10 DATA DIVISION. ->> Error: Unexpected indicator: `S' - -run_extensions.at-5188-prog.cob:9.6-9.7: - 6 AUTHOR. - 7 Somebody. - 8 \D Somebody else. +---- ^^^^^^^^^^^^^^^^^^^^^ 9 > One last author. ----- ^ +---- ^^^^^^^^^^^^^^^^^^^^^ 10 DATA DIVISION. 11 WORKING-STORAGE SECTION. ->> Error: Unexpected indicator: `e' - -run_extensions.at-5188-prog.cob:11.6-11.7: - 8 \D Somebody else. - 9 One last author. - 10 DATA DIVISION. - 11 > WORKING-STORAGE SECTION. ----- ^ - 12 PROCEDURE DIVISION. - 13 DISPLAY "OK" NO ADVANCING ->> Error: Unexpected indicator: `G' - -run_extensions.at-5188-prog.cob:9.13-10.26: - 6 AUTHOR. - 7 Somebody. - 8 \D Somebody else. - 9 > One last author. ----- ^^^^^^^ - 10 > DATA DIVISION. ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 11 WORKING-STORAGE SECTION. - 12 PROCEDURE DIVISION. >> Warning: comment paragraph in IDENTIFICATION DIVISION is obsolete in default -run_extensions.at-5188-prog.cob:12.6-12.7: - 9 One last author. - 10 DATA DIVISION. - 11 WORKING-STORAGE SECTION. - 12 > PROCEDURE DIVISION. ----- ^ - 13 DISPLAY "OK" NO ADVANCING - 14 END-DISPLAY. ->> Error: Unexpected indicator: `U' - -run_extensions.at-5188-prog.cob:14.6-14.7: - 11 WORKING-STORAGE SECTION. - 12 PROCEDURE DIVISION. - 13 DISPLAY "OK" NO ADVANCING - 14 > END-DISPLAY. ----- ^ - 15 \D DISPLAY "KO" NO ADVANCING - 16 \D END-DISPLAY. ->> Error: Unexpected indicator: `E' - -run_extensions.at-5188-prog.cob:16.6-16.7: - 13 DISPLAY "OK" NO ADVANCING - 14 END-DISPLAY. - 15 \D DISPLAY "KO" NO ADVANCING - 16 > \D END-DISPLAY. ----- ^ - 17 STOP RUN. ->> Error: Unexpected indicator: `E' - -run_extensions.at-5188-prog.cob:17.6-17.7: - 14 END-DISPLAY. - 15 \D DISPLAY "KO" NO ADVANCING - 16 \D END-DISPLAY. - 17 > STOP RUN. ----- ^ ->> Error: Unexpected indicator: `S' - -run_extensions.at-5188-prog.cob:2.7-2.8: - 1 - 2 > * Sample program in ACU terminal format. ----- ^ - 3 - 4 IDENTIFICATION DIVISION. ->> Error: Invalid syntax - Considering: import/gnucobol/tests/testsuite.src/run_extensions.at:5266:0 Considering: import/gnucobol/tests/testsuite.src/run_extensions.at:5290:0 Considering: import/gnucobol/tests/testsuite.src/run_extensions.at:5315:0 diff --git a/test/output-tests/syn_misc.expected b/test/output-tests/syn_misc.expected index 6f8ee16e4..cd6d515b1 100644 --- a/test/output-tests/syn_misc.expected +++ b/test/output-tests/syn_misc.expected @@ -4613,5 +4613,7 @@ syn_misc.at-8199-prog.cob:7.7-7.16: Considering: import/gnucobol/tests/testsuite.src/syn_misc.at:8235:0 Considering: import/gnucobol/tests/testsuite.src/syn_misc.at:8284:0 Considering: import/gnucobol/tests/testsuite.src/syn_misc.at:8286:0 +>> Warning: Source format `auto` is not supported yet, using `fixed` + Considering: import/gnucobol/tests/testsuite.src/syn_misc.at:8283:0 Considering: import/gnucobol/tests/testsuite.src/syn_misc.at:8340:0