@@ -570,28 +570,23 @@ and comment = parse
570570 }
571571 | " */"
572572 {
573- match ! comment_start_loc with
574- | [] ->
575- (* If it's part of a single line comment, we should raise an
576- * unterminated nested comment error *)
577- if ! single_line_comment then (
578- let loc = Location. curr lexbuf in
579- let start = List. hd (List. rev ! line_comment_start_loc) in
580- raise (Error (Unmatched_nested_comment loc, start))
581- )
582- else assert false
583- | [_] ->
584- if ! single_line_comment then (
585- comment_start_loc := [] ;
586- store_lexeme lexbuf;
587- comment lexbuf;
588- )
589- else (
590- comment_start_loc := [] ; Location. curr lexbuf
591- )
592- | _ :: l -> comment_start_loc := l ;
593- store_lexeme lexbuf;
594- comment lexbuf;
573+ match (! comment_start_loc, ! single_line_comment) with
574+ | ([] , false ) ->
575+ assert false
576+ | ([] , true ) ->
577+ let loc = Location. curr lexbuf in
578+ let start = List. hd (List. rev ! line_comment_start_loc) in
579+ raise (Error (Unmatched_nested_comment loc, start))
580+ | ([_ ], true ) ->
581+ comment_start_loc := [];
582+ store_lexeme lexbuf;
583+ comment lexbuf;
584+ | ([_ ], false ) ->
585+ comment_start_loc := []; Location. curr lexbuf
586+ | (_ :: l , _ ) ->
587+ comment_start_loc := l ;
588+ store_lexeme lexbuf;
589+ comment lexbuf;
595590 }
596591 | " \" "
597592 {
@@ -667,15 +662,14 @@ and comment = parse
667662 else (
668663 update_loc lexbuf None 1 false 0 ;
669664 (* check if there are any unmatched nested comments *)
670- match ! comment_start_loc with
671- | [] -> (
672- (* reset since we're done parsing a single line comment *)
673- single_line_comment := false ;
674- match ! line_comment_start_loc with
675- | [] -> assert false
676- | _ -> line_comment_start_loc := [] ; Location. curr lexbuf
677- )
678- | _ ->
665+
666+ single_line_comment := false ;
667+ match (! comment_start_loc, ! line_comment_start_loc) with
668+ | ([] , [] ) ->
669+ assert false
670+ | ([] , _ ) ->
671+ line_comment_start_loc := [] ; Location. curr lexbuf
672+ | (_ , _ ) ->
679673 let start = List. hd (List. rev ! comment_start_loc) in
680674 comment_start_loc := [] ;
681675 raise (Error (Unmatched_nested_comment start, Location. curr lexbuf))
0 commit comments