diff --git a/src/format/opamFile.ml b/src/format/opamFile.ml index 7324a9e67a6..71b0dd356d7 100644 --- a/src/format/opamFile.ml +++ b/src/format/opamFile.ml @@ -303,7 +303,12 @@ module LinesBase = struct aux acc (i-1) in aux ([],0) (len - 1) - let escape_spaces str = + let escape_spaces = function + | "" -> + "@" + | "@" -> + "\\@" + | str -> let len = String.length str in match find_escapes str len with | [], _ -> str diff --git a/src/format/opamLineLexer.mll b/src/format/opamLineLexer.mll index 42a2d786267..2e04c0bdb54 100644 --- a/src/format/opamLineLexer.mll +++ b/src/format/opamLineLexer.mll @@ -20,14 +20,19 @@ let word = Buffer.create 57 } -let normalchar = [^' ' '\t' '\n' '\\'] +let normalchar = [^' ' '\t' '\r' '\n' '\\'] rule main = parse -| '\n' { Lexing.new_line lexbuf; NEWLINE } +| '\n' | "\r\n" + { Lexing.new_line lexbuf; NEWLINE } | [' ' '\t']+ { main lexbuf } +| ('@' normalchar*) as w '\\' + { Buffer.reset word ; Buffer.add_string word w; escaped lexbuf } +| ('@' normalchar*) as w + { if w = "@" then WORD "" else WORD w } | (normalchar* as w) '\\' { Buffer.reset word ; Buffer.add_string word w; escaped lexbuf } -| (normalchar* as w) +| (normalchar+ as w) { WORD w } | eof { EOF } @@ -42,7 +47,6 @@ and escaped = parse let main lexbuf = let rec aux lines words = match main lexbuf with - | WORD "" -> aux lines words | WORD s -> aux lines (s::words) | NEWLINE -> let lines = if words = [] then lines else List.rev words::lines in