Skip to content

Commit

Permalink
feat: relax order of paragraph in config section
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoKaios committed Jul 29, 2024
1 parent bdc4016 commit a943b9f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 68 deletions.
18 changes: 8 additions & 10 deletions src/lsp/cobol_parser/grammar.mly
Original file line number Diff line number Diff line change
Expand Up @@ -624,16 +624,14 @@ let environment_division :=
(* ------------- ENVIRONMENT DIVISION / CONFIGURATION SECTION -------------- *)

let configuration_section :=
| CONFIGURATION; SECTION; ".";
source_computer_paragraph = ro(loc(source_computer_paragraph));
object_computer_paragraph = ro(loc(object_computer_paragraph));
special_names_paragraph = ro(loc(special_names_paragraph));
repository_paragraph = ro(loc(repository_paragraph)); (* +COB2002 *)
{ { source_computer_paragraph;
object_computer_paragraph;
special_names_paragraph;
repository_paragraph } }

| CONFIGURATION; SECTION; "."; body = rl(configuration_body);
{ build_configuration_section body }

let configuration_body ==
| p = loc(source_computer_paragraph); { P_SOURCE_COMPUTER_PARAGRAPH p }
| p = loc(object_computer_paragraph); { P_OBJECT_COMPUTER_PARAGRAPH p }
| p = loc(special_names_paragraph); { P_SPECIAL_NAMES_PARAGRAPH p }
| p = loc(repository_paragraph); { P_REPOSITORY_PARAGRAPH p } (* +COB2002 *)


(* ENVIRONMENT DIVISION / CONFIGURATION SECTION / SOURCE-COMPUTER PARAGRAPH *)
Expand Down
26 changes: 26 additions & 0 deletions src/lsp/cobol_parser/grammar_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,29 @@ let build_data_division = function
{ d with screen_sections = ss :: d.screen_sections }
in
Some (rebuild_sections list empty_data_division &@ loc)

type configuration_section_paragraph =
| P_SOURCE_COMPUTER_PARAGRAPH of source_computer_paragraph with_loc
| P_OBJECT_COMPUTER_PARAGRAPH of object_computer_paragraph with_loc
| P_SPECIAL_NAMES_PARAGRAPH of special_names_paragraph with_loc
| P_REPOSITORY_PARAGRAPH of repository_paragraph with_loc

let rec build_configuration_section = function
| [] -> {
source_computer_paragraph = None;
object_computer_paragraph = None;
special_names_paragraph = None;
repository_paragraph = None;
}
| hd::tl ->
let section = build_configuration_section tl in
match hd with
| P_SOURCE_COMPUTER_PARAGRAPH p ->
{ section with source_computer_paragraph = Some p }
| P_OBJECT_COMPUTER_PARAGRAPH p ->
{ section with object_computer_paragraph = Some p }
| P_SPECIAL_NAMES_PARAGRAPH p ->
{ section with special_names_paragraph = Some p }
| P_REPOSITORY_PARAGRAPH p ->
{ section with repository_paragraph = Some p }

9 changes: 9 additions & 0 deletions src/lsp/cobol_parser/grammar_utils.mli
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,12 @@ type data_division_sentence =
(* Takes a *reversed* list of sentences. *)
val build_data_division: data_division_sentence list with_loc ->
data_division with_loc option

type configuration_section_paragraph =
| P_SOURCE_COMPUTER_PARAGRAPH of source_computer_paragraph with_loc
| P_OBJECT_COMPUTER_PARAGRAPH of object_computer_paragraph with_loc
| P_SPECIAL_NAMES_PARAGRAPH of special_names_paragraph with_loc
| P_REPOSITORY_PARAGRAPH of repository_paragraph with_loc

val build_configuration_section
: configuration_section_paragraph list -> configuration_section
10 changes: 0 additions & 10 deletions test/output-tests/run_fundamental.expected
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,6 @@ run_fundamental.at-1390-prog.cob:18.11-18.17:
20 END FUNCTION f2.
>> Warning: Invalid syntax

run_fundamental.at-1390-prog.cob:29.7-29.20:
26 REPOSITORY.
27 FUNCTION f1
28 FUNCTION f2.
29 > SPECIAL-NAMES.
---- ^^^^^^^^^^^^^
30 CURRENCY SIGN IS "Y"
31 DECIMAL-POINT IS COMMA.
>> Error: Invalid syntax

run_fundamental.at-1390-prog.cob:45.19-45.20:
42 77 curr PIC 9.9999,99Y.
43
Expand Down
48 changes: 0 additions & 48 deletions test/output-tests/syn_misc.expected
Original file line number Diff line number Diff line change
Expand Up @@ -1494,55 +1494,7 @@ syn_misc.at-2876-prog.cob:6.11-6.17:
Considering: import/gnucobol/tests/testsuite.src/syn_misc.at:2910:0
Considering: import/gnucobol/tests/testsuite.src/syn_misc.at:2943:0
Considering: import/gnucobol/tests/testsuite.src/syn_misc.at:2987:0
syn_misc.at-2987-prog.cob:8.7-8.22:
5 ENVIRONMENT DIVISION.
6 CONFIGURATION SECTION.
7 OBJECT-COMPUTER. a.
8 > SOURCE-COMPUTER. b.
---- ^^^^^^^^^^^^^^^
>> Error: Invalid syntax

Considering: import/gnucobol/tests/testsuite.src/syn_misc.at:3048:0
syn_misc.at-3048-prog.cob:8.7-8.22:
5 ENVIRONMENT DIVISION.
6 CONFIGURATION SECTION.
7 REPOSITORY.
8 > SOURCE-COMPUTER. b.
---- ^^^^^^^^^^^^^^^
9 OBJECT-COMPUTER. a.
10 SPECIAL-NAMES.
>> Error: Invalid syntax

syn_misc.at-3048-prog.cob:22.7-22.20:
19 SOURCE-COMPUTER. b.
20 OBJECT-COMPUTER. a.
21 REPOSITORY.
22 > SPECIAL-NAMES.
---- ^^^^^^^^^^^^^
23
24 END PROGRAM prog2.
>> Error: Invalid syntax

syn_misc.at-3048-prog.cob:32.7-32.22:
29 ENVIRONMENT DIVISION.
30 CONFIGURATION SECTION.
31 REPOSITORY.
32 > SOURCE-COMPUTER. b.
---- ^^^^^^^^^^^^^^^
33 OBJECT-COMPUTER. a.
34
>> Error: Invalid syntax

syn_misc.at-3048-prog.cob:43.7-43.20:
40 ENVIRONMENT DIVISION.
41 CONFIGURATION SECTION.
42 REPOSITORY.
43 > SPECIAL-NAMES.
---- ^^^^^^^^^^^^^
44 SOURCE-COMPUTER. b.
45 OBJECT-COMPUTER. a.
>> Error: Invalid syntax

Considering: import/gnucobol/tests/testsuite.src/syn_misc.at:3104:0
Considering: import/gnucobol/tests/testsuite.src/syn_misc.at:3107:0
Considering: import/gnucobol/tests/testsuite.src/syn_misc.at:3109:0
Expand Down

0 comments on commit a943b9f

Please sign in to comment.