Add a helper for extending a span to include any trailing whitespace
This commit is contained in:
parent
a439eb259d
commit
3253c021cb
7 changed files with 17 additions and 27 deletions
|
@ -654,6 +654,12 @@ impl SourceMap {
|
|||
})
|
||||
}
|
||||
|
||||
/// Extends the span to include any trailing whitespace, or returns the original
|
||||
/// span if a `SpanSnippetError` was encountered.
|
||||
pub fn span_extend_while_whitespace(&self, span: Span) -> Span {
|
||||
self.span_extend_while(span, char::is_whitespace).unwrap_or(span)
|
||||
}
|
||||
|
||||
/// Extends the given `Span` to previous character while the previous character matches the predicate
|
||||
pub fn span_extend_prev_while(
|
||||
&self,
|
||||
|
@ -1034,12 +1040,9 @@ impl SourceMap {
|
|||
/// // ^^^^^^ input
|
||||
/// ```
|
||||
pub fn mac_call_stmt_semi_span(&self, mac_call: Span) -> Option<Span> {
|
||||
let span = self.span_extend_while(mac_call, char::is_whitespace).ok()?;
|
||||
let span = span.shrink_to_hi().with_hi(BytePos(span.hi().0.checked_add(1)?));
|
||||
if self.span_to_snippet(span).as_deref() != Ok(";") {
|
||||
return None;
|
||||
}
|
||||
Some(span)
|
||||
let span = self.span_extend_while_whitespace(mac_call);
|
||||
let span = self.next_point(span);
|
||||
if self.span_to_snippet(span).as_deref() == Ok(";") { Some(span) } else { None }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue