package / ocaml-base-compiler.4.10.0 / ocamldoc / odoc_text_lexer.mll
1 {
2 (**************************************************************************)
3 (* *)
4 (* OCaml *)
5 (* *)
6 (* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *)
7 (* *)
8 (* Copyright 2001 Institut National de Recherche en Informatique et *)
9 (* en Automatique. *)
10 (* *)
11 (* All rights reserved. This file is distributed under the terms of *)
12 (* the GNU Lesser General Public License version 2.1, with the *)
13 (* special exception on linking described in the file LICENSE. *)
14 (* *)
15 (**************************************************************************)
16
17 (** The lexer for string to build text structures. *)
18
19 open Lexing
20 open Odoc_text_parser
21
22 let line_number = ref 0
23 let char_number = ref 0
24
25 let string_buffer = Buffer.create 32
26
27 (** Reset the buffer *)
28 let reset_string_buffer () = Buffer.reset string_buffer
29
30 (** Add a character to the buffer *)
31 let add_char_string = Buffer.add_char string_buffer
32
33 (** Add a string to the buffer. *)
34 let add_string = Buffer.add_string string_buffer
35
36 let read_string () = Buffer.contents string_buffer
37
38
39 (** the variable which will contain the description string.
40 Is initialized when we encounter the start of a special comment. *)
41
42 let description = ref ""
43
44 let blank = "[ \013\009\012]"
45
46
47 let print_DEBUG s = print_string s; print_newline ()
48
49 (** this flag indicates whether we're in a string between begin_code and end_code tokens, to
50 remember the number of open '[' and handle ']' correctly. *)
51 let open_brackets = ref 0
52
53 (** this flag indicates if we're in verbatim mode or not, to handle any special expression
54 like a string when we're in verbatim mode.*)
55 let verb_mode = ref false
56
57 (** this flag indicates if we're in "target format" mode or not, to handle any special expression
58 like a string when we're in this mode.*)
59 let target_mode = ref false
60
61 (** this flag indicates if we're in shortcut list mode or not, to handle end_shortcut_list correctly.*)
62 let shortcut_list_mode = ref false
63
64 (** this flag indicates if we're in an element reference. *)
65 let ele_ref_mode = ref false
66
67 (** this flag indicates if we're in a preformatted code string. *)
68 let code_pre_mode = ref false
69
70 let init () =
71 open_brackets := 0;
72 verb_mode := false;
73 target_mode := false;
74 shortcut_list_mode := false;
75 ele_ref_mode := false ;
76 code_pre_mode := false ;
77 line_number := 0 ;
78 char_number := 0
79
80 let incr_cpts lexbuf =
81 let s = Lexing.lexeme lexbuf in
82 let l = Str.split_delim (Str.regexp_string "\n") s in
83 match List.rev l with
84 [] -> () (* should not occur *)
85 | [s2] -> (* no newline *)
86 char_number := !char_number + (String.length s2)
87 | s2 :: _ ->
88 line_number := !line_number + ((List.length l) - 1) ;
89 char_number := String.length s2
90
91 }
92
93 (** html marks, to use as alternative possible special strings *)
94
95 let html_bold = "<"('b'|'B')">"
96 let html_end_bold = "</"('b'|'B')">"
97 let html_italic = "<"('i'|'I')">"
98 let html_end_italic = "</"('i'|'I')">"
99 let html_title = "<"('h'|'H')(['0'-'9'])+">"
100 let html_end_title = "</"('h'|'H')(['0'-'9'])+">"
101 let html_list = "<"('u'|'U')('l'|'L')">"
102 let html_end_list = "</"('u'|'U')('l'|'L')">"
103 let html_enum = "<"('o'|'O')('l'|'L')">"
104 let html_end_enum = "</"('o'|'O')('l'|'L')">"
105 let html_item = "<"('l'|'L')('i'|'I')">"
106 let html_end_item = "</"('l'|'L')('i'|'I')">"
107 let html_code = "<"('c'|'C')('o'|'O')('d'|'D')('e'|'E')">"
108 let html_end_code = "</"('c'|'C')('o'|'O')('d'|'D')('e'|'E')">"
109 let html_center = "<"('c'|'C')('e'|'E')('n'|'N')('t'|'T')('e'|'E')('r'|'R')">"
110 let html_end_center = "</"('c'|'C')('e'|'E')('n'|'N')('t'|'T')('e'|'E')('r'|'R')">"
111 let html_left = "<"('l'|'L')('e'|'E')('f'|'F')('t'|'T')">"
112 let html_end_left = "</"('l'|'L')('e'|'E')('f'|'F')('t'|'T')">"
113 let html_right = "<"('r'|'R')('i'|'I')('g'|'G')('h'|'H')('t'|'T')">"
114 let html_end_right = "</"('r'|'R')('i'|'I')('g'|'G')('h'|'H')('t'|'T')">"
115
116
117 let blank = [' ' '\013' '\009' '\012']
118 let blank_nl = [' ' '\013' '\009' '\012' '\010']
119 let label = ['a'-'z']+['a'-'z' 'A'-'Z' '0'-'9' '_']*
120
121 (** special strings *)
122
123 let end = "}"
124 | html_end_bold
125 | html_end_italic
126 | html_end_title
127 | html_end_list
128 | html_end_enum
129 | html_end_item
130 | html_end_center
131 let begin_title =
132 ("{" ['0'-'9']+(":"label)? blank_nl)
133 | html_title
134
135 let begin_bold = "{b"blank_nl | html_bold
136 let begin_emp = "{e"blank_nl
137 let begin_center = "{C"blank_nl | html_center
138 let begin_left = "{L"blank_nl
139 let begin_right = "{R"blank_nl
140 let begin_italic = "{i"blank_nl | html_italic
141 let begin_list = "{ul"blank_nl? | html_list
142 let begin_enum = "{ol"blank_nl? | html_enum
143 let begin_item = "{li"blank_nl | "{- " | html_item
144 let begin_link = "{{:"
145 let begin_target = "{%"['a'-'z''A'-'Z''0'-'9''-''_']+":"blank_nl?
146 let begin_latex = "{%"blank_nl
147 let end_target = "%}"
148 let begin_code = "[" | html_code
149 let end_code = "]" | html_end_code
150 let begin_code_pre = "{["
151 let end_code_pre = "]}"
152 let begin_verb = "{v"blank_nl
153 let end_verb = blank_nl"v}"
154
155 let begin_ele_ref = "{!"blank_nl | "{!"
156 let begin_val_ref = "{!val:"blank_nl | "{!val:"
157 let begin_typ_ref = "{!type:"blank_nl | "{!type:"
158 let begin_ext_ref = "{!extension:"blank_nl | "{!extension:"
159 let begin_exc_ref = "{!exception:"blank_nl | "{!exception:"
160 let begin_mod_ref = "{!module:"blank_nl | "{!module:"
161 let begin_modt_ref = "{!modtype:"blank_nl | "{!modtype:"
162 let begin_cla_ref = "{!class:"blank_nl | "{!class:"
163 let begin_clt_ref = "{!classtype:"blank_nl | "{!classtype:"
164 let begin_att_ref = "{!attribute:"blank_nl | "{!attribute:"
165 let begin_met_ref = "{!method:"blank_nl | "{!method:"
166 let begin_sec_ref = "{!section:"blank_nl | "{!section:"
167 let begin_recf_ref = "{!recfield:"blank_nl | "{!recfield:"
168 let begin_const_ref = "{!const:"blank_nl | "{!const:"
169 let begin_mod_list_ref = "{!modules:"blank_nl | "{!modules:"
170 let index_list = "{!indexlist}"
171 let begin_custom = "{"['a'-'z''A'-'Z']['a'-'z''A'-'Z''0'-'9']*
172 let begin_superscript = "{^"blank_nl | "{^"
173 let begin_subscript = "{_"blank_nl | "{_"
174
175 let shortcut_list_item = '\n'blank*"- "
176 let shortcut_enum_item = '\n'blank*"+ "
177 let end_shortcut_list = '\n'(blank*'\n')+
178
179 rule main = parse
180 | "\\{"
181 | "\\}"
182 | "\\["
183 | "\\]"
184 {
185 incr_cpts lexbuf ;
186 let s = Lexing.lexeme lexbuf in
187 Char (String.sub s 1 1)
188 }
189
190 | end
191 {
192 print_DEBUG "end";
193 incr_cpts lexbuf ;
194 if !verb_mode || !target_mode || !code_pre_mode ||
195 (!open_brackets >= 1) then
196 Char (Lexing.lexeme lexbuf)
197 else begin
198 if !ele_ref_mode then
199 ele_ref_mode := false;
200 END
201 end
202 }
203 | begin_title
204 {
205 print_DEBUG "begin_title";
206 incr_cpts lexbuf ;
207 if !verb_mode || !target_mode || !code_pre_mode ||
208 (!open_brackets >= 1) || !ele_ref_mode then
209 Char (Lexing.lexeme lexbuf)
210 else
211 let s = Lexing.lexeme lexbuf in
212 try
213 (* check if the "{..." or html_title mark was used. *)
214 if s.[0] = '<' then
215 let (n, l) = (2, (String.length s - 3)) in
216 let s2 = String.sub s n l in
217 Title (int_of_string s2, None)
218 else
219 let (n, l) = (1, (String.length s - 2)) in
220 let s2 = String.sub s n l in
221 try
222 let i = String.index s2 ':' in
223 let s_n = String.sub s2 0 i in
224 let s_label = String.sub s2 (i+1) (l-i-1) in
225 Title (int_of_string s_n, Some s_label)
226 with
227 Not_found ->
228 Title (int_of_string s2, None)
229 with
230 _ ->
231 Title (1, None)
232 }
233 | begin_bold
234 {
235 incr_cpts lexbuf ;
236 if !verb_mode || !target_mode || !code_pre_mode ||
237 (!open_brackets >= 1) || !ele_ref_mode then
238 Char (Lexing.lexeme lexbuf)
239 else
240 BOLD
241 }
242 | begin_italic
243 {
244 incr_cpts lexbuf ;
245 if !verb_mode || !target_mode || !code_pre_mode ||
246 (!open_brackets >= 1) || !ele_ref_mode then
247 Char (Lexing.lexeme lexbuf)
248 else
249 ITALIC
250 }
251 | begin_link
252 {
253 incr_cpts lexbuf ;
254 if !verb_mode || !target_mode || !code_pre_mode ||
255 (!open_brackets >= 1) || !ele_ref_mode then
256 Char (Lexing.lexeme lexbuf)
257 else
258 LINK
259 }
260 | begin_emp
261 {
262 incr_cpts lexbuf ;
263 if !verb_mode || !target_mode || !code_pre_mode ||
264 (!open_brackets >= 1) || !ele_ref_mode then
265 Char (Lexing.lexeme lexbuf)
266 else
267 EMP
268 }
269 | begin_superscript
270 {
271 incr_cpts lexbuf ;
272 if !verb_mode || !target_mode || !code_pre_mode ||
273 (!open_brackets >= 1) || !ele_ref_mode then
274 Char (Lexing.lexeme lexbuf)
275 else
276 SUPERSCRIPT
277 }
278 | begin_subscript
279 {
280 incr_cpts lexbuf ;
281 if !verb_mode || !target_mode || !code_pre_mode ||
282 (!open_brackets >= 1) || !ele_ref_mode then
283 Char (Lexing.lexeme lexbuf)
284 else
285 SUBSCRIPT
286 }
287 | begin_center
288 {
289 incr_cpts lexbuf ;
290 if !verb_mode || !target_mode || !code_pre_mode ||
291 (!open_brackets >= 1) || !ele_ref_mode then
292 Char (Lexing.lexeme lexbuf)
293 else
294 CENTER
295 }
296 | begin_left
297 {
298 incr_cpts lexbuf ;
299 if !verb_mode || !target_mode || !code_pre_mode ||
300 (!open_brackets >= 1) || !ele_ref_mode then
301 Char (Lexing.lexeme lexbuf)
302 else
303 LEFT
304 }
305 | begin_right
306 {
307 incr_cpts lexbuf ;
308 if !verb_mode || !target_mode || !code_pre_mode
309 || (!open_brackets >= 1) || !ele_ref_mode then
310 Char (Lexing.lexeme lexbuf)
311 else
312 RIGHT
313 }
314 | begin_list
315 {
316 print_DEBUG "LIST";
317 incr_cpts lexbuf ;
318 if !verb_mode || !target_mode || !code_pre_mode ||
319 (!open_brackets >= 1) || !ele_ref_mode then
320 Char (Lexing.lexeme lexbuf)
321 else
322 LIST
323 }
324 | begin_enum
325 {
326 incr_cpts lexbuf ;
327 if !verb_mode || !target_mode || !code_pre_mode ||
328 (!open_brackets >= 1) || !ele_ref_mode then
329 Char (Lexing.lexeme lexbuf)
330 else
331 ENUM
332 }
333 | begin_item
334 {
335 print_DEBUG "ITEM";
336 incr_cpts lexbuf ;
337 if !verb_mode || !target_mode || !code_pre_mode ||
338 (!open_brackets >= 1) || !ele_ref_mode then
339 Char (Lexing.lexeme lexbuf)
340 else
341 ITEM
342 }
343 | begin_target
344 {
345 incr_cpts lexbuf ;
346 if !verb_mode || !target_mode || !code_pre_mode ||
347 (!open_brackets >= 1) || !ele_ref_mode then
348 Char (Lexing.lexeme lexbuf)
349 else
350 (
351 let s = Lexing.lexeme lexbuf in
352 let fmt =
353 let p1 = String.index s '%' in
354 let p2 = String.index s ':' in
355 String.sub s (p1 + 1) (p2 - p1 - 1)
356 in
357 target_mode := true;
358 Target fmt
359 )
360 }
361 | begin_latex
362 {
363 incr_cpts lexbuf ;
364 if !verb_mode || !target_mode || !code_pre_mode ||
365 (!open_brackets >= 1) || !ele_ref_mode then
366 Char (Lexing.lexeme lexbuf)
367 else
368 (
369 target_mode := true;
370 LATEX
371 )
372 }
373 | end_target
374 {
375 incr_cpts lexbuf ;
376 if !verb_mode || (!open_brackets >= 1) || !code_pre_mode ||
377 !ele_ref_mode then
378 Char (Lexing.lexeme lexbuf)
379 else
380 (
381 target_mode := false;
382 END_TARGET
383 )
384 }
385 | begin_code end_code
386 {
387 incr_cpts lexbuf ;
388 Char (Lexing.lexeme lexbuf)
389 }
390
391 | begin_code
392 {
393 incr_cpts lexbuf ;
394 if !verb_mode || !target_mode || !code_pre_mode || !ele_ref_mode then
395 Char (Lexing.lexeme lexbuf)
396 else
397 if !open_brackets <= 0 then
398 (
399 open_brackets := 1;
400 CODE
401 )
402 else
403 (
404 incr open_brackets;
405 Char (Lexing.lexeme lexbuf)
406 )
407 }
408 | end_code
409 {
410 incr_cpts lexbuf ;
411 if !verb_mode || !target_mode || !code_pre_mode || !ele_ref_mode then
412 Char (Lexing.lexeme lexbuf)
413 else
414 if !open_brackets > 1 then
415 (
416 decr open_brackets;
417 Char "]"
418 )
419 else
420 (
421 open_brackets := 0;
422 END_CODE
423 )
424 }
425
426 | begin_code_pre end_code_pre
427 {
428 incr_cpts lexbuf ;
429 Char (Lexing.lexeme lexbuf)
430 }
431
432 | begin_code_pre
433 {
434 incr_cpts lexbuf ;
435 if !verb_mode || !target_mode || !code_pre_mode || !ele_ref_mode then
436 Char (Lexing.lexeme lexbuf)
437 else
438 (
439 code_pre_mode := true;
440 CODE_PRE
441 )
442 }
443 | end_code_pre
444 {
445 incr_cpts lexbuf ;
446 if !verb_mode || !target_mode || !ele_ref_mode then
447 Char (Lexing.lexeme lexbuf)
448 else
449 if !open_brackets >= 1 then
450 (
451 lexbuf.Lexing.lex_curr_pos <- lexbuf.Lexing.lex_curr_pos - 1;
452 lexbuf.Lexing.lex_curr_p <-
453 { lexbuf.Lexing.lex_curr_p with
454 pos_cnum = lexbuf.Lexing.lex_curr_p.pos_cnum - 1
455 } ;
456 decr char_number ;
457 if !open_brackets > 1 then
458 (
459 decr open_brackets;
460 Char "]"
461 )
462 else
463 (
464 open_brackets := 0;
465 END_CODE
466 )
467 )
468 else
469 if !code_pre_mode then
470 (
471 code_pre_mode := false;
472 END_CODE_PRE
473 )
474 else
475 Char (Lexing.lexeme lexbuf)
476 }
477
478 | begin_ele_ref end
479 {
480 incr_cpts lexbuf ;
481 Char (Lexing.lexeme lexbuf)
482 }
483
484 | begin_ele_ref
485 {
486 incr_cpts lexbuf ;
487 if !verb_mode || !target_mode || !code_pre_mode || !open_brackets >= 1 then
488 Char (Lexing.lexeme lexbuf)
489 else
490 if not !ele_ref_mode then
491 (
492 ele_ref_mode := true;
493 ELE_REF
494 )
495 else
496 (
497 Char (Lexing.lexeme lexbuf)
498 )
499 }
500
501
502 | begin_val_ref
503 {
504 incr_cpts lexbuf ;
505 if !verb_mode || !target_mode || !code_pre_mode || !open_brackets >= 1 then
506 Char (Lexing.lexeme lexbuf)
507 else
508 if not !ele_ref_mode then
509 (
510 ele_ref_mode := true;
511 VAL_REF
512 )
513 else
514 (
515 Char (Lexing.lexeme lexbuf)
516 )
517 }
518
519 | begin_typ_ref
520 {
521 incr_cpts lexbuf ;
522 if !verb_mode || !target_mode || !code_pre_mode || !open_brackets >= 1 then
523 Char (Lexing.lexeme lexbuf)
524 else
525 if not !ele_ref_mode then
526 (
527 ele_ref_mode := true;
528 TYP_REF
529 )
530 else
531 (
532 Char (Lexing.lexeme lexbuf)
533 )
534 }
535
536 | begin_ext_ref
537 {
538 incr_cpts lexbuf ;
539 if !verb_mode || !target_mode || !code_pre_mode || !open_brackets >= 1 then
540 Char (Lexing.lexeme lexbuf)
541 else
542 if not !ele_ref_mode then
543 (
544 ele_ref_mode := true;
545 EXT_REF
546 )
547 else
548 (
549 Char (Lexing.lexeme lexbuf)
550 )
551 }
552
553 | begin_exc_ref
554 {
555 incr_cpts lexbuf ;
556 if !verb_mode || !target_mode || !code_pre_mode || !open_brackets >= 1 then
557 Char (Lexing.lexeme lexbuf)
558 else
559 if not !ele_ref_mode then
560 (
561 ele_ref_mode := true;
562 EXC_REF
563 )
564 else
565 (
566 Char (Lexing.lexeme lexbuf)
567 )
568 }
569
570 | begin_mod_ref
571 {
572 incr_cpts lexbuf ;
573 if !verb_mode || !target_mode || !code_pre_mode || !open_brackets >= 1 then
574 Char (Lexing.lexeme lexbuf)
575 else
576 if not !ele_ref_mode then
577 (
578 ele_ref_mode := true;
579 MOD_REF
580 )
581 else
582 (
583 Char (Lexing.lexeme lexbuf)
584 )
585 }
586
587 | begin_modt_ref
588 {
589 incr_cpts lexbuf ;
590 if !verb_mode || !target_mode || !code_pre_mode || !open_brackets >= 1 then
591 Char (Lexing.lexeme lexbuf)
592 else
593 if not !ele_ref_mode then
594 (
595 ele_ref_mode := true;
596 MODT_REF
597 )
598 else
599 (
600 Char (Lexing.lexeme lexbuf)
601 )
602 }
603
604 | begin_cla_ref
605 {
606 incr_cpts lexbuf ;
607 if !verb_mode || !target_mode || !code_pre_mode || !open_brackets >= 1 then
608 Char (Lexing.lexeme lexbuf)
609 else
610 if not !ele_ref_mode then
611 (
612 ele_ref_mode := true;
613 CLA_REF
614 )
615 else
616 (
617 Char (Lexing.lexeme lexbuf)
618 )
619 }
620
621 | begin_clt_ref
622 {
623 incr_cpts lexbuf ;
624 if !verb_mode || !target_mode || !code_pre_mode || !open_brackets >= 1 then
625 Char (Lexing.lexeme lexbuf)
626 else
627 if not !ele_ref_mode then
628 (
629 ele_ref_mode := true;
630 CLT_REF
631 )
632 else
633 (
634 Char (Lexing.lexeme lexbuf)
635 )
636 }
637
638 | begin_att_ref
639 {
640 incr_cpts lexbuf ;
641 if !verb_mode || !target_mode || !code_pre_mode || !open_brackets >= 1 then
642 Char (Lexing.lexeme lexbuf)
643 else
644 if not !ele_ref_mode then
645 (
646 ele_ref_mode := true;
647 ATT_REF
648 )
649 else
650 (
651 Char (Lexing.lexeme lexbuf)
652 )
653 }
654
655 | begin_met_ref
656 {
657 incr_cpts lexbuf ;
658 if !verb_mode || !target_mode || !code_pre_mode || !open_brackets >= 1 then
659 Char (Lexing.lexeme lexbuf)
660 else
661 if not !ele_ref_mode then
662 (
663 ele_ref_mode := true;
664 MET_REF
665 )
666 else
667 (
668 Char (Lexing.lexeme lexbuf)
669 )
670 }
671
672 | begin_sec_ref
673 {
674 incr_cpts lexbuf ;
675 if !verb_mode || !target_mode || !code_pre_mode || !open_brackets >= 1 then
676 Char (Lexing.lexeme lexbuf)
677 else
678 if not !ele_ref_mode then
679 (
680 ele_ref_mode := true;
681 SEC_REF
682 )
683 else
684 (
685 Char (Lexing.lexeme lexbuf)
686 )
687 }
688 | begin_recf_ref
689 {
690 incr_cpts lexbuf ;
691 if !verb_mode || !target_mode || !code_pre_mode || !open_brackets >= 1 then
692 Char (Lexing.lexeme lexbuf)
693 else
694 if not !ele_ref_mode then
695 (
696 ele_ref_mode := true;
697 RECF_REF
698 )
699 else
700 (
701 Char (Lexing.lexeme lexbuf)
702 )
703 }
704 | begin_const_ref
705 {
706 incr_cpts lexbuf ;
707 if !verb_mode || !target_mode || !code_pre_mode || !open_brackets >= 1 then
708 Char (Lexing.lexeme lexbuf)
709 else
710 if not !ele_ref_mode then
711 (
712 ele_ref_mode := true;
713 CONST_REF
714 )
715 else
716 (
717 Char (Lexing.lexeme lexbuf)
718 )
719 }
720 | begin_mod_list_ref
721 {
722 incr_cpts lexbuf ;
723 if !verb_mode || !target_mode || !code_pre_mode || !open_brackets >= 1 then
724 Char (Lexing.lexeme lexbuf)
725 else
726 if not !ele_ref_mode then
727 (
728 ele_ref_mode := true;
729 MOD_LIST_REF
730 )
731 else
732 (
733 Char (Lexing.lexeme lexbuf)
734 )
735 }
736
737 | index_list
738 {
739 incr_cpts lexbuf ;
740 if !verb_mode || !target_mode || !code_pre_mode || !open_brackets >= 1 then
741 Char (Lexing.lexeme lexbuf)
742 else
743 if not !ele_ref_mode then
744 INDEX_LIST
745 else
746 Char (Lexing.lexeme lexbuf)
747 }
748
749 | begin_verb
750 {
751 incr_cpts lexbuf ;
752 if !target_mode || (!open_brackets >= 1) || !code_pre_mode || !ele_ref_mode then
753 Char (Lexing.lexeme lexbuf)
754 else
755 (
756 verb_mode := true;
757 VERB
758 )
759 }
760 | end_verb
761 {
762 incr_cpts lexbuf ;
763 if !target_mode || (!open_brackets >= 1) || !code_pre_mode || !ele_ref_mode then
764 Char (Lexing.lexeme lexbuf)
765 else
766 (
767 verb_mode := false;
768 END_VERB
769 )
770 }
771
772 | shortcut_list_item
773 {
774 incr_cpts lexbuf ;
775 if !target_mode || (!open_brackets >= 1) || !code_pre_mode
776 || !ele_ref_mode || !verb_mode then
777 Char (Lexing.lexeme lexbuf)
778 else if !shortcut_list_mode then
779 (
780 SHORTCUT_LIST_ITEM
781 )
782 else
783 (
784 shortcut_list_mode := true;
785 BEGIN_SHORTCUT_LIST_ITEM
786 )
787 }
788
789 | shortcut_enum_item
790 {
791 incr_cpts lexbuf ;
792 if !target_mode || (!open_brackets >= 1) || !code_pre_mode
793 || !ele_ref_mode || !verb_mode then
794 Char (Lexing.lexeme lexbuf)
795 else if !shortcut_list_mode then
796 SHORTCUT_ENUM_ITEM
797 else
798 (
799 shortcut_list_mode := true;
800 BEGIN_SHORTCUT_ENUM_ITEM
801 )
802 }
803 | end_shortcut_list
804 {
805 incr_cpts lexbuf ;
806 lexbuf.Lexing.lex_curr_pos <- lexbuf.Lexing.lex_curr_pos - 1;
807 lexbuf.Lexing.lex_curr_p <-
808 { lexbuf.Lexing.lex_curr_p with
809 pos_cnum = lexbuf.Lexing.lex_curr_p.pos_cnum - 1 ;
810 } ;
811 decr line_number ;
812 if !shortcut_list_mode then
813 (
814 shortcut_list_mode := false;
815 (* go back one char to re-use the last '\n', so we can
816 restart another shortcut-list with a single blank line,
817 and not two.*)
818 END_SHORTCUT_LIST
819 )
820 else
821 if !target_mode || (!open_brackets >= 1) || !code_pre_mode || !ele_ref_mode || !verb_mode then
822 Char (Lexing.lexeme lexbuf)
823 else
824 BLANK_LINE
825 }
826
827 | eof { EOF }
828
829 | begin_custom
830 {
831 print_DEBUG "begin_custom";
832 incr_cpts lexbuf ;
833 if !verb_mode || !target_mode || !code_pre_mode ||
834 (!open_brackets >= 1) || !ele_ref_mode then
835 Char (Lexing.lexeme lexbuf)
836 else
837 let s = Lexing.lexeme lexbuf in
838 let len = String.length s in
839 (* remove this starting '{' *)
840 let tag = Odoc_misc.no_blanks (String.sub s 1 (len - 1)) in
841 CUSTOM tag
842 }
843
844 | "{"
845 {
846 incr_cpts lexbuf ;
847 if !target_mode || (!open_brackets >= 1) || !code_pre_mode || !ele_ref_mode then
848 Char (Lexing.lexeme lexbuf)
849 else
850 LBRACE
851 }
852 | '\r' { main lexbuf }
853 | _
854 {
855 incr_cpts lexbuf ;
856 Char (Lexing.lexeme lexbuf)
857 }
858