mirror of
https://github.com/RustPython/Parser.git
synced 2025-08-04 02:39:22 +00:00
Separate byteoffset ast and located ast
This commit is contained in:
parent
f47dfca4e3
commit
a14e43e03a
21 changed files with 893 additions and 562 deletions
|
@ -463,6 +463,13 @@ impl RangeBounds<TextSize> for TextRange {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Range<TextSize>> for TextRange {
|
||||
#[inline]
|
||||
fn from(r: Range<TextSize>) -> Self {
|
||||
TextRange::new(r.start, r.end)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<TextRange> for Range<T>
|
||||
where
|
||||
T: From<TextSize>,
|
||||
|
|
|
@ -63,6 +63,30 @@ impl TextSize {
|
|||
pub fn of<T: TextLen>(text: T) -> TextSize {
|
||||
text.text_len()
|
||||
}
|
||||
|
||||
/// Returns current raw `offset` as u32.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # use ruff_text_size::*;
|
||||
/// assert_eq!(TextSize::from(4).to_u32(), 4);
|
||||
/// ```
|
||||
pub fn to_u32(&self) -> u32 {
|
||||
self.raw
|
||||
}
|
||||
|
||||
/// Returns current raw `offset` as usize.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # use ruff_text_size::*;
|
||||
/// assert_eq!(TextSize::from(4).to_usize(), 4);
|
||||
/// ```
|
||||
pub fn to_usize(&self) -> usize {
|
||||
self.raw as usize
|
||||
}
|
||||
}
|
||||
|
||||
/// Methods to act like a primitive integer type, where reasonably applicable.
|
||||
|
@ -91,7 +115,7 @@ impl From<u32> for TextSize {
|
|||
impl From<TextSize> for u32 {
|
||||
#[inline]
|
||||
fn from(value: TextSize) -> Self {
|
||||
value.raw
|
||||
value.to_u32()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,7 +130,7 @@ impl TryFrom<usize> for TextSize {
|
|||
impl From<TextSize> for usize {
|
||||
#[inline]
|
||||
fn from(value: TextSize) -> Self {
|
||||
value.raw as usize
|
||||
value.to_usize()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue