diff --git a/lib/lexer_mdx.mll b/lib/lexer_mdx.mll index 3de044c34..383bd20b7 100644 --- a/lib/lexer_mdx.mll +++ b/lib/lexer_mdx.mll @@ -20,17 +20,21 @@ let labels l = failwith msg } -let eol = '\n' | eof -let ws = ' ' | '\t' +let eol = '\n' | '\r' '\n' | eof +let ws = [' ' '\t'] + +let until_eol = [^'\n' '\r'] +let until_ws = [^' ' '\t'] +let until_ws_or_eol = [^' ' '\t' '\n' '\r'] rule text section = parse | eof { [] } - | ("#"+ as n) " " ([^'\n']* as str) eol + | ("#"+ as n) " " (until_eol* as str) eol { let section = (String.length n, str) in newline lexbuf; `Section section :: text (Some section) lexbuf } - | ( "" ws* eol? )? - "```" ([^' ' '\n']* as h) ws* ([^'\n']* as legacy_labels) eol + | ( "" ws* eol? )? + "```" (until_ws_or_eol* as h) ws* (until_eol* as legacy_labels) eol { let header = Block.Header.of_string h in let contents = block lexbuf in let labels, legacy_labels = @@ -69,24 +73,24 @@ rule text section = parse List.iter (fun _ -> newline lexbuf) errors; newline lexbuf); `Block block :: text section lexbuf } - | ([^'\n']* as str) eol + | (until_eol* as str) eol { newline lexbuf; `Text str :: text section lexbuf } and block = parse | eof | "```" ws* eol { [] } - | ([^'\n'] * as str) eol { str :: block lexbuf } + | (until_eol* as str) eol { str :: block lexbuf } and error_block = parse | "```mdx-error" ws* eol { block lexbuf } and cram_text section = parse | eof { [] } - | ("#"+ as n) " " ([^'\n']* as str) eol + | ("#"+ as n) " " (until_eol* as str) eol { let section = (String.length n, str) in newline lexbuf; `Section section :: cram_text (Some section) lexbuf } - | " " ([^'\n']* as first_line) eol + | " " (until_eol* as first_line) eol { let header = Some (Block.Header.Shell `Sh) in let requires_empty_line, contents = cram_block lexbuf in let contents = first_line :: contents in @@ -107,7 +111,7 @@ and cram_text section = parse in `Block block :: (if requires_empty_line then `Text "" :: rest else rest) } - | "<-- non-deterministic" ws* ([^'\n']* as choice) eol + | "<-- non-deterministic" ws* (until_eol* as choice) eol { let header = Some (Block.Header.Shell `Sh) in let requires_empty_line, contents = cram_block lexbuf in let labels = @@ -132,14 +136,14 @@ and cram_text section = parse in `Block block :: (if requires_empty_line then `Text "" :: rest else rest) } - | ([^'\n']* as str) eol + | (until_eol* as str) eol { newline lexbuf; `Text str :: cram_text section lexbuf } and cram_block = parse | eof { false, [] } | eol { newline lexbuf; true, [] } - | " " ([^'\n'] * as str) eol + | " " (until_eol* as str) eol { let requires_empty_line, lst = cram_block lexbuf in requires_empty_line, str :: lst }