From d09bce80e6acb86f4c6ee9c6a3f7f0acaef578c4 Mon Sep 17 00:00:00 2001 From: "Jeong, YunWon" <69878+youknowone@users.noreply.github.com> Date: Tue, 29 Aug 2023 19:52:25 +0900 Subject: [PATCH] vendor text_size and source_location (#102) --- Cargo.toml | 4 +- core/Cargo.toml | 8 +- core/src/lib.rs | 5 +- core/src/source_code.rs | 2 +- literal/src/escape.rs | 22 ++++- parser/src/string.rs | 10 ++- ruff_source_location/Cargo.toml | 17 ---- ruff_text_size/Cargo.toml | 22 ----- ruff_text_size/tests/auto_traits.rs | 18 ---- ruff_text_size/tests/constructors.rs | 24 ------ ruff_text_size/tests/indexing.rs | 8 -- ruff_text_size/tests/main.rs | 79 ------------------ ruff_text_size/tests/serde.rs | 83 ------------------- vendored/Cargo.toml | 17 ++++ vendored/README | 3 + vendored/src/lib.rs | 2 + vendored/src/source_location/LICENSE | 23 +++++ vendored/src/source_location/README | 2 + .../src/source_location}/line_index.rs | 18 ++-- .../src/source_location/mod.rs | 6 +- .../src/source_location}/newlines.rs | 10 +-- vendored/src/text_size/LICENSE | 53 ++++++++++++ vendored/src/text_size/README | 2 + .../lib.rs => vendored/src/text_size/mod.rs | 2 +- .../src => vendored/src/text_size}/range.rs | 32 +++---- .../src/text_size}/schemars_impls.rs | 0 .../src/text_size}/serde_impls.rs | 2 +- .../src => vendored/src/text_size}/size.rs | 10 +-- .../src => vendored/src/text_size}/traits.rs | 2 +- 29 files changed, 175 insertions(+), 311 deletions(-) delete mode 100644 ruff_source_location/Cargo.toml delete mode 100644 ruff_text_size/Cargo.toml delete mode 100644 ruff_text_size/tests/auto_traits.rs delete mode 100644 ruff_text_size/tests/constructors.rs delete mode 100644 ruff_text_size/tests/indexing.rs delete mode 100644 ruff_text_size/tests/main.rs delete mode 100644 ruff_text_size/tests/serde.rs create mode 100644 vendored/Cargo.toml create mode 100644 vendored/README create mode 100644 vendored/src/lib.rs create mode 100644 vendored/src/source_location/LICENSE create mode 100644 vendored/src/source_location/README rename {ruff_source_location/src => vendored/src/source_location}/line_index.rs (97%) rename ruff_source_location/src/lib.rs => vendored/src/source_location/mod.rs (97%) rename {ruff_source_location/src => vendored/src/source_location}/newlines.rs (97%) create mode 100644 vendored/src/text_size/LICENSE create mode 100644 vendored/src/text_size/README rename ruff_text_size/src/lib.rs => vendored/src/text_size/mod.rs (94%) rename {ruff_text_size/src => vendored/src/text_size}/range.rs (93%) rename {ruff_text_size/src => vendored/src/text_size}/schemars_impls.rs (100%) rename {ruff_text_size/src => vendored/src/text_size}/serde_impls.rs (97%) rename {ruff_text_size/src => vendored/src/text_size}/size.rs (95%) rename {ruff_text_size/src => vendored/src/text_size}/traits.rs (94%) diff --git a/Cargo.toml b/Cargo.toml index 2342f7f..e0b86de 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" } diff --git a/core/Cargo.toml b/core/Cargo.toml index 867a146..a268328 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -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 = [] diff --git a/core/src/lib.rs b/core/src/lib.rs index 06b2d3b..00687a6 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -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; diff --git a/core/src/source_code.rs b/core/src/source_code.rs index b45f200..3e1c44e 100644 --- a/core/src/source_code.rs +++ b/core/src/source_code.rs @@ -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, }; diff --git a/literal/src/escape.rs b/literal/src/escape.rs index 082248a..ee4fae5 100644 --- a/literal/src/escape.rs +++ b/literal/src/escape.rs @@ -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); }; diff --git a/parser/src/string.rs b/parser/src/string.rs index cb2b0e1..2201343 100644 --- a/parser/src/string.rs +++ b/parser/src/string.rs @@ -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::().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::().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::().into(), + value: std::mem::take(&mut content).into(), kind: None, range: self.range(), } diff --git a/ruff_source_location/Cargo.toml b/ruff_source_location/Cargo.toml deleted file mode 100644 index 3512307..0000000 --- a/ruff_source_location/Cargo.toml +++ /dev/null @@ -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 } diff --git a/ruff_text_size/Cargo.toml b/ruff_text_size/Cargo.toml deleted file mode 100644 index d3ce185..0000000 --- a/ruff_text_size/Cargo.toml +++ /dev/null @@ -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"] \ No newline at end of file diff --git a/ruff_text_size/tests/auto_traits.rs b/ruff_text_size/tests/auto_traits.rs deleted file mode 100644 index 6adf8bd..0000000 --- a/ruff_text_size/tests/auto_traits.rs +++ /dev/null @@ -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); diff --git a/ruff_text_size/tests/constructors.rs b/ruff_text_size/tests/constructors.rs deleted file mode 100644 index 8ee2fde..0000000 --- a/ruff_text_size/tests/constructors.rs +++ /dev/null @@ -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(); -} diff --git a/ruff_text_size/tests/indexing.rs b/ruff_text_size/tests/indexing.rs deleted file mode 100644 index e7205fd..0000000 --- a/ruff_text_size/tests/indexing.rs +++ /dev/null @@ -1,8 +0,0 @@ -use ruff_text_size::TextRange; - -#[test] -fn main() { - let range = TextRange::default(); - let _ = &""[range]; - let _ = &String::new()[range]; -} diff --git a/ruff_text_size/tests/main.rs b/ruff_text_size/tests/main.rs deleted file mode 100644 index 8d8dd09..0000000 --- a/ruff_text_size/tests/main.rs +++ /dev/null @@ -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) -> TextRange { - TextRange::new(x.start.into(), x.end.into()) -} - -#[test] -fn sum() { - let xs: Vec = vec![size(0), size(1), size(2)]; - assert_eq!(xs.iter().sum::(), size(3)); - assert_eq!(xs.into_iter().sum::(), 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))); -} diff --git a/ruff_text_size/tests/serde.rs b/ruff_text_size/tests/serde.rs deleted file mode 100644 index 0d8f9d4..0000000 --- a/ruff_text_size/tests/serde.rs +++ /dev/null @@ -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) -> 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::( - &range(62..92), - &[ - Token::Tuple { len: 2 }, - Token::U32(62), - Token::U32(92), - Token::TupleEnd, - ], - ); - assert_de_tokens_error::( - &[ - Token::Tuple { len: 2 }, - Token::U32(92), - Token::U32(62), - Token::TupleEnd, - ], - "invalid range: 92..62", - ); -} diff --git a/vendored/Cargo.toml b/vendored/Cargo.toml new file mode 100644 index 0000000..550ff18 --- /dev/null +++ b/vendored/Cargo.toml @@ -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 = [] diff --git a/vendored/README b/vendored/README new file mode 100644 index 0000000..39236fb --- /dev/null +++ b/vendored/README @@ -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. diff --git a/vendored/src/lib.rs b/vendored/src/lib.rs new file mode 100644 index 0000000..f90702b --- /dev/null +++ b/vendored/src/lib.rs @@ -0,0 +1,2 @@ +pub mod source_location; +pub mod text_size; diff --git a/vendored/src/source_location/LICENSE b/vendored/src/source_location/LICENSE new file mode 100644 index 0000000..b219e66 --- /dev/null +++ b/vendored/src/source_location/LICENSE @@ -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 diff --git a/vendored/src/source_location/README b/vendored/src/source_location/README new file mode 100644 index 0000000..d6871d1 --- /dev/null +++ b/vendored/src/source_location/README @@ -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. \ No newline at end of file diff --git a/ruff_source_location/src/line_index.rs b/vendored/src/source_location/line_index.rs similarity index 97% rename from ruff_source_location/src/line_index.rs rename to vendored/src/source_location/line_index.rs index 35041b0..4e42440 100644 --- a/ruff_source_location/src/line_index.rs +++ b/vendored/src/source_location/line_index.rs @@ -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(option: Option) -> 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() { diff --git a/ruff_source_location/src/lib.rs b/vendored/src/source_location/mod.rs similarity index 97% rename from ruff_source_location/src/lib.rs rename to vendored/src/source_location/mod.rs index c7e8b9f..033bf6f 100644 --- a/ruff_source_location/src/lib.rs +++ b/vendored/src/source_location/mod.rs @@ -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}; diff --git a/ruff_source_location/src/newlines.rs b/vendored/src/source_location/newlines.rs similarity index 97% rename from ruff_source_location/src/newlines.rs rename to vendored/src/source_location/newlines.rs index 75d778b..ac7cf44 100644 --- a/ruff_source_location/src/newlines.rs +++ b/vendored/src/source_location/newlines.rs @@ -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() { diff --git a/vendored/src/text_size/LICENSE b/vendored/src/text_size/LICENSE new file mode 100644 index 0000000..f5dadce --- /dev/null +++ b/vendored/src/text_size/LICENSE @@ -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. + """ diff --git a/vendored/src/text_size/README b/vendored/src/text_size/README new file mode 100644 index 0000000..8f8a820 --- /dev/null +++ b/vendored/src/text_size/README @@ -0,0 +1,2 @@ +This module is imported from `ruff_text_size`, +which is a fork of `text-size`. diff --git a/ruff_text_size/src/lib.rs b/vendored/src/text_size/mod.rs similarity index 94% rename from ruff_text_size/src/lib.rs rename to vendored/src/text_size/mod.rs index fd27c65..977038a 100644 --- a/ruff_text_size/src/lib.rs +++ b/vendored/src/text_size/mod.rs @@ -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"); diff --git a/ruff_text_size/src/range.rs b/vendored/src/text_size/range.rs similarity index 93% rename from ruff_text_size/src/range.rs rename to vendored/src/text_size/range.rs index 2703bf3..b9ba93c 100644 --- a/ruff_text_size/src/range.rs +++ b/vendored/src/text_size/range.rs @@ -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))); diff --git a/ruff_text_size/src/schemars_impls.rs b/vendored/src/text_size/schemars_impls.rs similarity index 100% rename from ruff_text_size/src/schemars_impls.rs rename to vendored/src/text_size/schemars_impls.rs diff --git a/ruff_text_size/src/serde_impls.rs b/vendored/src/text_size/serde_impls.rs similarity index 97% rename from ruff_text_size/src/serde_impls.rs rename to vendored/src/text_size/serde_impls.rs index b6885d6..9dace57 100644 --- a/ruff_text_size/src/serde_impls.rs +++ b/vendored/src/text_size/serde_impls.rs @@ -1,5 +1,5 @@ use { - crate::{TextRange, TextSize}, + super::{TextRange, TextSize}, serde::{de, Deserialize, Deserializer, Serialize, Serializer}, }; diff --git a/ruff_text_size/src/size.rs b/vendored/src/text_size/size.rs similarity index 95% rename from ruff_text_size/src/size.rs rename to vendored/src/text_size/size.rs index 7002d5a..27a0f12 100644 --- a/ruff_text_size/src/size.rs +++ b/vendored/src/text_size/size.rs @@ -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 { diff --git a/ruff_text_size/src/traits.rs b/vendored/src/text_size/traits.rs similarity index 94% rename from ruff_text_size/src/traits.rs rename to vendored/src/text_size/traits.rs index 3f5261b..b72d2de 100644 --- a/ruff_text_size/src/traits.rs +++ b/vendored/src/text_size/traits.rs @@ -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 {