Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support more compiler directives #257

Merged
merged 7 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/lsp/cobol_preproc/compdir_grammar.mly
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@
%token NE "<>" [@keyword (* symbol *) "<>"]

%token CDIR_DEFINE [@keyword ">>DEFINE", "$DEFINE"]
nberth marked this conversation as resolved.
Show resolved Hide resolved
%token CDIR_ELIF [@keyword ">>ELIF", ">>ELSE-IF"]
%token CDIR_ELSE [@keyword ">>ELSE"]
%token CDIR_END_IF [@keyword ">>END-IF"]
%token CDIR_IF [@keyword ">>IF"]
%token CDIR_ELIF [@keyword ">>ELIF", "$ELIF", ">>ELSE-IF", "$ELSE-IF"]
nberth marked this conversation as resolved.
Show resolved Hide resolved
%token CDIR_ELSE [@keyword ">>ELSE", "$ELSE"]
%token CDIR_END [@keyword "$END"] (* Note: no `>>END` equivalent *)
%token CDIR_END_IF [@keyword ">>END-IF", "$END-IF"]
nberth marked this conversation as resolved.
Show resolved Hide resolved
%token CDIR_IF [@keyword ">>IF", "$IF"]
%token CDIR_SET [@keyword ">>SET", "$SET"]
%token CDIR_SOURCE [@keyword ">>SOURCE", "$SOURCE"]
nberth marked this conversation as resolved.
Show resolved Hide resolved

Expand Down Expand Up @@ -109,6 +110,7 @@ let compiler_directive :=
| CDIR_IF; ~ = if_directive; <Preproc>
| CDIR_ELIF; ~ = elif_directive; <Preproc>
| CDIR_ELSE; EOL; { Preproc Else }
| CDIR_END; EOL; { Preproc End }
| CDIR_END_IF; EOL; { Preproc End_if }

(* --- >>SOURCE | $ SET SOURCEFORMAT ---------------------------------------- *)
Expand Down
2 changes: 2 additions & 0 deletions src/lsp/cobol_preproc/compdir_tree.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type directive_kind =
| Define_directive
| Elif_directive
| Else_directive
| End_directive
| EndIf_directive
| If_directive
| Set_directive
Expand All @@ -39,6 +40,7 @@ and preproc_directive =
| If of boolexpr with_loc
| Elif of boolexpr with_loc
| Else
| End
| End_if

and definition =
Expand Down
1 change: 1 addition & 0 deletions src/lsp/cobol_preproc/preproc_engine.ml
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ and apply_preproc_directive ({ env; context; _ } as lp)
new_context lp @@ Preproc_logic.on_elif ~loc ~condition ~env context
| Else ->
new_context lp @@ Preproc_logic.on_else ~loc context
| End
| End_if ->
let lp = new_context lp @@ Preproc_logic.on_endif ~loc context in
if Preproc_logic.emitting lp.context && lp.rev_ignored <> []
Expand Down
3 changes: 3 additions & 0 deletions src/lsp/cobol_preproc/src_lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
| CDIR_DEFINE -> Define_directive
| CDIR_ELIF -> Elif_directive
| CDIR_ELSE -> Else_directive
| CDIR_END -> End_directive
| CDIR_END_IF -> EndIf_directive
| CDIR_IF -> If_directive
| CDIR_SET -> Set_directive
Expand Down Expand Up @@ -138,6 +139,7 @@
let else_endif_keywords =
cdtokens_subset [
CDIR_ELSE;
CDIR_END;
CDIR_END_IF;
]

Expand All @@ -146,6 +148,7 @@
| If_directive
| Elif_directive -> conditional_keywords
| Else_directive
| End_directive
| EndIf_directive -> else_endif_keywords
| Set_directive -> set_keywords
| Source_directive -> source_keywords
Expand Down
39 changes: 0 additions & 39 deletions test/output-tests/listings.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2984,45 +2984,6 @@ listings.at-2762-prog.cob:34.32-34.41:

Considering: import/gnucobol/tests/testsuite.src/listings.at:2848:0
Considering: import/gnucobol/tests/testsuite.src/listings.at:2876:0
listings.at-2876-prog2.cob:7.6-7.26:
4 DATA DIVISION.
5 WORKING-STORAGE SECTION.
6 PROCEDURE DIVISION.
7 > $IF ACTIVATE DEFINED
---- ^^^^^^^^^^^^^^^^^^^^
8 DISPLAY "NOTOK" NO ADVANCING
9 END-DISPLAY
>> Error: Invalid $IF compiler directive

listings.at-2876-prog2.cob:10.6-10.29:
7 $IF ACTIVATE DEFINED
8 DISPLAY "NOTOK" NO ADVANCING
9 END-DISPLAY
10 > $ELIF ACTIVATE2 DEFINED
---- ^^^^^^^^^^^^^^^^^^^^^^^
11 DISPLAY "OK" NO ADVANCING
12 END-DISPLAY
>> Error: Invalid $ELIF compiler directive

listings.at-2876-prog2.cob:13.6-13.11:
10 $ELIF ACTIVATE2 DEFINED
11 DISPLAY "OK" NO ADVANCING
12 END-DISPLAY
13 > $ELSE
---- ^^^^^
14 DISPLAY "NOTOK" NO ADVANCING
15 END-DISPLAY
>> Error: Invalid $ELSE compiler directive

listings.at-2876-prog2.cob:16.6-16.10:
13 $ELSE
14 DISPLAY "NOTOK" NO ADVANCING
15 END-DISPLAY
16 > $END
---- ^^^^
17 STOP RUN.
>> Error: Invalid $END compiler directive

Considering: import/gnucobol/tests/testsuite.src/listings.at:3684:0
listings.at-3684-expected.lst:1.6-1.7:
1 > GnuCOBOL V.R.P prog.cob
Expand Down
20 changes: 0 additions & 20 deletions test/output-tests/run_refmod.expected
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,6 @@ run_refmod.at-466-prog2.cob:2.6-2.21:
4 PROGRAM-ID. prog2.
>> Error: Malformed compiler directive

run_refmod.at-466-prog2.cob:15.6-15.39:
12 01 m PIC 9 VALUE 2.
13
14 PROCEDURE DIVISION.
15 > $IF TEST-ZERO-LEN-REF-MOD DEFINED
---- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16 DISPLAY y (1:n)
17 $END
>> Error: Invalid $IF compiler directive

run_refmod.at-466-prog2.cob:17.6-17.10:
14 PROCEDURE DIVISION.
15 $IF TEST-ZERO-LEN-REF-MOD DEFINED
16 DISPLAY y (1:n)
17 > $END
---- ^^^^
18 DISPLAY y (1:m)
19 GOBACK.
>> Error: Invalid $END compiler directive

Considering: import/gnucobol/tests/testsuite.src/run_refmod.at:490:0
run_refmod.at-490-prog3.cob:2.6-2.21:
1
Expand Down
150 changes: 0 additions & 150 deletions test/output-tests/syn_misc.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2434,16 +2434,6 @@ syn_misc.at-7027-prog.cob:17.7-17.22:

Considering: import/gnucobol/tests/testsuite.src/syn_misc.at:7051:0
Considering: import/gnucobol/tests/testsuite.src/syn_misc.at:7109:0
syn_misc.at-7109-prog.cob:8.6-8.19:
5 WORKING-STORAGE SECTION.
6 78 Y VALUE 'a'.
7 PROCEDURE DIVISION.
8 > $IF X DEFINED
---- ^^^^^^^^^^^^^
9 $DISPLAY X defined
10 $ELIF Y DEFINED
>> Error: Invalid $IF compiler directive

syn_misc.at-7109-prog.cob:9.6-9.24:
6 78 Y VALUE 'a'.
7 PROCEDURE DIVISION.
Expand All @@ -2454,16 +2444,6 @@ syn_misc.at-7109-prog.cob:9.6-9.24:
11 $DISPLAY X not defined, but Y via lvl 78
>> Error: Invalid $DISPLAY compiler directive

syn_misc.at-7109-prog.cob:10.6-10.21:
7 PROCEDURE DIVISION.
8 $IF X DEFINED
9 $DISPLAY X defined
10 > $ELIF Y DEFINED
---- ^^^^^^^^^^^^^^^
11 $DISPLAY X not defined, but Y via lvl 78
12 $ELSE
>> Error: Invalid $ELIF compiler directive

syn_misc.at-7109-prog.cob:11.6-11.46:
8 $IF X DEFINED
9 $DISPLAY X defined
Expand All @@ -2474,16 +2454,6 @@ syn_misc.at-7109-prog.cob:11.6-11.46:
13 $DISPLAY X not defined
>> Error: Invalid $DISPLAY compiler directive

syn_misc.at-7109-prog.cob:12.6-12.11:
9 $DISPLAY X defined
10 $ELIF Y DEFINED
11 $DISPLAY X not defined, but Y via lvl 78
12 > $ELSE
---- ^^^^^
13 $DISPLAY X not defined
14 $END
>> Error: Invalid $ELSE compiler directive

syn_misc.at-7109-prog.cob:13.6-13.28:
10 $ELIF Y DEFINED
11 $DISPLAY X not defined, but Y via lvl 78
Expand All @@ -2494,27 +2464,7 @@ syn_misc.at-7109-prog.cob:13.6-13.28:
15 CONTINUE
>> Error: Invalid $DISPLAY compiler directive

syn_misc.at-7109-prog.cob:14.6-14.10:
11 $DISPLAY X not defined, but Y via lvl 78
12 $ELSE
13 $DISPLAY X not defined
14 > $END
---- ^^^^
15 CONTINUE
16 .
>> Error: Invalid $END compiler directive

Considering: import/gnucobol/tests/testsuite.src/syn_misc.at:7160:0
syn_misc.at-7160-prog.cob:11.6-11.17:
8 78 X VALUE 2.
9 78 Z VALUE 354.
10 PROCEDURE DIVISION.
11 > $IF Y = Y2X
---- ^^^^^^^^^^^
12 $DISPLAY correct Y = Y2
13 $ELSE
>> Error: Invalid $IF compiler directive

syn_misc.at-7160-prog.cob:12.6-12.29:
9 78 Z VALUE 354.
10 PROCEDURE DIVISION.
Expand All @@ -2525,16 +2475,6 @@ syn_misc.at-7160-prog.cob:12.6-12.29:
14 $DISPLAY bad: Y should be = Y2
>> Error: Invalid $DISPLAY compiler directive

syn_misc.at-7160-prog.cob:13.6-13.11:
10 PROCEDURE DIVISION.
11 $IF Y = Y2X
12 $DISPLAY correct Y = Y2
13 > $ELSE
---- ^^^^^
14 $DISPLAY bad: Y should be = Y2
15 $END
>> Error: Invalid $ELSE compiler directive

syn_misc.at-7160-prog.cob:14.6-14.36:
11 $IF Y = Y2X
12 $DISPLAY correct Y = Y2
Expand All @@ -2545,26 +2485,6 @@ syn_misc.at-7160-prog.cob:14.6-14.36:
16 $IF Y > X
>> Error: Invalid $DISPLAY compiler directive

syn_misc.at-7160-prog.cob:15.6-15.10:
12 $DISPLAY correct Y = Y2
13 $ELSE
14 $DISPLAY bad: Y should be = Y2
15 > $END
---- ^^^^
16 $IF Y > X
17 $DISPLAY BAD - Y is not > X
>> Error: Invalid $END compiler directive

syn_misc.at-7160-prog.cob:16.6-16.15:
13 $ELSE
14 $DISPLAY bad: Y should be = Y2
15 $END
16 > $IF Y > X
---- ^^^^^^^^^
17 $DISPLAY BAD - Y is not > X
18 $ELIF Y < X
>> Error: Invalid $IF compiler directive

syn_misc.at-7160-prog.cob:17.6-17.33:
14 $DISPLAY bad: Y should be = Y2
15 $END
Expand All @@ -2575,16 +2495,6 @@ syn_misc.at-7160-prog.cob:17.6-17.33:
19 $DISPLAY correct Y < X
>> Error: Invalid $DISPLAY compiler directive

syn_misc.at-7160-prog.cob:18.6-18.17:
15 $END
16 $IF Y > X
17 $DISPLAY BAD - Y is not > X
18 > $ELIF Y < X
---- ^^^^^^^^^^^
19 $DISPLAY correct Y < X
20 $ELSE
>> Error: Invalid $ELIF compiler directive

syn_misc.at-7160-prog.cob:19.6-19.28:
16 $IF Y > X
17 $DISPLAY BAD - Y is not > X
Expand All @@ -2595,16 +2505,6 @@ syn_misc.at-7160-prog.cob:19.6-19.28:
21 $DISPLAY BROKEN
>> Error: Invalid $DISPLAY compiler directive

syn_misc.at-7160-prog.cob:20.6-20.11:
17 $DISPLAY BAD - Y is not > X
18 $ELIF Y < X
19 $DISPLAY correct Y < X
20 > $ELSE
---- ^^^^^
21 $DISPLAY BROKEN
22 $END
>> Error: Invalid $ELSE compiler directive

syn_misc.at-7160-prog.cob:21.6-21.21:
18 $ELIF Y < X
19 $DISPLAY correct Y < X
Expand All @@ -2615,26 +2515,6 @@ syn_misc.at-7160-prog.cob:21.6-21.21:
23
>> Error: Invalid $DISPLAY compiler directive

syn_misc.at-7160-prog.cob:22.6-22.10:
19 $DISPLAY correct Y < X
20 $ELSE
21 $DISPLAY BROKEN
22 > $END
---- ^^^^
23
24 $IF X > Y
>> Error: Invalid $END compiler directive

syn_misc.at-7160-prog.cob:24.6-24.15:
21 $DISPLAY BROKEN
22 $END
23
24 > $IF X > Y
---- ^^^^^^^^^
25 $DISPLAY correct X > Y
26 $ELIF X < Y
>> Error: Invalid $IF compiler directive

syn_misc.at-7160-prog.cob:25.6-25.28:
22 $END
23
Expand All @@ -2645,16 +2525,6 @@ syn_misc.at-7160-prog.cob:25.6-25.28:
27 $DISPLAY BAD - X is not < Y
>> Error: Invalid $DISPLAY compiler directive

syn_misc.at-7160-prog.cob:26.6-26.17:
23
24 $IF X > Y
25 $DISPLAY correct X > Y
26 > $ELIF X < Y
---- ^^^^^^^^^^^
27 $DISPLAY BAD - X is not < Y
28 $ELSE
>> Error: Invalid $ELIF compiler directive

syn_misc.at-7160-prog.cob:27.6-27.33:
24 $IF X > Y
25 $DISPLAY correct X > Y
Expand All @@ -2665,16 +2535,6 @@ syn_misc.at-7160-prog.cob:27.6-27.33:
29 $DISPLAY BROKEN
>> Error: Invalid $DISPLAY compiler directive

syn_misc.at-7160-prog.cob:28.6-28.11:
25 $DISPLAY correct X > Y
26 $ELIF X < Y
27 $DISPLAY BAD - X is not < Y
28 > $ELSE
---- ^^^^^
29 $DISPLAY BROKEN
30 $END
>> Error: Invalid $ELSE compiler directive

syn_misc.at-7160-prog.cob:29.6-29.21:
26 $ELIF X < Y
27 $DISPLAY BAD - X is not < Y
Expand All @@ -2685,16 +2545,6 @@ syn_misc.at-7160-prog.cob:29.6-29.21:
31 CONTINUE
>> Error: Invalid $DISPLAY compiler directive

syn_misc.at-7160-prog.cob:30.6-30.10:
27 $DISPLAY BAD - X is not < Y
28 $ELSE
29 $DISPLAY BROKEN
30 > $END
---- ^^^^
31 CONTINUE
32 .
>> Error: Invalid $END compiler directive

Considering: import/gnucobol/tests/testsuite.src/syn_misc.at:7193:0
Considering: import/gnucobol/tests/testsuite.src/syn_misc.at:7264:0
Considering: import/gnucobol/tests/testsuite.src/syn_misc.at:7417:0
Expand Down
Loading