Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
Co-authored-by: Nathan Rebours <nathan.p.rebours@gmail.com>
  • Loading branch information
Julow and NathanReb committed Nov 16, 2020
1 parent e656753 commit bd731f8
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions lib/lexer_mdx.mll
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ let labels l =
failwith msg
}

let eol = '\n' | '\r' '\n' | eof
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']
let not_eol = [^'\n' '\r']
let not_ws = [^' ' '\t']
let not_ws_or_eol = [^' ' '\t' '\n' '\r']

rule text section = parse
| eof { [] }
| ("#"+ as n) " " (until_eol* as str) eol
| ("#"+ as n) " " (not_eol* as str) eol
{ let section = (String.length n, str) in
newline lexbuf;
`Section section :: text (Some section) lexbuf }
| ( "<!--" ws* "$MDX" ws* (until_ws* as label_cmt) ws* "-->" ws* eol? )?
"```" (until_ws_or_eol* as h) ws* (until_eol* as legacy_labels) eol
| ( "<!--" ws* "$MDX" ws* (not_ws* as label_cmt) ws* "-->" ws* eol? )?
"```" (not_ws_or_eol* as h) ws* (not_eol* as legacy_labels) eol
{ let header = Block.Header.of_string h in
let contents = block lexbuf in
let labels, legacy_labels =
Expand Down Expand Up @@ -67,7 +67,7 @@ rule text section = parse
List.iter (fun _ -> newline lexbuf) errors;
newline lexbuf);
`Block block :: text section lexbuf }
| "<!--" ws* "$MDX" ws* (until_ws* as label_cmt) ws* "-->" ws* eol
| "<!--" ws* "$MDX" ws* (not_ws* as label_cmt) ws* "-->" ws* eol
{ let labels = labels label_cmt in
newline lexbuf;
let loc = Location.curr lexbuf in
Expand All @@ -77,24 +77,24 @@ rule text section = parse
| Error (`Msg msg) -> failwith msg
in
`Block block :: text section lexbuf }
| (until_eol* as str) eol
| (not_eol* as str) eol
{ newline lexbuf;
`Text str :: text section lexbuf }

and block = parse
| eof | "```" ws* eol { [] }
| (until_eol* as str) eol { str :: block lexbuf }
| (not_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) " " (until_eol* as str) eol
| ("#"+ as n) " " (not_eol* as str) eol
{ let section = (String.length n, str) in
newline lexbuf;
`Section section :: cram_text (Some section) lexbuf }
| " " (until_eol* as first_line) eol
| " " (not_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
Expand All @@ -113,7 +113,7 @@ and cram_text section = parse
in
`Block block
:: (if requires_empty_line then `Text "" :: rest else rest) }
| "<-- non-deterministic" ws* (until_eol* as choice) eol
| "<-- non-deterministic" ws* (not_eol* as choice) eol
{ let header = Some (Block.Header.Shell `Sh) in
let requires_empty_line, contents = cram_block lexbuf in
let labels =
Expand All @@ -136,14 +136,14 @@ and cram_text section = parse
in
`Block block
:: (if requires_empty_line then `Text "" :: rest else rest) }
| (until_eol* as str) eol
| (not_eol* as str) eol
{ newline lexbuf;
`Text str :: cram_text section lexbuf }

and cram_block = parse
| eof { false, [] }
| eol { newline lexbuf; true, [] }
| " " (until_eol* as str) eol
| " " (not_eol* as str) eol
{ let requires_empty_line, lst = cram_block lexbuf in
requires_empty_line, str :: lst }

Expand Down

0 comments on commit bd731f8

Please sign in to comment.