Skip to content

Commit

Permalink
Fix buffering mistake in handling of compiler directives
Browse files Browse the repository at this point in the history
  • Loading branch information
nberth committed Oct 5, 2023
1 parent a7255d6 commit 331e007
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/lsp/cobol_preproc/preproc_engine.ml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ let rec next_chunk ({ srclex; buff; _ } as lp) =
| Error `NotCDir ->
preprocess_line { lp with srclex; buff = [] } (buff @ text)
| Ok ([], lexdir_text) ->
next_chunk @@ on_lexing_directive lp lexdir_text
next_chunk @@ on_lexing_directive { lp with srclex } lexdir_text
| Ok (text, lexdir_text) ->
let lp = { lp with srclex; buff = [] } in
preprocess_line (on_lexing_directive lp lexdir_text) (buff @ text)
Expand Down Expand Up @@ -228,7 +228,7 @@ and preprocess_line lp srctext =
be a compiler directive. *)
preprocess_line lp srctext
| Ok (`ReplaceDone (lp, text, srctext)) ->
text, with_buff lp srctext
text, with_buff lp @@ Text.strip_eof srctext
| Error (`MissingPeriod | `MissingText) ->
next_chunk (with_buff lp srctext)

Expand Down
5 changes: 3 additions & 2 deletions src/lsp/cobol_preproc/src_lexing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@ let flushed = function
(** Flush buffered lexing productions, possibly holding onto one that may be
subject to continuation on the following line.
Always flushes completely whenever a compiler-directive word has been seen.
Always flushes completely whenever a compiler-directive word has been seen,
or upon end-of-input/file.
*)
let flush ({ lex_prods; _ } as state) : _ state * text =
match lex_prods with
| h :: prods when not state.cdir_seen ->
| h :: prods when not state.cdir_seen && ~&h <> Eof ->
{ state with lex_prods = [h] }, List.rev prods
| prods ->
{ state with lex_prods = []; cdir_seen = false }, List.rev prods
Expand Down
5 changes: 5 additions & 0 deletions src/lsp/cobol_preproc/text.ml
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,8 @@ let pseudotext_of_string = pseudotext_ pseudo_string
let pseudotext_of_alphanum = pseudotext_ pseudo_alphanum
let pseudotext_of_integer = pseudotext_ pseudo_integer
let alphanum_as_pseudotext a = pseudotext_ alphanum_as_pseudo a

(** Strips any end-of-input/file item from the beginning of the given text. *)
let rec strip_eof = function
| { payload = Eof; _ } :: text -> strip_eof text
| text -> text
1 change: 1 addition & 0 deletions src/lsp/cobol_preproc/text.mli
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ val pp_alphanum: alphanum Pretty.printer

val prefix_of_literal_kind: literal_kind -> string
val char_of_quotation: quotation -> char
val strip_eof: text -> text

0 comments on commit 331e007

Please sign in to comment.