@@ -16,17 +16,21 @@ let labels l =
16
16
failwith msg
17
17
}
18
18
19
- let eol = '\n' | eof
20
- let ws = ' ' | '\t'
19
+ let eol = '\n' | '\r' '\n' | eof
20
+ let ws = [' ' '\t' ]
21
+
22
+ let until_eol = [^ '\n' '\r' ]
23
+ let until_ws = [^ ' ' '\t' ]
24
+ let until_ws_or_eol = [^ ' ' '\t' '\n' '\r' ]
21
25
22
26
rule text section = parse
23
27
| eof { [] }
24
- | (" #" + as n) " " ([ ^ '\n' ] * as str) eol
28
+ | (" #" + as n) " " (until_eol * as str) eol
25
29
{ let section = (String. length n, str) in
26
30
newline lexbuf;
27
31
`Section section :: text (Some section ) lexbuf }
28
- | ( "<!--" ws * "$MDX" ws * ([^ ' ' '\n' ] * as label_cmt ) ws * "-->" ws * eol ? )?
29
- "```" ([^ ' ' '\n' ] * as h ) ws * ([^ '\n' ] * as legacy_labels ) eol
32
+ | ( "<!--" ws * "$MDX" ws * (until_ws * as label_cmt ) ws * "-->" ws * eol ? )?
33
+ "```" (until_ws_or_eol * as h ) ws * (until_eol * as legacy_labels ) eol
30
34
{ let header = Block.Header. of_string h in
31
35
let contents = block lexbuf in
32
36
let labels , legacy_labels =
@@ -63,7 +67,7 @@ rule text section = parse
63
67
List. iter (fun _ -> newline lexbuf ) errors ;
64
68
newline lexbuf );
65
69
`Block block :: text section lexbuf }
66
- | "<!--" ws * "$MDX" ws * ([^ ' ' '\n' ] * as label_cmt ) ws * "-->" ws * eol
70
+ | "<!--" ws * "$MDX" ws * (until_ws * as label_cmt ) ws * "-->" ws * eol
67
71
{ let labels = labels label_cmt in
68
72
newline lexbuf ;
69
73
let loc = Location. curr lexbuf in
@@ -73,24 +77,24 @@ rule text section = parse
73
77
| Error (`Msg msg ) -> failwith msg
74
78
in
75
79
`Block block :: text section lexbuf }
76
- | ([ ^ '\n' ] * as str) eol
80
+ | (until_eol * as str) eol
77
81
{ newline lexbuf;
78
82
`Text str :: text section lexbuf }
79
83
80
84
and block = parse
81
85
| eof | " ```" ws* eol { [] }
82
- | ([ ^ '\n' ] * as str) eol { str :: block lexbuf }
86
+ | (until_eol * as str) eol { str :: block lexbuf }
83
87
84
88
and error_block = parse
85
89
| " ```mdx-error" ws* eol { block lexbuf }
86
90
87
91
and cram_text section = parse
88
92
| eof { [] }
89
- | (" #" + as n) " " ([ ^ '\n' ] * as str) eol
93
+ | (" #" + as n) " " (until_eol * as str) eol
90
94
{ let section = (String. length n, str) in
91
95
newline lexbuf;
92
96
`Section section :: cram_text (Some section ) lexbuf }
93
- | " " ([ ^ '\n' ] * as first_line) eol
97
+ | " " (until_eol * as first_line) eol
94
98
{ let header = Some (Block.Header. Shell `Sh ) in
95
99
let requires_empty_line, contents = cram_block lexbuf in
96
100
let contents = first_line :: contents in
@@ -109,7 +113,7 @@ and cram_text section = parse
109
113
in
110
114
`Block block
111
115
:: (if requires_empty_line then `Text " " :: rest else rest) }
112
- | " <-- non-deterministic" ws* ([ ^ '\n' ] * as choice) eol
116
+ | " <-- non-deterministic" ws* (until_eol * as choice) eol
113
117
{ let header = Some (Block.Header. Shell `Sh ) in
114
118
let requires_empty_line, contents = cram_block lexbuf in
115
119
let labels =
@@ -132,14 +136,14 @@ and cram_text section = parse
132
136
in
133
137
`Block block
134
138
:: (if requires_empty_line then `Text " " :: rest else rest) }
135
- | ([ ^ '\n' ] * as str) eol
139
+ | (until_eol * as str) eol
136
140
{ newline lexbuf;
137
141
`Text str :: cram_text section lexbuf }
138
142
139
143
and cram_block = parse
140
144
| eof { false , [] }
141
145
| eol { newline lexbuf; true , [] }
142
- | " " ([ ^ '\n' ] * as str) eol
146
+ | " " (until_eol * as str) eol
143
147
{ let requires_empty_line, lst = cram_block lexbuf in
144
148
requires_empty_line, str :: lst }
145
149
0 commit comments