Skip to content

Commit 29b5666

Browse files
committed
Remove cobol_parser/cobol_parser.ml
1 parent 0458349 commit 29b5666

File tree

21 files changed

+92
-106
lines changed

21 files changed

+92
-106
lines changed

.drom

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lsp/cobol_lsp/document.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module TYPES = struct
3434
and rewinder =
3535
(Cobol_ptree.Types.compilation_group option,
3636
Cobol_common.Behaviors.eidetic) Cobol_parser.Outputs.output
37-
Cobol_parser.rewinder
37+
Cobol_parser.Main.rewinder
3838

3939
(** Raised by {!val:Document.checked}. *)
4040
exception Unparseable of Lsp.Types.DocumentUri.t
@@ -66,7 +66,7 @@ type t = document
6666
let uri { textdoc; _ } = Lsp.Text_document.documentUri textdoc
6767

6868
let rewindable_parse ({ project; textdoc; _ } as doc) =
69-
Cobol_parser.rewindable_parse_with_artifacts
69+
Cobol_parser.Main.rewindable_parse_with_artifacts
7070
~options:Cobol_parser.Options.{
7171
default with
7272
recovery = EnableRecovery { silence_benign_recoveries = true };
@@ -95,7 +95,7 @@ let check doc ptree =
9595
Cobol_typeck.Engine.compilation_group ~config ptree |>
9696
Cobol_typeck.Engine.translate_diagnostics ~config |>
9797
DIAGS.map_result ~f:begin fun checked ->
98-
Cobol_parser.artifacts ptree, Some rewinder, Some checked
98+
Cobol_parser.Main.artifacts ptree, Some rewinder, Some checked
9999
end
100100
end ptree
101101
in
@@ -115,7 +115,7 @@ let reparse_and_analyze ?position ({ copybook; rewinder; textdoc; _ } as doc) =
115115
{ doc with artifacts = no_artifacts; rewinder = None; checked = None }
116116
| Some position, Some rewinder ->
117117
check doc @@
118-
Cobol_parser.rewind_and_parse rewinder ~position @@
118+
Cobol_parser.Main.rewind_and_parse rewinder ~position @@
119119
Cobol_preproc.Preprocess.reset_preprocessor_for_string @@
120120
Lsp.Text_document.text textdoc
121121

@@ -156,7 +156,7 @@ let first_change_pos changes =
156156
acc
157157
end Int.(max_int, max_int) changes (* can |changes|=0 really happen? *)
158158
in
159-
Cobol_parser.Indexed { line; char }
159+
Cobol_parser.Main.Indexed { line; char }
160160

161161
let update ({ textdoc; _ } as doc) changes =
162162
let position = first_change_pos changes in

src/lsp/cobol_lsp/lsp_semtoks.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
open Cobol_common.Srcloc.TYPES
1515
open Cobol_common (* Srcloc, Visitor *)
1616
open Cobol_common.Srcloc.INFIX
17-
open Cobol_parser.Tokens
17+
open Cobol_parser.Grammar_tokens
1818

1919
module TOKTYP = struct
2020
type t = { index: int; name: string }

src/lsp/cobol_parser/cobol_parser.ml

Lines changed: 0 additions & 66 deletions
This file was deleted.

src/lsp/cobol_parser/dune

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lsp/cobol_parser/parser_engine.ml renamed to src/lsp/cobol_parser/main.ml

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ module DIAGS = Cobol_common.Diagnostics
1515

1616
open Cobol_common.Diagnostics.TYPES
1717
open Cobol_common.Srcloc.INFIX
18-
open Parser_options (* import types for options *)
19-
open Parser_outputs (* import types for outputs *)
18+
open Options (* import types for options *)
19+
open Outputs (* import types for outputs *)
2020

2121
module Tokzr = Text_tokenizer
2222
module Overlay_manager = Grammar_utils.Overlay_manager
@@ -94,12 +94,12 @@ and 'm persist =
9494

9595
(** Initializes a parser state, given a preprocessor. *)
9696
let make_parser
97-
(type m) Parser_options.{ verbose; show; recovery; config }
97+
(type m) Options.{ verbose; show; recovery; config }
9898
?show_if_verbose ~(tokenizer_memory: m memory) pp =
9999
let tokzr: m Tokzr.state =
100100
let memory: m Tokzr.memory = match tokenizer_memory with
101-
| Parser_options.Amnesic -> Tokzr.amnesic
102-
| Parser_options.Eidetic -> Tokzr.eidetic
101+
| Options.Amnesic -> Tokzr.amnesic
102+
| Options.Eidetic -> Tokzr.eidetic
103103
in
104104
let module Config = (val config) in
105105
Tokzr.init ~verbose ?show_if_verbose ~memory Config.words
@@ -580,7 +580,7 @@ let rewindable_parse
580580
let parse
581581
(type m)
582582
~(memory: m memory)
583-
?(options = Parser_options.default)
583+
?(options = Options.default)
584584
: Cobol_preproc.Preprocess.t ->
585585
(Cobol_ptree.Types.compilation_group option, m) output with_diags =
586586
parse_once ~options ~memory
@@ -592,7 +592,7 @@ let parse_with_artifacts = parse ~memory:Eidetic
592592
let rewindable_parse
593593
(type m)
594594
~(memory: m memory)
595-
?(options = Parser_options.default)
595+
?(options = Options.default)
596596
: Cobol_preproc.Preprocess.t ->
597597
(((Cobol_ptree.Types.compilation_group option, m) output as 'x) * 'x rewinder)
598598
with_diags =
@@ -608,3 +608,38 @@ let rewind_and_parse { rewind_n_parse } rewind_preproc ~position =
608608
let artifacts
609609
: (_, Cobol_common.Behaviors.eidetic) output -> _ = function
610610
| WithArtifacts (_, artifacts) -> artifacts
611+
612+
module INTERNAL = struct
613+
614+
(** {2 COBOL tokens} *)
615+
616+
module Tokens = Grammar_tokens
617+
618+
let pp_token = Text_tokenizer.pp_token
619+
let pp_tokens = Text_tokenizer.pp_tokens
620+
let pp_tokens' = Text_tokenizer.pp_tokens'
621+
622+
(** {2 COBOL grammar} *)
623+
624+
module Grammar (* : Grammar_sig.S *) = Grammar
625+
626+
(** {2 Dummy parser} *)
627+
628+
(** Parser with dummy source locations, that can be fed directly with a
629+
list of tokens *)
630+
module Dummy = struct
631+
module Tags = struct
632+
let loc = Cobol_common.Srcloc.dummy
633+
end
634+
635+
let parse_as item toks =
636+
let toks = ref toks
637+
and dummy_lexer = Lexing.from_string ~with_positions:false "" in
638+
item begin fun _ -> match !toks () with
639+
| Seq.Nil -> Grammar_tokens.EOF
640+
| Cons (x, tl) -> toks := tl; x
641+
end dummy_lexer
642+
643+
let parse_list_as parse lx = parse_as parse (List.to_seq lx)
644+
end
645+
end

src/lsp/cobol_parser/parser_engine.mli renamed to src/lsp/cobol_parser/main.mli

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
(* *)
1212
(**************************************************************************)
1313

14-
open Parser_options
15-
open Parser_outputs
14+
open Options
15+
open Outputs
1616

1717
(** Parsing functions essentially parse a stream of tokens that is produced by a
1818
given preprocessor (typically returned by
@@ -36,7 +36,7 @@ open Parser_outputs
3636

3737
(** Simple parsing functions traverse the inputs once to produce a result. *)
3838
type 'm simple_parsing
39-
= ?options:Parser_options.parser_options
39+
= ?options:Options.parser_options
4040
-> Cobol_preproc.Preprocess.t
4141
-> (Cobol_ptree.Types.compilation_group option, 'm) output
4242
Cobol_common.Diagnostics.with_diags
@@ -113,3 +113,20 @@ val rewind_and_parse
113113

114114
val artifacts
115115
: (_, Cobol_common.Behaviors.eidetic) output -> artifacts
116+
117+
module INTERNAL : sig
118+
119+
val pp_token : Text_tokenizer.token Pretty.printer
120+
val pp_tokens : Text_tokenizer.tokens Pretty.printer
121+
val pp_tokens' : ?fsep:Pretty.simple -> Text_tokenizer.tokens Pretty.printer
122+
123+
module Dummy : sig
124+
module Tags : sig
125+
val loc : Cobol_common.Srcloc.t
126+
end
127+
val parse_list_as : (('a -> Grammar.token) -> Lexing.lexbuf -> 'b) ->
128+
Grammar.token list -> 'b
129+
end
130+
131+
132+
end

src/lsp/cobol_parser/package.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ dune-trailer = """
9595
(flags --inspection --table --only-tokens))
9696
9797
(rule
98-
(targets text_keywords.ml)
98+
(targets keywords.ml)
9999
(enabled_if (<> %{profile} "release"))
100100
(deps grammar.cmly)
101101
(mode promote)

src/lsp/cobol_parser/text_lexer.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,18 @@ let __init_puncts =
8686
List.iter begin fun (punct, token) ->
8787
Hashtbl.add punct_of_token token punct;
8888
Hashtbl.add token_of_punct punct token
89-
end Text_keywords.puncts
89+
end Keywords.puncts
9090

9191
let __init_default_keywords =
9292
List.iter begin fun (kwd, token) ->
9393
Hashtbl.add keyword_of_token token kwd;
9494
(* Every default token needs to be reserved explicitly *)
9595
Hashtbl.add __token_of_keyword kwd
9696
{ token; enabled = true; reserved = false }
97-
end Text_keywords.keywords
97+
end Keywords.keywords
9898

9999
let silenced_keywords =
100-
StringSet.of_list Text_keywords.silenced_keywords
100+
StringSet.of_list Keywords.silenced_keywords
101101

102102
(* --- *)
103103

src/lsp/superbol_free_lib/command_pp.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ let cmd =
6464
in
6565
input |>
6666
Cobol_preproc.Preprocess.preprocessor ~options:preproc_options |>
67-
Cobol_parser.parse_simple ~options:common.parser_options
67+
Cobol_parser.Main.parse_simple ~options:common.parser_options
6868
in
6969
let my_text = Cobol_preproc.Src_input.from ~filename:file ~f:parse in
7070
Format.eprintf "%a@." Cobol_common.Diagnostics.Set.pp my_text.diags;

test/cobol_data/test_memory.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
(* *)
1212
(**************************************************************************)
1313

14-
open Testing_helpers.Make (Cobol_parser.INTERNAL.Dummy.Tags)
14+
open Testing_helpers.Make (Cobol_parser.Main.INTERNAL.Dummy.Tags)
1515
module NEL = Cobol_common.Basics.NEL
1616

1717
module Memory = Cobol_data.Memory

test/cobol_parsing/parser_testing.ml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@ let show_parsed_tokens ?(verbose = false) ?(with_locations = false)
3232
?source_format ?filename contents =
3333
let DIAGS.{ result = WithArtifacts (_, { tokens; _ }); _ } =
3434
preproc ?source_format ?filename contents |>
35-
Cobol_parser.parse_with_artifacts
35+
Cobol_parser.Main.parse_with_artifacts
3636
~options:Cobol_parser.Options.{
3737
default with
3838
verbose;
3939
recovery = EnableRecovery { silence_benign_recoveries = true };
4040
}
4141
in
4242
(if with_locations
43-
then Cobol_parser.INTERNAL.pp_tokens' ~fsep:"@\n"
44-
else Cobol_parser.INTERNAL.pp_tokens) Fmt.stdout (Lazy.force tokens)
43+
then Cobol_parser.Main.INTERNAL.pp_tokens' ~fsep:"@\n"
44+
else Cobol_parser.Main.INTERNAL.pp_tokens) Fmt.stdout (Lazy.force tokens)
4545

4646
let show_diagnostics ?(verbose = false) ?source_format ?filename contents =
4747
preproc ?source_format ?filename contents |>
48-
Cobol_parser.parse_simple
48+
Cobol_parser.Main.parse_simple
4949
~options:Cobol_parser.Options.{
5050
default with
5151
verbose;
@@ -154,7 +154,7 @@ let rewindable_parse
154154
verbose; libpath = []; source_format;
155155
config = Option.value config ~default:default.config;
156156
} |>
157-
Cobol_parser.rewindable_parse_simple
157+
Cobol_parser.Main.rewindable_parse_simple
158158
~options:Cobol_parser.Options.{
159159
default with
160160
verbose; recovery = DisableRecovery;
@@ -166,8 +166,8 @@ let rewindable_parse
166166
(** Note: won't show detailed source locations as the openned file is neither
167167
actually on disk nor registered via {!Srcloc.register_file_contents}. *)
168168
let rewind_n_parse ~f rewinder { line; char; _ } preproc_rewind =
169-
let DIAGS.{ result = Only ptree, rewinder; diags } =
170-
Cobol_parser.rewind_and_parse rewinder preproc_rewind
169+
let DIAGS.{ result = Cobol_parser.Outputs.Only ptree, rewinder; diags } =
170+
Cobol_parser.Main.rewind_and_parse rewinder preproc_rewind
171171
~position:(Indexed { line; char })
172172
in
173173
f ptree diags;

test/cobol_parsing/test_combined_relations_parsing.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
open Alcotest
1515

1616
open Cobol_ptree.Types
17-
open Testing_helpers.Make (Cobol_parser.INTERNAL.Dummy.Tags)
18-
open Cobol_parser.INTERNAL.Tokens
19-
open Cobol_parser.INTERNAL.Grammar
20-
open Cobol_parser.INTERNAL.Dummy
17+
open Testing_helpers.Make (Cobol_parser.Main.INTERNAL.Dummy.Tags)
18+
open Cobol_parser.Grammar_tokens
19+
open Cobol_parser.Grammar
20+
open Cobol_parser.Main.INTERNAL.Dummy
2121

2222
let condition: condition testable = testable pp_condition (=)
2323
let parse_condition = parse_list_as standalone_condition

test/cobol_typeck/typeck_testing.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module DIAGS = Cobol_common.Diagnostics
1818
let show_diagnostics ?(show_data = false) ?(verbose = false)
1919
?source_format ?filename contents =
2020
preproc ?source_format ?filename contents |>
21-
Cobol_parser.parse_simple
21+
Cobol_parser.Main.parse_simple
2222
~options:Cobol_parser.Options.{
2323
default with
2424
verbose;

test/cobol_unit/test_qualmap.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
(**************************************************************************)
1313

1414
open Cobol_unit.Qualmap
15-
open Testing_helpers.Make (Cobol_parser.INTERNAL.Dummy.Tags)
15+
open Testing_helpers.Make (Cobol_parser.Main.INTERNAL.Dummy.Tags)
1616

1717
module NEL = Cobol_common.Basics.NEL
1818

0 commit comments

Comments
 (0)