@@ -15,107 +15,27 @@ open Cobol_common.Srcloc.TYPES
15
15
open Cobol_common.Diagnostics.TYPES
16
16
open Text.TYPES
17
17
18
+ (* * {1 Source text lexer} *)
19
+
18
20
type 'k srclexer = 'k Src_lexing .state * Lexing .lexbuf
19
21
and any_srclexer =
20
22
| Plx : 'k srclexer -> any_srclexer [@@ unboxed]
21
23
22
- (* --- Compiler Directives -------------------------------------------------- *)
23
-
24
- (* SOURCE FORMAT *)
25
-
26
- type lexing_directive =
27
- | LexDirSource :
28
- 'k Src_format .source_format with_loc -> lexing_directive [@@ unboxed]
29
-
30
- (* COPY/REPLACING *)
31
-
32
- type copy_statement =
33
- | CDirCopy of
34
- {
35
- library : library ;
36
- suppress_printing : bool ;
37
- replacing : replacing with_loc list ;
38
- }
39
- and replace_statement =
40
- | CDirReplace of
41
- {
42
- also : bool ;
43
- replacing : replacing with_loc list ;
44
- }
45
- | CDirReplaceOff of
46
- {
47
- last : bool ;
48
- }
49
- and library =
50
- {
51
- libname : fileloc with_loc ;
52
- cbkname : fileloc with_loc option ;
53
- }
54
- and fileloc = [`Word | `Alphanum ] * string
55
- and replacing
56
-
57
- type (_, _) repl_attempt =
58
- | OnPartText : ([`NoReplacement | `MissingText ],
59
- partial_text_repl_result ) repl_attempt
60
- | OnFullText : ([`NoReplacement ],
61
- text * Preproc_trace .log ) repl_attempt
62
- and partial_text_repl_result =
63
- (text * Preproc_trace .log ,
64
- [`MissingText of text * Preproc_trace .log * text ]) result
65
-
66
- module type ENTRY_POINTS = sig
67
- type 'x entry
68
- val replace_statement : replace_statement with_diags with_loc entry
69
- val lexing_directive : lexing_directive option with_diags with_loc entry
70
- val copy_statement : copy_statement with_diags with_loc entry
71
- end
72
-
73
- module type PPPARSER = sig
74
- exception Error
75
-
76
- (* The incremental API. *)
77
- module MenhirInterpreter : MenhirLib .IncrementalEngine. INCREMENTAL_ENGINE
78
- with type token = Preproc_tokens. token
79
-
80
- (* The entry point(s) to the incremental API. *)
81
- module Incremental : ENTRY_POINTS with type
82
- 'x entry := Lexing. position -> 'x MenhirInterpreter. checkpoint
83
- end
84
-
85
- type partial_replacing =
86
- {
87
- repl_dir : replacing_direction ;
88
- repl_strict : bool ;
89
- }
90
- and replacing_direction = Leading | Trailing
91
-
92
- val replacing
93
- : ?partial:partial_replacing
94
- -> pseudotext with_loc
95
- -> pseudotext with_loc
96
- -> replacing option with_diags
97
- val apply_replacing
98
- : (_, 'a) repl_attempt
99
- -> replacing with_loc list
100
- -> Preproc_trace. log
101
- -> text
102
- -> 'a
103
-
104
- (* * {3 Source format} *)
24
+ (* * {2 Source format} *)
105
25
106
26
val source_format
107
27
: any_srclexer
108
28
-> Src_format. any
109
29
val cdir_source_format
110
30
: dialect: Cobol_config. dialect
111
31
-> string with_loc
112
- -> lexing_directive option with_diags
32
+ -> Preproc_directives. lexing_directive option with_diags
113
33
val with_source_format
114
34
: 'k Src_format. source_format with_loc
115
35
-> any_srclexer
116
36
-> any_srclexer
117
37
118
- (* * {3 Instantiation} *)
38
+ (* * {2 Instantiation} *)
119
39
120
40
val srclex_from_file
121
41
: source_format: Src_format. any
@@ -132,7 +52,7 @@ val srclex_from_channel
132
52
-> in_channel
133
53
-> any_srclexer
134
54
135
- (* * {3 Resetting the input} *)
55
+ (* * {2 Resetting the input} *)
136
56
137
57
(* * Note: the functions below assume [position] corresponds to the begining of
138
58
the input.} *)
@@ -153,7 +73,7 @@ val srclex_restart_on_channel
153
73
-> any_srclexer
154
74
-> any_srclexer
155
75
156
- (* * {3 Queries} *)
76
+ (* * {2 Queries} *)
157
77
158
78
val srclex_diags
159
79
: any_srclexer
@@ -167,12 +87,46 @@ val srclex_comments
167
87
val srclex_newline_cnums
168
88
: any_srclexer
169
89
-> int list
90
+ val next_source_line
91
+ : any_srclexer
92
+ -> any_srclexer * text
93
+ val fold_source_lines
94
+ : any_srclexer
95
+ -> (text -> 'a -> 'a)
96
+ -> 'a
97
+ -> 'a
98
+ val print_source_lines
99
+ : Format. formatter
100
+ -> any_srclexer
101
+ -> unit
170
102
171
- val next_source_line : any_srclexer -> any_srclexer * text
172
- val fold_source_lines : any_srclexer -> (text -> 'a -> 'a ) -> 'a -> 'a
173
- val print_source_lines : Format .formatter -> any_srclexer -> unit
103
+ (* * {1 Compiler Directives} *)
174
104
175
- (* --- *)
105
+ val replacing
106
+ : ?partial: Preproc_directives. partial_replacing
107
+ -> pseudotext with_loc
108
+ -> pseudotext with_loc
109
+ -> Preproc_directives. replacing option with_diags
110
+
111
+ type (_, _) repl_attempt =
112
+ | OnPartText : ([`NoReplacement | `MissingText ],
113
+ partial_text_repl_result ) repl_attempt
114
+ | OnFullText : ([`NoReplacement ],
115
+ text * Preproc_trace .log ) repl_attempt
116
+ and partial_text_repl_result =
117
+ (text * Preproc_trace .log ,
118
+ [`MissingText of text * Preproc_trace .log * text ]) result
119
+ val apply_replacing
120
+ : (_, 'a) repl_attempt
121
+ -> Preproc_directives. replacing with_loc list
122
+ -> Preproc_trace. log
123
+ -> text
124
+ -> 'a
125
+
126
+ (* * {1 Preprocessor state}
127
+
128
+ This state is used to track some preprocessing-related divisions, like the
129
+ `CONTROL DIVISION` in the GCOS dialect. *)
176
130
177
131
type state
178
132
@@ -198,3 +152,27 @@ val find_preproc_phrase
198
152
-> text
199
153
-> (preproc_phrase * state,
200
154
[> `MissingPeriod | `MissingText | `NoneFound ]) result
155
+
156
+ (* * {1 Parsing statements and directives} *)
157
+
158
+ module type ENTRY_POINTS = sig
159
+ type 'x entry
160
+ val replace_statement
161
+ : Preproc_directives. replace_statement with_diags with_loc entry
162
+ val lexing_directive
163
+ : Preproc_directives. lexing_directive option with_diags with_loc entry
164
+ val copy_statement
165
+ : Preproc_directives. copy_statement with_diags with_loc entry
166
+ end
167
+
168
+ module type PPPARSER = sig
169
+ exception Error
170
+
171
+ (* The incremental API. *)
172
+ module MenhirInterpreter : MenhirLib .IncrementalEngine. INCREMENTAL_ENGINE
173
+ with type token = Preproc_tokens. token
174
+
175
+ (* The entry point(s) to the incremental API. *)
176
+ module Incremental : ENTRY_POINTS with type
177
+ 'x entry := Lexing. position -> 'x MenhirInterpreter. checkpoint
178
+ end
0 commit comments