@@ -753,22 +753,29 @@ impl SourceMap {
753753 }
754754 }
755755
756- /// Given a 'Span', tries to tell if the next character is '>'
757- /// and the previous charactoer is '<' after skipping white space
758- /// return true if wrapped by '<>'
759- pub fn span_wrapped_by_angle_bracket ( & self , span : Span ) -> bool {
756+ /// Given a 'Span', tries to tell if it's wrapped by "<>" or "()"
757+ /// the algorithm searches if the next character is '>' or ')' after skipping white space
758+ /// then searches the previous charactoer to match '<' or '(' after skipping white space
759+ /// return true if wrapped by '<>' or '()'
760+ pub fn span_wrapped_by_angle_or_parentheses ( & self , span : Span ) -> bool {
760761 self . span_to_source ( span, |src, start_index, end_index| {
761762 if src. get ( start_index..end_index) . is_none ( ) {
762763 return Ok ( false ) ;
763764 }
764765 // test the right side to match '>' after skipping white space
765766 let end_src = & src[ end_index..] ;
766767 let mut i = 0 ;
768+ let mut found_right_parentheses = false ;
769+ let mut found_right_angle = false ;
767770 while let Some ( cc) = end_src. chars ( ) . nth ( i) {
768771 if cc == ' ' {
769772 i = i + 1 ;
770773 } else if cc == '>' {
771774 // found > in the right;
775+ found_right_angle = true ;
776+ break ;
777+ } else if cc == ')' {
778+ found_right_parentheses = true ;
772779 break ;
773780 } else {
774781 // failed to find '>' return false immediately
@@ -786,6 +793,16 @@ impl SourceMap {
786793 i = i - 1 ;
787794 } else if cc == '<' {
788795 // found < in the left
796+ if !found_right_angle {
797+ // skip something like "(< )>"
798+ return Ok ( false ) ;
799+ }
800+ break ;
801+ } else if cc == '(' {
802+ if !found_right_parentheses {
803+ // skip something like "<(>)"
804+ return Ok ( false ) ;
805+ }
789806 break ;
790807 } else {
791808 // failed to find '<' return false immediately
0 commit comments