@@ -20,17 +20,21 @@ let labels l =
20
20
failwith msg
21
21
}
22
22
23
- let eol = '\n' | eof
24
- let ws = ' ' | '\t'
23
+ let eol = '\n' | '\r' '\n' | eof
24
+ let ws = [' ' '\t' ]
25
+
26
+ let until_eol = [^ '\n' '\r' ]
27
+ let until_ws = [^ ' ' '\t' ]
28
+ let until_ws_or_eol = [^ ' ' '\t' '\n' '\r' ]
25
29
26
30
rule text section = parse
27
31
| eof { [] }
28
- | (" #" + as n) " " ([ ^ '\n' ] * as str) eol
32
+ | (" #" + as n) " " (until_eol * as str) eol
29
33
{ let section = (String. length n, str) in
30
34
newline lexbuf;
31
35
`Section section :: text (Some section ) lexbuf }
32
- | ( "<!--" ws * "$MDX" ws * ([^ ' ' '\n' ] * as label_cmt ) ws * "-->" ws * eol ? )?
33
- "```" ([^ ' ' '\n' ] * as h ) ws * ([^ '\n' ] * as legacy_labels ) eol
36
+ | ( "<!--" ws * "$MDX" ws * (until_ws * as label_cmt ) ws * "-->" ws * eol ? )?
37
+ "```" (until_ws_or_eol * as h ) ws * (until_eol * as legacy_labels ) eol
34
38
{ let header = Block.Header. of_string h in
35
39
let contents = block lexbuf in
36
40
let labels , legacy_labels =
@@ -69,24 +73,24 @@ rule text section = parse
69
73
List. iter (fun _ -> newline lexbuf ) errors ;
70
74
newline lexbuf );
71
75
`Block block :: text section lexbuf }
72
- | ([ ^ '\n' ] * as str) eol
76
+ | (until_eol * as str) eol
73
77
{ newline lexbuf;
74
78
`Text str :: text section lexbuf }
75
79
76
80
and block = parse
77
81
| eof | " ```" ws* eol { [] }
78
- | ([ ^ '\n' ] * as str) eol { str :: block lexbuf }
82
+ | (until_eol * as str) eol { str :: block lexbuf }
79
83
80
84
and error_block = parse
81
85
| " ```mdx-error" ws* eol { block lexbuf }
82
86
83
87
and cram_text section = parse
84
88
| eof { [] }
85
- | (" #" + as n) " " ([ ^ '\n' ] * as str) eol
89
+ | (" #" + as n) " " (until_eol * as str) eol
86
90
{ let section = (String. length n, str) in
87
91
newline lexbuf;
88
92
`Section section :: cram_text (Some section ) lexbuf }
89
- | " " ([ ^ '\n' ] * as first_line) eol
93
+ | " " (until_eol * as first_line) eol
90
94
{ let header = Some (Block.Header. Shell `Sh ) in
91
95
let requires_empty_line, contents = cram_block lexbuf in
92
96
let contents = first_line :: contents in
@@ -107,7 +111,7 @@ and cram_text section = parse
107
111
in
108
112
`Block block
109
113
:: (if requires_empty_line then `Text " " :: rest else rest) }
110
- | " <-- non-deterministic" ws* ([ ^ '\n' ] * as choice) eol
114
+ | " <-- non-deterministic" ws* (until_eol * as choice) eol
111
115
{ let header = Some (Block.Header. Shell `Sh ) in
112
116
let requires_empty_line, contents = cram_block lexbuf in
113
117
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