Skip to content

Commit

Permalink
Introduce extent to ClangToken
Browse files Browse the repository at this point in the history
  • Loading branch information
kulp authored and emilio committed Jun 20, 2020
1 parent 2ba27bf commit c462892
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,13 +793,16 @@ impl<'a> Drop for RawTokens<'a> {
}
}

/// A raw clang token, that exposes only the kind and spelling. This is a
/// A raw clang token, that exposes only kind, spelling, and extent. This is a
/// slightly more convenient version of `CXToken` which owns the spelling
/// string.
/// string and extent.
#[derive(Debug)]
pub struct ClangToken {
spelling: CXString,
/// The kind of token, this is the same as the relevant member from
/// The extent of the token. This is the same as the relevant member from
/// `CXToken`.
pub extent: CXSourceRange,
/// The kind of the token. This is the same as the relevant member from
/// `CXToken`.
pub kind: CXTokenKind,
}
Expand Down Expand Up @@ -834,7 +837,12 @@ impl<'a> Iterator for ClangTokenIterator<'a> {
unsafe {
let kind = clang_getTokenKind(*raw);
let spelling = clang_getTokenSpelling(self.tu, *raw);
Some(ClangToken { kind, spelling })
let extent = clang_getTokenExtent(self.tu, *raw);
Some(ClangToken {
kind,
extent,
spelling,
})
}
}
}
Expand Down

0 comments on commit c462892

Please sign in to comment.