@@ -134,25 +134,31 @@ type deferred_token =
134
134
; end_pos : Lexing .position
135
135
}
136
136
137
+ (* This queue will only ever have 0 or 1 elements in it. We use it
138
+ instead of an [option ref] for its convenient interface.
139
+ *)
137
140
let deferred_tokens : deferred_token Queue.t = Queue. create ()
138
141
139
- (* Effectively splits the current lexer production into two halves. The current
140
- call to the lexer will return the first half of the text matched by the
141
- production, and the next call to the lexer will return the second half (of
142
- length [len]) of the text matched by the production.
142
+ (* Effectively splits the text in the lexer's current "window" (defined below)
143
+ into two halves. The current call to the lexer will return the first half of
144
+ the text in the window, and the next call to the lexer will return the second
145
+ half (of length [len]) of the text in the window.
146
+
147
+ "window" refers to the text matched by a production of the lexer. It spans
148
+ from [lexer.lex_start_p] to [lexer.lex_curr_p].
143
149
144
- It accomplishes this by doing two things:
145
- - It sets the current bounds of the lexbuf to only account for the
150
+ The function accomplishes this splitting by doing two things:
151
+ - It sets the current window of the lexbuf to only account for the
146
152
first half of the text. (The first half is of length: |text|-len.)
147
- - It sets the [next_token] ref such that, the next time the lexer is
148
- called, it will return the specified [token] *and* set the bounds of
149
- the lexbuf to account for the second half of the text. (The second half
153
+ - It enqueues a token into [deferred_tokens] such that, the next time the
154
+ lexer is called, it will return the specified [token] *and* set the window
155
+ of the lexbuf to account for the second half of the text. (The second half
150
156
is of length: |text|.)
151
157
152
- This business with setting the bounds of the lexbuf is only so that error
158
+ This business with setting the window of the lexbuf is only so that error
153
159
messages point at the right place in the program text.
154
160
*)
155
- let enqueue_token_from_end_of_lexbuf (lexbuf : Lexing.lexbuf ) token ~len =
161
+ let enqueue_token_from_end_of_lexbuf_window (lexbuf : Lexing.lexbuf ) token ~len =
156
162
let suffix_end = lexbuf.lex_curr_p in
157
163
let suffix_start =
158
164
{ suffix_end with pos_cnum = suffix_end.pos_cnum - len }
@@ -192,7 +198,7 @@ let enqueue_token_from_end_of_lexbuf (lexbuf : Lexing.lexbuf) token ~len =
192
198
We accomplish this hack by setting some global mutable state upon seeing
193
199
an identifier immediately followed by a hash. When that state is set, we
194
200
will produce [HASH_SUFFIX] the next time the lexer is called. This is
195
- done in [enqueue_hash_suffix_from_end_of_lexbuf ].
201
+ done in [enqueue_hash_suffix_from_end_of_lexbuf_window ].
196
202
197
203
Note [Lexing hack for hash operators]
198
204
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -209,14 +215,14 @@ let enqueue_token_from_end_of_lexbuf (lexbuf : Lexing.lexbuf) token ~len =
209
215
the style of Note [Lexing hack for float#], where the lexer consumes [x#~#]
210
216
all at once, but produces LIDENT(x) from the current call to the lexer and
211
217
HASHOP(#~#) from the next call to the lexer. This is done in
212
- [enqueue_hashop_from_end_of_lexbuf ].
218
+ [enqueue_hashop_from_end_of_lexbuf_window ].
213
219
*)
214
220
215
- let enqueue_hash_suffix_from_end_of_lexbuf lexbuf =
216
- enqueue_token_from_end_of_lexbuf lexbuf HASH_SUFFIX ~len: 1
221
+ let enqueue_hash_suffix_from_end_of_lexbuf_window lexbuf =
222
+ enqueue_token_from_end_of_lexbuf_window lexbuf HASH_SUFFIX ~len: 1
217
223
218
- let enqueue_hashop_from_end_of_lexbuf lexbuf ~hashop =
219
- enqueue_token_from_end_of_lexbuf lexbuf (HASHOP hashop)
224
+ let enqueue_hashop_from_end_of_lexbuf_window lexbuf ~hashop =
225
+ enqueue_token_from_end_of_lexbuf_window lexbuf (HASHOP hashop)
220
226
~len: (String. length hashop)
221
227
222
228
(* Escaped chars are interpreted in strings unless they are in comments. *)
@@ -515,11 +521,11 @@ rule token = parse
515
521
*)
516
522
| (lowercase identchar * as name) ('#' symbolchar_or_hash+ as hashop)
517
523
(* See Note [Lexing hack for hash operators] *)
518
- { enqueue_hashop_from_end_of_lexbuf lexbuf ~hashop ;
524
+ { enqueue_hashop_from_end_of_lexbuf_window lexbuf ~hashop ;
519
525
lookup_keyword name }
520
526
| (lowercase identchar * as name) '#'
521
527
(* See Note [Lexing hack for float#] *)
522
- { enqueue_hash_suffix_from_end_of_lexbuf lexbuf;
528
+ { enqueue_hash_suffix_from_end_of_lexbuf_window lexbuf;
523
529
lookup_keyword name }
524
530
| lowercase identchar * as name
525
531
{ lookup_keyword name }
@@ -530,12 +536,12 @@ rule token = parse
530
536
('#' symbolchar_or_hash+ as hashop)
531
537
(* See Note [Lexing hack for hash operators] *)
532
538
{ warn_latin1 lexbuf;
533
- enqueue_hashop_from_end_of_lexbuf lexbuf ~hashop ;
539
+ enqueue_hashop_from_end_of_lexbuf_window lexbuf ~hashop ;
534
540
LIDENT name }
535
541
| (lowercase_latin1 identchar_latin1 * as name) '#'
536
542
(* See Note [Lexing hack for float#] *)
537
543
{ warn_latin1 lexbuf;
538
- enqueue_hash_suffix_from_end_of_lexbuf lexbuf;
544
+ enqueue_hash_suffix_from_end_of_lexbuf_window lexbuf;
539
545
LIDENT name }
540
546
| lowercase_latin1 identchar_latin1 * as name
541
547
{ warn_latin1 lexbuf; LIDENT name }
0 commit comments