From 56cb04742f3b2f22fcbf7e77c457b690f8c63442 Mon Sep 17 00:00:00 2001 From: Mateo Date: Fri, 26 Jul 2024 16:55:30 +0200 Subject: [PATCH] feat: relax order of configuration paragraphs --- src/lsp/cobol_parser/grammar.mly | 33 ++++++++++++--- test/output-tests/run_fundamental.expected | 10 ----- test/output-tests/syn_misc.expected | 48 ---------------------- 3 files changed, 28 insertions(+), 63 deletions(-) diff --git a/src/lsp/cobol_parser/grammar.mly b/src/lsp/cobol_parser/grammar.mly index 09191906a..d0e80aeaa 100644 --- a/src/lsp/cobol_parser/grammar.mly +++ b/src/lsp/cobol_parser/grammar.mly @@ -623,13 +623,36 @@ let environment_division := (* ------------- ENVIRONMENT DIVISION / CONFIGURATION SECTION -------------- *) +let unorder2_opt [@default (None, None)] (A, B) := + | a = A; b = ro(B); { (Some a, b) } + | b = B; a = ro(A); { (a, Some b) } + | { (None, None) } + +let unorder3_opt [@default (None, None, None)](A, B, C) := + | a = A; u2 = unorder2_opt(B, C); { (Some a, fst u2, snd u2) } + | b = B; u2 = unorder2_opt(A, C); { (fst u2, Some b, snd u2) } + | c = C; u2 = unorder2_opt(A, B); { (fst u2, snd u2, Some c) } + | { (None, None, None) } + +let unorder4_opt [@default (None, None, None, None)] (A, B, C, D) := + | a = A; u3 = unorder3_opt(B, C, D); { let (b,c,d) = u3 in (Some a, b, c, d) } + | b = B; u3 = unorder3_opt(A, C, D); { let (a,c,d) = u3 in (a, Some b, c, d) } + | c = C; u3 = unorder3_opt(A, B, D); { let (a,b,d) = u3 in (a, b, Some c, d) } + | d = D; u3 = unorder3_opt(A, B, C); { let (a,b,c) = u3 in (a, b, c, Some d) } + | { (None, None, None, None) } + 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; + unordered = unorder4_opt( + loc(source_computer_paragraph), + loc(object_computer_paragraph), + loc(special_names_paragraph), + loc(repository_paragraph)); (* +COB2002 *) + { let (source_computer_paragraph, + object_computer_paragraph, + special_names_paragraph, + repository_paragraph) = unordered in + { source_computer_paragraph; object_computer_paragraph; special_names_paragraph; repository_paragraph } } diff --git a/test/output-tests/run_fundamental.expected b/test/output-tests/run_fundamental.expected index 1549e5158..33d1f9a70 100644 --- a/test/output-tests/run_fundamental.expected +++ b/test/output-tests/run_fundamental.expected @@ -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 diff --git a/test/output-tests/syn_misc.expected b/test/output-tests/syn_misc.expected index 48bfe221a..b184224df 100644 --- a/test/output-tests/syn_misc.expected +++ b/test/output-tests/syn_misc.expected @@ -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