···390390 true
391391 | _ -> false
392392 in
393393- let rec loop () =
393393+ let rec loop_ml () =
394394 if is_eof l then failwith "Unterminated string";
395395 let c = get_current l in
396396- if multiline then begin
397397- if c = '"' then handle_multiline_quotes l buf '"' loop
398398- else if c = '\\' then handle_multiline_basic_backslash l buf loop
396396+ if c = '"' then handle_multiline_quotes l buf '"' loop_ml
397397+ else if c = '\\' then handle_multiline_basic_backslash l buf loop_ml
398398+ else begin
399399+ if c = '\r' then begin
400400+ advance l;
401401+ if peek l = Some '\n' then (
402402+ Buffer.add_char buf '\n';
403403+ advance l)
404404+ else failwith "Bare carriage return not allowed in string"
405405+ end
406406+ else if Char.code c >= 0x80 then validate_and_add_utf8_to_buffer l buf
399407 else begin
400400- if c = '\r' then begin
401401- advance l;
402402- if peek l = Some '\n' then (
403403- Buffer.add_char buf '\n';
404404- advance l)
405405- else failwith "Bare carriage return not allowed in string"
406406- end
407407- else if Char.code c >= 0x80 then validate_and_add_utf8_to_buffer l buf
408408- else begin
409409- validate_string_char l c true;
410410- Buffer.add_char buf c;
411411- advance l
412412- end;
413413- loop ()
414414- end
408408+ validate_string_char l c true;
409409+ Buffer.add_char buf c;
410410+ advance l
411411+ end;
412412+ loop_ml ()
415413 end
414414+ in
415415+ let rec loop_sl () =
416416+ if is_eof l then failwith "Unterminated string";
417417+ let c = get_current l in
418418+ if c = '"' then advance l
419419+ else if c = '\\' then (
420420+ Buffer.add_string buf (parse_escape l);
421421+ loop_sl ())
422422+ else if c = '\n' || c = '\r' then
423423+ failwith "Newline not allowed in basic string"
416424 else begin
417417- if c = '"' then advance l
418418- else if c = '\\' then (
419419- Buffer.add_string buf (parse_escape l);
420420- loop ())
421421- else if c = '\n' || c = '\r' then
422422- failwith "Newline not allowed in basic string"
425425+ if Char.code c >= 0x80 then validate_and_add_utf8_to_buffer l buf
423426 else begin
424424- if Char.code c >= 0x80 then validate_and_add_utf8_to_buffer l buf
425425- else begin
426426- validate_string_char l c false;
427427- Buffer.add_char buf c;
428428- advance l
429429- end;
430430- loop ()
431431- end
427427+ validate_string_char l c false;
428428+ Buffer.add_char buf c;
429429+ advance l
430430+ end;
431431+ loop_sl ()
432432 end
433433 in
434434- loop ();
434434+ if multiline then loop_ml () else loop_sl ();
435435 (Buffer.contents buf, multiline)
436436437437let validate_literal_ctrl l c code ~multiline =
···462462 true
463463 | _ -> false
464464 in
465465- let rec loop () =
465465+ let rec loop_ml () =
466466 if is_eof l then failwith "Unterminated literal string";
467467 let c = get_current l in
468468- if multiline then begin
469469- if c = '\'' then handle_multiline_quotes l buf '\'' loop
468468+ if c = '\'' then handle_multiline_quotes l buf '\'' loop_ml
469469+ else begin
470470+ if c = '\r' then begin
471471+ advance l;
472472+ if peek l = Some '\n' then (
473473+ Buffer.add_char buf '\n';
474474+ advance l)
475475+ else failwith "Bare carriage return not allowed in literal string"
476476+ end
477477+ else if Char.code c >= 0x80 then validate_and_add_utf8_to_buffer l buf
470478 else begin
471471- if c = '\r' then begin
472472- advance l;
473473- if peek l = Some '\n' then (
474474- Buffer.add_char buf '\n';
475475- advance l)
476476- else failwith "Bare carriage return not allowed in literal string"
477477- end
478478- else if Char.code c >= 0x80 then validate_and_add_utf8_to_buffer l buf
479479- else begin
480480- validate_literal_ctrl l c (Char.code c) ~multiline:true;
481481- Buffer.add_char buf c;
482482- advance l
483483- end;
484484- loop ()
485485- end
479479+ validate_literal_ctrl l c (Char.code c) ~multiline:true;
480480+ Buffer.add_char buf c;
481481+ advance l
482482+ end;
483483+ loop_ml ()
486484 end
485485+ in
486486+ let rec loop_sl () =
487487+ if is_eof l then failwith "Unterminated literal string";
488488+ let c = get_current l in
489489+ if c = '\'' then advance l
490490+ else if c = '\n' || c = '\r' then
491491+ failwith "Newline not allowed in literal string"
487492 else begin
488488- if c = '\'' then advance l
489489- else if c = '\n' || c = '\r' then
490490- failwith "Newline not allowed in literal string"
493493+ let code = Char.code c in
494494+ if code >= 0x80 then validate_and_add_utf8_to_buffer l buf
491495 else begin
492492- let code = Char.code c in
493493- if code >= 0x80 then validate_and_add_utf8_to_buffer l buf
494494- else begin
495495- validate_literal_ctrl l c code ~multiline:false;
496496- Buffer.add_char buf c;
497497- advance l
498498- end;
499499- loop ()
500500- end
496496+ validate_literal_ctrl l c code ~multiline:false;
497497+ Buffer.add_char buf c;
498498+ advance l
499499+ end;
500500+ loop_sl ()
501501 end
502502 in
503503- loop ();
503503+ if multiline then loop_ml () else loop_sl ();
504504 (Buffer.contents buf, multiline)
505505506506let parse_number l =