Skip to content

Commit ac1bb60

Browse files
committed
Colorize the SUBSTITUTION SECTION of the CONTROL DIVISION (GCOS)
1 parent 4249374 commit ac1bb60

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

src/lsp/cobol_preproc/preproc_directives.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ open Text.TYPES
1616

1717
type compiler_directive =
1818
| CDir_source of Src_format.any with_loc
19+
| CDir_control_section (* SECTION in CONTROL DIVISION *)
1920
| CDir_preproc of Compdir_tree.preproc_directive
2021

2122
type copy_statement =

src/lsp/cobol_preproc/preproc_engine.ml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ and apply_compiler_directive ({ reader; pplog; _ } as lp)
224224
(match Src_reader.with_source_format sf reader with
225225
| Ok reader -> with_reader lp reader
226226
| Error e -> add_error lp e)
227+
| CDir_control_section -> (* nothing to do here *)
228+
lp
227229
| CDir_preproc preproc_directive ->
228230
apply_preproc_directive lp (preproc_directive &@ loc)
229231

@@ -324,15 +326,18 @@ and process_preproc_phrase ({ persist = { pparser = (module Pp);
324326
~error:(fun e -> `ReplaceDone (add_error lp e,
325327
List.rev rev_prefix, suffix))
326328
| Header (header, { prefix = rev_prefix; phrase; suffix }) ->
327-
let prefix = match header with
329+
let prefix, lp = match header with
328330
| ControlDivision
329331
| IdentificationDivision ->
330332
(* keep phrases that are further syntax-checked by the parser, and
331333
used to perform dialect-related checks there. *)
332-
List.rev_append rev_prefix phrase
334+
List.rev_append rev_prefix phrase, lp
333335
| SubstitutionSection ->
334-
(* discard this phrase, which is not checked by the parser *)
335-
List.rev rev_prefix
336+
(* discard this phrase, which is not checked by the parser; keep it
337+
in pplog anyways, so as to keep its location for later use. *)
338+
let loc = Option.get @@ Cobol_common.Srcloc.concat_locs phrase in
339+
let section = Preproc_directives.CDir_control_section &@ loc in
340+
List.rev rev_prefix, apply_compiler_directive lp section
336341
in
337342
`ReplaceDone (lp, prefix, suffix)
338343
| ExecBlock { prefix = rev_prefix; phrase; suffix } ->

src/lsp/cobol_preproc/src_reader.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ let fold_chunks
161161
(match with_source_format sf pl with
162162
| Ok pl -> pl
163163
| Error _error -> pl) (* ignore *)
164+
| CDir_control_section
164165
| CDir_preproc _ -> pl (* ignore *)
165166
in
166167
aux pl acc

0 commit comments

Comments
 (0)