@@ -27,7 +27,13 @@ let unescape_word : string -> string = fun s ->
27
27
scan_word 0 ;
28
28
Buffer. contents buffer
29
29
30
- let math_constr inline x = if inline then `Math_span x else `Math_block x
30
+ type math_kind =
31
+ Inline | Block
32
+
33
+ let math_constr kind x =
34
+ match kind with
35
+ | Inline -> `Math_span x
36
+ | Block -> `Math_block x
31
37
32
38
(* This is used for code and verbatim blocks. It can be done with a regular
33
39
expression, but the regexp gets quite ugly, so a function is easier to
@@ -322,10 +328,10 @@ rule token input = parse
322
328
{ emit input (`Begin_style `Subscript ) }
323
329
324
330
| " {math" space_char
325
- { math false (Buffer. create 1024 ) 0 (Lexing. lexeme_start lexbuf) input lexbuf }
331
+ { math Block (Buffer. create 1024 ) 0 (Lexing. lexeme_start lexbuf) input lexbuf }
326
332
327
333
| " {m" horizontal_space
328
- { math true (Buffer. create 1024 ) 0 (Lexing. lexeme_start lexbuf) input lexbuf }
334
+ { math Inline (Buffer. create 1024 ) 0 (Lexing. lexeme_start lexbuf) input lexbuf }
329
335
330
336
331
337
| " {!modules:" ([^ '}' ]* as modules) '}'
@@ -546,49 +552,46 @@ and code_span buffer nesting_level start_offset input = parse
546
552
{ Buffer. add_char buffer c;
547
553
code_span buffer nesting_level start_offset input lexbuf }
548
554
549
- and math inline buffer nesting_level start_offset input = parse
555
+ and math kind buffer nesting_level start_offset input = parse
550
556
| '}'
551
557
{ if nesting_level == 0 then
552
- emit input (math_constr inline (Buffer. contents buffer)) ~start_offset
558
+ emit input (math_constr kind (Buffer. contents buffer)) ~start_offset
553
559
else begin
554
560
Buffer. add_char buffer '}' ;
555
- math inline buffer (nesting_level - 1 ) start_offset input lexbuf
561
+ math kind buffer (nesting_level - 1 ) start_offset input lexbuf
556
562
end
557
563
}
558
564
| '{'
559
565
{ Buffer. add_char buffer '{' ;
560
- math inline buffer (nesting_level + 1 ) start_offset input lexbuf }
566
+ math kind buffer (nesting_level + 1 ) start_offset input lexbuf }
561
567
| (" \\ {" | " \\ }" ) as s
562
568
{ Buffer. add_string buffer s;
563
- math inline buffer nesting_level start_offset input lexbuf }
569
+ math kind buffer nesting_level start_offset input lexbuf }
564
570
| (newline) as s
565
571
{
566
- if inline then
567
- begin
568
- warning
569
- input
570
- (Parse_error. not_allowed
571
- ~what: (Token. describe (`Blank_line " \n " ))
572
- ~in_what: (Token. describe (math_constr inline " " )));
573
- Buffer. add_char buffer '\n' ;
574
- math inline buffer nesting_level start_offset input lexbuf
575
- end
576
- else
577
- begin
578
- Buffer. add_string buffer s;
579
- math inline buffer nesting_level start_offset input lexbuf
580
- end
572
+ match kind with
573
+ | Inline ->
574
+ warning
575
+ input
576
+ (Parse_error. not_allowed
577
+ ~what: (Token. describe (`Blank_line " \n " ))
578
+ ~in_what: (Token. describe (math_constr kind " " )));
579
+ Buffer. add_char buffer '\n' ;
580
+ math kind buffer nesting_level start_offset input lexbuf
581
+ | Block ->
582
+ Buffer. add_string buffer s;
583
+ math kind buffer nesting_level start_offset input lexbuf
581
584
}
582
585
| eof
583
586
{ warning
584
587
input
585
588
(Parse_error. not_allowed
586
589
~what: (Token. describe `End )
587
- ~in_what: (Token. describe (math_constr inline " " )));
588
- emit input (math_constr inline (Buffer. contents buffer)) ~start_offset }
590
+ ~in_what: (Token. describe (math_constr kind " " )));
591
+ emit input (math_constr kind (Buffer. contents buffer)) ~start_offset }
589
592
| _ as c
590
593
{ Buffer. add_char buffer c;
591
- math inline buffer nesting_level start_offset input lexbuf }
594
+ math kind buffer nesting_level start_offset input lexbuf }
592
595
593
596
and verbatim buffer last_false_terminator start_offset input = parse
594
597
| (space_char as c) " v}"
0 commit comments