Skip to content

Commit

Permalink
Merge pull request #382 from nberth/colorize-substitution-section
Browse files Browse the repository at this point in the history
Colorize the `SUBSTITUTION SECTION` of the `CONTROL DIVISION` (GCOS)
  • Loading branch information
nberth authored Dec 18, 2024
2 parents f1dc62e + ac1bb60 commit e8edfbc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/lsp/cobol_preproc/preproc_directives.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ open Text.TYPES

type compiler_directive =
| CDir_source of Src_format.any with_loc
| CDir_control_section (* SECTION in CONTROL DIVISION *)
| CDir_preproc of Compdir_tree.preproc_directive

type copy_statement =
Expand Down
13 changes: 9 additions & 4 deletions src/lsp/cobol_preproc/preproc_engine.ml
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ and apply_compiler_directive ({ reader; pplog; _ } as lp)
(match Src_reader.with_source_format sf reader with
| Ok reader -> with_reader lp reader
| Error e -> add_error lp e)
| CDir_control_section -> (* nothing to do here *)
lp
| CDir_preproc preproc_directive ->
apply_preproc_directive lp (preproc_directive &@ loc)

Expand Down Expand Up @@ -324,15 +326,18 @@ and process_preproc_phrase ({ persist = { pparser = (module Pp);
~error:(fun e -> `ReplaceDone (add_error lp e,
List.rev rev_prefix, suffix))
| Header (header, { prefix = rev_prefix; phrase; suffix }) ->
let prefix = match header with
let prefix, lp = match header with
| ControlDivision
| IdentificationDivision ->
(* keep phrases that are further syntax-checked by the parser, and
used to perform dialect-related checks there. *)
List.rev_append rev_prefix phrase
List.rev_append rev_prefix phrase, lp
| SubstitutionSection ->
(* discard this phrase, which is not checked by the parser *)
List.rev rev_prefix
(* discard this phrase, which is not checked by the parser; keep it
in pplog anyways, so as to keep its location for later use. *)
let loc = Option.get @@ Cobol_common.Srcloc.concat_locs phrase in
let section = Preproc_directives.CDir_control_section &@ loc in
List.rev rev_prefix, apply_compiler_directive lp section
in
`ReplaceDone (lp, prefix, suffix)
| ExecBlock { prefix = rev_prefix; phrase; suffix } ->
Expand Down
1 change: 1 addition & 0 deletions src/lsp/cobol_preproc/src_reader.ml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ let fold_chunks
(match with_source_format sf pl with
| Ok pl -> pl
| Error _error -> pl) (* ignore *)
| CDir_control_section
| CDir_preproc _ -> pl (* ignore *)
in
aux pl acc
Expand Down

0 comments on commit e8edfbc

Please sign in to comment.