vendor text_size and source_location (#102)

This commit is contained in:
Jeong, YunWon 2023-08-29 19:52:25 +09:00 committed by GitHub
parent b07966695a
commit d09bce80e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 175 additions and 311 deletions

View file

@ -11,12 +11,12 @@ include = ["LICENSE", "Cargo.toml", "src/**/*.rs"]
[workspace]
resolver = "2"
members = [
"ast", "core", "format", "literal", "parser",
"ast", "core", "format", "literal", "parser", "vendored",
"ast-pyo3",
"ruff_text_size", "ruff_source_location",
]
[workspace.dependencies]
rustpython-parser-vendored = { path = "vendored" }
rustpython-ast = { path = "ast", default-features = false }
rustpython-parser-core = { path = "core", features = [] }
rustpython-literal = { path = "literal" }

View file

@ -8,14 +8,12 @@ repository = "https://github.com/RustPython/Parser/"
license = "MIT"
[dependencies]
# ruff dependency shouldn't be placed out of this crate
ruff_text_size = { path = "../ruff_text_size" }
ruff_source_location = { path = "../ruff_source_location", optional = true }
# vendored dependency shouldn't be placed out of this crate
rustpython-parser-vendored.workspace = true
serde = { version = "1.0.133", optional = true, default-features = false, features = ["derive"] }
is-macro.workspace = true
memchr.workspace = true
[features]
default = []
location = ["dep:ruff_source_location"]
location = []

View file

@ -11,5 +11,6 @@ pub use error::BaseError;
pub use format::ConversionFlag;
pub use mode::Mode;
// re-export our public interface
pub use ruff_text_size as text_size;
#[cfg(feature = "location")]
pub use rustpython_parser_vendored::source_location;
pub use rustpython_parser_vendored::text_size;

View file

@ -2,7 +2,7 @@
use crate::text_size::{TextLen, TextSize};
use memchr::memrchr2;
pub use ruff_source_location::{
pub use crate::source_location::{
newlines::{find_newline, UniversalNewlineIterator},
LineIndex, OneIndexed, SourceCode, SourceLocation,
};

View file

@ -155,8 +155,15 @@ impl UnicodeEscape<'_> {
};
let Some(new_len) = length_add(out_len, incr) else {
#[cold]
fn stop(single_count: usize, double_count: usize, preferred_quote: Quote) -> EscapeLayout {
EscapeLayout { quote: choose_quote(single_count, double_count, preferred_quote).0, len: None }
fn stop(
single_count: usize,
double_count: usize,
preferred_quote: Quote,
) -> EscapeLayout {
EscapeLayout {
quote: choose_quote(single_count, double_count, preferred_quote).0,
len: None,
}
}
return stop(single_count, double_count, preferred_quote);
};
@ -332,8 +339,15 @@ impl AsciiEscape<'_> {
};
let Some(new_len) = length_add(out_len, incr) else {
#[cold]
fn stop(single_count: usize, double_count: usize, preferred_quote: Quote) -> EscapeLayout {
EscapeLayout { quote: choose_quote(single_count, double_count, preferred_quote).0, len: None }
fn stop(
single_count: usize,
double_count: usize,
preferred_quote: Quote,
) -> EscapeLayout {
EscapeLayout {
quote: choose_quote(single_count, double_count, preferred_quote).0,
len: None,
}
}
return stop(single_count, double_count, preferred_quote);
};

View file

@ -374,7 +374,9 @@ impl<'a> StringParser<'a> {
expression.push(ch);
loop {
let Some(c) = self.next_char() else {
return Err(FStringError::new(UnterminatedString, self.get_pos()).into());
return Err(
FStringError::new(UnterminatedString, self.get_pos()).into()
);
};
expression.push(c);
if c == ch {
@ -408,7 +410,7 @@ impl<'a> StringParser<'a> {
spec_constructor.push(
self.expr(
ast::ExprConstant {
value: constant_piece.drain(..).collect::<String>().into(),
value: std::mem::take(&mut constant_piece).into(),
kind: None,
range: self.range(),
}
@ -433,7 +435,7 @@ impl<'a> StringParser<'a> {
spec_constructor.push(
self.expr(
ast::ExprConstant {
value: constant_piece.drain(..).collect::<String>().into(),
value: std::mem::take(&mut constant_piece).into(),
kind: None,
range: self.range(),
}
@ -475,7 +477,7 @@ impl<'a> StringParser<'a> {
values.push(
self.expr(
ast::ExprConstant {
value: content.drain(..).collect::<String>().into(),
value: std::mem::take(&mut content).into(),
kind: None,
range: self.range(),
}

View file

@ -1,17 +0,0 @@
# NOTE: RUSTPYTHON
# This crate is not a real crate of ruff, but cut off a part of `ruff_python_ast` and vendored it to avoid cross dependency
[package]
name = "ruff_source_location"
version = "0.0.0"
publish = false
edition = { workspace = true }
rust-version = { workspace = true }
[lib]
[dependencies]
ruff_text_size = { path = "../ruff_text_size" }
memchr = { workspace = true }
once_cell = { workspace = true }

View file

@ -1,22 +0,0 @@
[package]
name = "ruff_text_size"
version = "0.0.0"
publish = false
edition = "2021"
rust-version = "1.67.1"
[dependencies]
serde = { version="1.0.152", optional = true, default_features = false }
schemars = { version = "0.8.12", optional = true }
[dev-dependencies]
serde_test = { version = "1.0.152" }
static_assertions = { version = "1.1.0" }
[features]
serde = ["dep:serde"]
[[test]]
name = "serde"
path = "tests/serde.rs"
required-features = ["serde"]

View file

@ -1,18 +0,0 @@
use {
ruff_text_size::{TextRange, TextSize},
static_assertions::assert_impl_all,
std::{
fmt::Debug,
hash::Hash,
marker::{Send, Sync},
panic::{RefUnwindSafe, UnwindSafe},
},
};
// auto traits
assert_impl_all!(TextSize: Send, Sync, Unpin, UnwindSafe, RefUnwindSafe);
assert_impl_all!(TextRange: Send, Sync, Unpin, UnwindSafe, RefUnwindSafe);
// common traits
assert_impl_all!(TextSize: Copy, Debug, Default, Hash, Ord);
assert_impl_all!(TextRange: Copy, Debug, Default, Hash, Eq);

View file

@ -1,24 +0,0 @@
use ruff_text_size::TextSize;
#[derive(Copy, Clone)]
struct BadRope<'a>(&'a [&'a str]);
impl BadRope<'_> {
fn text_len(self) -> TextSize {
self.0.iter().copied().map(TextSize::of).sum()
}
}
#[test]
fn main() {
let x: char = 'c';
let _ = TextSize::of(x);
let x: &str = "hello";
let _ = TextSize::of(x);
let x: &String = &"hello".into();
let _ = TextSize::of(x);
let _ = BadRope(&[""]).text_len();
}

View file

@ -1,8 +0,0 @@
use ruff_text_size::TextRange;
#[test]
fn main() {
let range = TextRange::default();
let _ = &""[range];
let _ = &String::new()[range];
}

View file

@ -1,79 +0,0 @@
use {
ruff_text_size::{TextRange, TextSize},
std::ops,
};
fn size(x: u32) -> TextSize {
TextSize::from(x)
}
fn range(x: ops::Range<u32>) -> TextRange {
TextRange::new(x.start.into(), x.end.into())
}
#[test]
fn sum() {
let xs: Vec<TextSize> = vec![size(0), size(1), size(2)];
assert_eq!(xs.iter().sum::<TextSize>(), size(3));
assert_eq!(xs.into_iter().sum::<TextSize>(), size(3));
}
#[test]
fn math() {
assert_eq!(size(10) + size(5), size(15));
assert_eq!(size(10) - size(5), size(5));
}
#[test]
fn checked_math() {
assert_eq!(size(1).checked_add(size(1)), Some(size(2)));
assert_eq!(size(1).checked_sub(size(1)), Some(size(0)));
assert_eq!(size(1).checked_sub(size(2)), None);
assert_eq!(size(!0).checked_add(size(1)), None);
}
#[test]
#[rustfmt::skip]
fn contains() {
assert!( range(2..4).contains_range(range(2..3)));
assert!( ! range(2..4).contains_range(range(1..3)));
}
#[test]
fn intersect() {
assert_eq!(range(1..2).intersect(range(2..3)), Some(range(2..2)));
assert_eq!(range(1..5).intersect(range(2..3)), Some(range(2..3)));
assert_eq!(range(1..2).intersect(range(3..4)), None);
}
#[test]
fn cover() {
assert_eq!(range(1..2).cover(range(2..3)), range(1..3));
assert_eq!(range(1..5).cover(range(2..3)), range(1..5));
assert_eq!(range(1..2).cover(range(4..5)), range(1..5));
}
#[test]
fn cover_offset() {
assert_eq!(range(1..3).cover_offset(size(0)), range(0..3));
assert_eq!(range(1..3).cover_offset(size(1)), range(1..3));
assert_eq!(range(1..3).cover_offset(size(2)), range(1..3));
assert_eq!(range(1..3).cover_offset(size(3)), range(1..3));
assert_eq!(range(1..3).cover_offset(size(4)), range(1..4));
}
#[test]
#[rustfmt::skip]
fn contains_point() {
assert!( ! range(1..3).contains(size(0)));
assert!( range(1..3).contains(size(1)));
assert!( range(1..3).contains(size(2)));
assert!( ! range(1..3).contains(size(3)));
assert!( ! range(1..3).contains(size(4)));
assert!( ! range(1..3).contains_inclusive(size(0)));
assert!( range(1..3).contains_inclusive(size(1)));
assert!( range(1..3).contains_inclusive(size(2)));
assert!( range(1..3).contains_inclusive(size(3)));
assert!( ! range(1..3).contains_inclusive(size(4)));
}

View file

@ -1,83 +0,0 @@
use {
ruff_text_size::{TextRange, TextSize},
serde_test::{assert_de_tokens_error, assert_tokens, Token},
std::ops,
};
fn size(x: u32) -> TextSize {
TextSize::from(x)
}
fn range(x: ops::Range<u32>) -> TextRange {
TextRange::new(x.start.into(), x.end.into())
}
#[test]
fn size_serialization() {
assert_tokens(&size(00), &[Token::U32(00)]);
assert_tokens(&size(10), &[Token::U32(10)]);
assert_tokens(&size(20), &[Token::U32(20)]);
assert_tokens(&size(30), &[Token::U32(30)]);
}
#[test]
fn range_serialization() {
assert_tokens(
&range(00..10),
&[
Token::Tuple { len: 2 },
Token::U32(00),
Token::U32(10),
Token::TupleEnd,
],
);
assert_tokens(
&range(10..20),
&[
Token::Tuple { len: 2 },
Token::U32(10),
Token::U32(20),
Token::TupleEnd,
],
);
assert_tokens(
&range(20..30),
&[
Token::Tuple { len: 2 },
Token::U32(20),
Token::U32(30),
Token::TupleEnd,
],
);
assert_tokens(
&range(30..40),
&[
Token::Tuple { len: 2 },
Token::U32(30),
Token::U32(40),
Token::TupleEnd,
],
);
}
#[test]
fn invalid_range_deserialization() {
assert_tokens::<TextRange>(
&range(62..92),
&[
Token::Tuple { len: 2 },
Token::U32(62),
Token::U32(92),
Token::TupleEnd,
],
);
assert_de_tokens_error::<TextRange>(
&[
Token::Tuple { len: 2 },
Token::U32(92),
Token::U32(62),
Token::TupleEnd,
],
"invalid range: 92..62",
);
}

17
vendored/Cargo.toml Normal file
View file

@ -0,0 +1,17 @@
[package]
name = "rustpython-parser-vendored"
description = "RustPython parser vendored third-party crates."
version = "0.3.0"
authors = ["RustPython Team"]
edition = "2021"
repository = "https://github.com/RustPython/Parser/"
license = "MIT"
[dependencies]
serde = { version = "1.0.133", optional = true, default-features = false, features = ["derive"] }
memchr.workspace = true
once_cell.workspace = true
[features]
default = []
location = []

3
vendored/README Normal file
View file

@ -0,0 +1,3 @@
This crate vendors third-party source codes which we can't depend on them through crates.io.
See README and LICENSE of each modules.

2
vendored/src/lib.rs Normal file
View file

@ -0,0 +1,2 @@
pub mod source_location;
pub mod text_size;

View file

@ -0,0 +1,23 @@
MIT License
Copyright (c) 2022 Charles Marsh
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
end of terms and conditions

View file

@ -0,0 +1,2 @@
This module is mainly imported from `ruff_python_ast::source_code`,
including `ruff_python_ast::source_code::SourceLocation` related source code.

View file

@ -1,5 +1,5 @@
use crate::SourceLocation;
use ruff_text_size::{TextLen, TextRange, TextSize};
use super::SourceLocation;
use crate::text_size::{TextLen, TextRange, TextSize};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use std::fmt;
@ -67,8 +67,8 @@ impl LineIndex {
/// ## Examples
///
/// ```
/// # use ruff_text_size::TextSize;
/// # use ruff_source_location::{LineIndex, OneIndexed, SourceLocation};
/// # use rustpython_parser_vendored::text_size::TextSize;
/// # use rustpython_parser_vendored::source_location::{LineIndex, OneIndexed, SourceLocation};
/// let source = "def a():\n pass";
/// let index = LineIndex::from_source_text(source);
///
@ -132,8 +132,8 @@ impl LineIndex {
/// ## Examples
///
/// ```
/// # use ruff_text_size::TextSize;
/// # use ruff_source_location::{LineIndex, OneIndexed, SourceLocation};
/// # use rustpython_parser_vendored::text_size::TextSize;
/// # use rustpython_parser_vendored::source_location::{LineIndex, OneIndexed, SourceLocation};
/// let source = "def a():\n pass";
/// let index = LineIndex::from_source_text(source);
///
@ -349,9 +349,9 @@ const fn unwrap<T: Copy>(option: Option<T>) -> T {
#[cfg(test)]
mod tests {
use crate::line_index::LineIndex;
use crate::{OneIndexed, SourceLocation};
use ruff_text_size::TextSize;
use crate::source_location::line_index::LineIndex;
use crate::source_location::{OneIndexed, SourceLocation};
use crate::text_size::TextSize;
#[test]
fn ascii_index() {

View file

@ -2,10 +2,8 @@ mod line_index;
// mod locator;
pub mod newlines;
pub use crate::line_index::{LineIndex, OneIndexed};
// TODO: RUSTPYTHON; import it later
// pub use locator::Locator;
use ruff_text_size::{TextRange, TextSize};
pub use self::line_index::{LineIndex, OneIndexed};
use crate::text_size::{TextRange, TextSize};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use std::fmt::{Debug, Formatter};

View file

@ -1,5 +1,5 @@
use crate::text_size::{TextLen, TextRange, TextSize};
use memchr::{memchr2, memrchr2};
use ruff_text_size::{TextLen, TextRange, TextSize};
use std::iter::FusedIterator;
use std::ops::Deref;
@ -20,8 +20,8 @@ impl StrExt for str {
/// ## Examples
///
/// ```rust
/// # use ruff_text_size::TextSize;
/// # use ruff_source_location::newlines::{Line, UniversalNewlineIterator};
/// # use rustpython_parser_vendored::text_size::TextSize;
/// # use rustpython_parser_vendored::source_location::newlines::{Line, UniversalNewlineIterator};
/// let mut lines = UniversalNewlineIterator::from("foo\nbar\n\r\nbaz\rbop");
///
/// assert_eq!(lines.next_back(), Some(Line::new("bop", TextSize::from(14))));
@ -337,9 +337,9 @@ impl Deref for LineEnding {
#[cfg(test)]
mod tests {
use super::Line;
use super::UniversalNewlineIterator;
use crate::newlines::Line;
use ruff_text_size::TextSize;
use crate::text_size::TextSize;
#[test]
fn universal_newlines_empty_str() {

View file

@ -0,0 +1,53 @@
MIT License
Copyright (c) 2022 Charles Marsh
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
end of terms and conditions
The externally maintained libraries from which parts of the Software is derived
are:
- rust-analyzer/text-size, licensed under the MIT license:
"""
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""

View file

@ -0,0 +1,2 @@
This module is imported from `ruff_text_size`,
which is a fork of `text-size`.

View file

@ -28,7 +28,7 @@ mod schemars_impls;
#[cfg(feature = "serde")]
mod serde_impls;
pub use crate::{range::TextRange, size::TextSize, traits::TextLen};
pub use self::{range::TextRange, size::TextSize, traits::TextLen};
#[cfg(target_pointer_width = "16")]
compile_error!("text-size assumes usize >= u32 and does not work on 16-bit targets");

View file

@ -1,7 +1,7 @@
use cmp::Ordering;
use {
crate::TextSize,
super::TextSize,
std::{
cmp, fmt,
ops::{Add, AddAssign, Bound, Index, IndexMut, Range, RangeBounds, Sub, SubAssign},
@ -34,7 +34,7 @@ impl TextRange {
/// # Examples
///
/// ```rust
/// # use ruff_text_size::*;
/// # use rustpython_parser_vendored::text_size::*;
/// let start = TextSize::from(5);
/// let end = TextSize::from(10);
/// let range = TextRange::new(start, end);
@ -54,7 +54,7 @@ impl TextRange {
/// # Examples
///
/// ```rust
/// # use ruff_text_size::*;
/// # use rustpython_parser_vendored::text_size::*;
/// let text = "0123456789";
///
/// let offset = TextSize::from(2);
@ -74,7 +74,7 @@ impl TextRange {
/// # Examples
///
/// ```rust
/// # use ruff_text_size::*;
/// # use rustpython_parser_vendored::text_size::*;
/// let point: TextSize;
/// # point = TextSize::from(3);
/// let range = TextRange::empty(point);
@ -94,7 +94,7 @@ impl TextRange {
/// # Examples
///
/// ```rust
/// # use ruff_text_size::*;
/// # use rustpython_parser_vendored::text_size::*;
/// let point: TextSize;
/// # point = TextSize::from(12);
/// let range = TextRange::up_to(point);
@ -152,7 +152,7 @@ impl TextRange {
/// # Examples
///
/// ```rust
/// # use ruff_text_size::*;
/// # use rustpython_parser_vendored::text_size::*;
/// let (start, end): (TextSize, TextSize);
/// # start = 10.into(); end = 20.into();
/// let range = TextRange::new(start, end);
@ -171,7 +171,7 @@ impl TextRange {
/// # Examples
///
/// ```rust
/// # use ruff_text_size::*;
/// # use rustpython_parser_vendored::text_size::*;
/// let (start, end): (TextSize, TextSize);
/// # start = 10.into(); end = 20.into();
/// let range = TextRange::new(start, end);
@ -188,7 +188,7 @@ impl TextRange {
/// # Examples
///
/// ```rust
/// # use ruff_text_size::*;
/// # use rustpython_parser_vendored::text_size::*;
/// let larger = TextRange::new(0.into(), 20.into());
/// let smaller = TextRange::new(5.into(), 15.into());
/// assert!(larger.contains_range(smaller));
@ -209,7 +209,7 @@ impl TextRange {
/// # Examples
///
/// ```rust
/// # use ruff_text_size::*;
/// # use rustpython_parser_vendored::text_size::*;
/// assert_eq!(
/// TextRange::intersect(
/// TextRange::new(0.into(), 10.into()),
@ -233,7 +233,7 @@ impl TextRange {
/// # Examples
///
/// ```rust
/// # use ruff_text_size::*;
/// # use rustpython_parser_vendored::text_size::*;
/// assert_eq!(
/// TextRange::cover(
/// TextRange::new(0.into(), 5.into()),
@ -255,7 +255,7 @@ impl TextRange {
/// # Examples
///
/// ```rust
/// # use ruff_text_size::*;
/// # use rustpython_parser_vendored::text_size::*;
/// assert_eq!(
/// TextRange::empty(0.into()).cover_offset(20.into()),
/// TextRange::new(0.into(), 20.into()),
@ -309,7 +309,7 @@ impl TextRange {
/// # Examples
///
/// ```
/// # use ruff_text_size::*;
/// # use rustpython_parser_vendored::text_size::*;
/// # use std::cmp::Ordering;
///
/// let a = TextRange::new(0.into(), 3.into());
@ -352,7 +352,7 @@ impl TextRange {
/// ## Examples
///
/// ```
/// use ruff_text_size::{TextRange, TextSize};
/// use rustpython_parser_vendored::text_size::{TextRange, TextSize};
///
/// let range = TextRange::new(TextSize::from(5), TextSize::from(10));
/// assert_eq!(range.sub_start(TextSize::from(2)), TextRange::new(TextSize::from(3), TextSize::from(10)));
@ -371,7 +371,7 @@ impl TextRange {
/// ## Examples
///
/// ```
/// use ruff_text_size::{TextRange, TextSize};
/// use rustpython_parser_vendored::text_size::{TextRange, TextSize};
///
/// let range = TextRange::new(TextSize::from(5), TextSize::from(10));
/// assert_eq!(range.add_start(TextSize::from(3)), TextRange::new(TextSize::from(8), TextSize::from(10)));
@ -391,7 +391,7 @@ impl TextRange {
/// ## Examples
///
/// ```
/// use ruff_text_size::{TextRange, TextSize};
/// use rustpython_parser_vendored::text_size::{TextRange, TextSize};
///
/// let range = TextRange::new(TextSize::from(5), TextSize::from(10));
/// assert_eq!(range.sub_end(TextSize::from(2)), TextRange::new(TextSize::from(5), TextSize::from(8)));
@ -411,7 +411,7 @@ impl TextRange {
/// ## Examples
///
/// ```
/// use ruff_text_size::{TextRange, TextSize};
/// use rustpython_parser_vendored::text_size::{TextRange, TextSize};
///
/// let range = TextRange::new(TextSize::from(5), TextSize::from(10));
/// assert_eq!(range.add_end(TextSize::from(2)), TextRange::new(TextSize::from(5), TextSize::from(12)));

View file

@ -1,5 +1,5 @@
use {
crate::{TextRange, TextSize},
super::{TextRange, TextSize},
serde::{de, Deserialize, Deserializer, Serialize, Serializer},
};

View file

@ -1,5 +1,5 @@
use {
crate::TextLen,
super::TextLen,
std::{
convert::TryFrom,
fmt, iter,
@ -38,7 +38,7 @@ impl TextSize {
/// # Examples
///
/// ```rust
/// # use ruff_text_size::*;
/// # use rustpython_parser_vendored::text_size::*;
/// assert_eq!(TextSize::from(4), TextSize::new(4));
/// ```
pub const fn new(offset: u32) -> Self {
@ -52,7 +52,7 @@ impl TextSize {
/// # Examples
///
/// ```rust
/// # use ruff_text_size::*;
/// # use rustpython_parser_vendored::text_size::*;
/// let char_size = TextSize::of('🦀');
/// assert_eq!(char_size, TextSize::from(4));
///
@ -69,7 +69,7 @@ impl TextSize {
/// # Examples
///
/// ```rust
/// # use ruff_text_size::*;
/// # use rustpython_parser_vendored::text_size::*;
/// assert_eq!(TextSize::from(4).to_u32(), 4);
/// ```
pub fn to_u32(&self) -> u32 {
@ -81,7 +81,7 @@ impl TextSize {
/// # Examples
///
/// ```rust
/// # use ruff_text_size::*;
/// # use rustpython_parser_vendored::text_size::*;
/// assert_eq!(TextSize::from(4).to_usize(), 4);
/// ```
pub fn to_usize(&self) -> usize {

View file

@ -1,4 +1,4 @@
use {crate::TextSize, std::convert::TryInto};
use {super::TextSize, std::convert::TryInto};
use priv_in_pub::Sealed;
mod priv_in_pub {