Skip to content

Commit 862f51c

Browse files
committed
Fix end of line parsing on Windows
1 parent a518016 commit 862f51c

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

lib/lexer_mdx.mll

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,21 @@ let labels l =
2020
failwith msg
2121
}
2222

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']
2529

2630
rule text section = parse
2731
| eof { [] }
28-
| ("#"+ as n) " " ([^'\n']* as str) eol
32+
| ("#"+ as n) " " (until_eol* as str) eol
2933
{ let section = (String.length n, str) in
3034
newline lexbuf;
3135
`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
3438
{ let header = Block.Header.of_string h in
3539
let contents = block lexbuf in
3640
let labels, legacy_labels =
@@ -69,24 +73,24 @@ rule text section = parse
6973
List.iter (fun _ -> newline lexbuf) errors;
7074
newline lexbuf);
7175
`Block block :: text section lexbuf }
72-
| ([^'\n']* as str) eol
76+
| (until_eol* as str) eol
7377
{ newline lexbuf;
7478
`Text str :: text section lexbuf }
7579

7680
and block = parse
7781
| eof | "```" ws* eol { [] }
78-
| ([^'\n'] * as str) eol { str :: block lexbuf }
82+
| (until_eol* as str) eol { str :: block lexbuf }
7983

8084
and error_block = parse
8185
| "```mdx-error" ws* eol { block lexbuf }
8286

8387
and cram_text section = parse
8488
| eof { [] }
85-
| ("#"+ as n) " " ([^'\n']* as str) eol
89+
| ("#"+ as n) " " (until_eol* as str) eol
8690
{ let section = (String.length n, str) in
8791
newline lexbuf;
8892
`Section section :: cram_text (Some section) lexbuf }
89-
| " " ([^'\n']* as first_line) eol
93+
| " " (until_eol* as first_line) eol
9094
{ let header = Some (Block.Header.Shell `Sh) in
9195
let requires_empty_line, contents = cram_block lexbuf in
9296
let contents = first_line :: contents in
@@ -107,7 +111,7 @@ and cram_text section = parse
107111
in
108112
`Block block
109113
:: (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
111115
{ let header = Some (Block.Header.Shell `Sh) in
112116
let requires_empty_line, contents = cram_block lexbuf in
113117
let labels =
@@ -132,14 +136,14 @@ and cram_text section = parse
132136
in
133137
`Block block
134138
:: (if requires_empty_line then `Text "" :: rest else rest) }
135-
| ([^'\n']* as str) eol
139+
| (until_eol* as str) eol
136140
{ newline lexbuf;
137141
`Text str :: cram_text section lexbuf }
138142

139143
and cram_block = parse
140144
| eof { false, [] }
141145
| eol { newline lexbuf; true, [] }
142-
| " " ([^'\n'] * as str) eol
146+
| " " (until_eol* as str) eol
143147
{ let requires_empty_line, lst = cram_block lexbuf in
144148
requires_empty_line, str :: lst }
145149

0 commit comments

Comments
 (0)