Skip to content

Commit d09bce8

Browse files
authored
vendor text_size and source_location (#102)
1 parent b079666 commit d09bce8

29 files changed

+175
-311
lines changed

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ include = ["LICENSE", "Cargo.toml", "src/**/*.rs"]
1111
[workspace]
1212
resolver = "2"
1313
members = [
14-
"ast", "core", "format", "literal", "parser",
14+
"ast", "core", "format", "literal", "parser", "vendored",
1515
"ast-pyo3",
16-
"ruff_text_size", "ruff_source_location",
1716
]
1817

1918
[workspace.dependencies]
19+
rustpython-parser-vendored = { path = "vendored" }
2020
rustpython-ast = { path = "ast", default-features = false }
2121
rustpython-parser-core = { path = "core", features = [] }
2222
rustpython-literal = { path = "literal" }

core/Cargo.toml

+3-5
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ repository = "https://github.com/RustPython/Parser/"
88
license = "MIT"
99

1010
[dependencies]
11-
# ruff dependency shouldn't be placed out of this crate
12-
ruff_text_size = { path = "../ruff_text_size" }
13-
ruff_source_location = { path = "../ruff_source_location", optional = true }
14-
11+
# vendored dependency shouldn't be placed out of this crate
12+
rustpython-parser-vendored.workspace = true
1513
serde = { version = "1.0.133", optional = true, default-features = false, features = ["derive"] }
1614
is-macro.workspace = true
1715
memchr.workspace = true
1816

1917
[features]
2018
default = []
21-
location = ["dep:ruff_source_location"]
19+
location = []

core/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ pub use error::BaseError;
1111
pub use format::ConversionFlag;
1212
pub use mode::Mode;
1313

14-
// re-export our public interface
15-
pub use ruff_text_size as text_size;
14+
#[cfg(feature = "location")]
15+
pub use rustpython_parser_vendored::source_location;
16+
pub use rustpython_parser_vendored::text_size;

core/src/source_code.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use crate::text_size::{TextLen, TextSize};
33
use memchr::memrchr2;
44

5-
pub use ruff_source_location::{
5+
pub use crate::source_location::{
66
newlines::{find_newline, UniversalNewlineIterator},
77
LineIndex, OneIndexed, SourceCode, SourceLocation,
88
};

literal/src/escape.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,15 @@ impl UnicodeEscape<'_> {
155155
};
156156
let Some(new_len) = length_add(out_len, incr) else {
157157
#[cold]
158-
fn stop(single_count: usize, double_count: usize, preferred_quote: Quote) -> EscapeLayout {
159-
EscapeLayout { quote: choose_quote(single_count, double_count, preferred_quote).0, len: None }
158+
fn stop(
159+
single_count: usize,
160+
double_count: usize,
161+
preferred_quote: Quote,
162+
) -> EscapeLayout {
163+
EscapeLayout {
164+
quote: choose_quote(single_count, double_count, preferred_quote).0,
165+
len: None,
166+
}
160167
}
161168
return stop(single_count, double_count, preferred_quote);
162169
};
@@ -332,8 +339,15 @@ impl AsciiEscape<'_> {
332339
};
333340
let Some(new_len) = length_add(out_len, incr) else {
334341
#[cold]
335-
fn stop(single_count: usize, double_count: usize, preferred_quote: Quote) -> EscapeLayout {
336-
EscapeLayout { quote: choose_quote(single_count, double_count, preferred_quote).0, len: None }
342+
fn stop(
343+
single_count: usize,
344+
double_count: usize,
345+
preferred_quote: Quote,
346+
) -> EscapeLayout {
347+
EscapeLayout {
348+
quote: choose_quote(single_count, double_count, preferred_quote).0,
349+
len: None,
350+
}
337351
}
338352
return stop(single_count, double_count, preferred_quote);
339353
};

parser/src/string.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,9 @@ impl<'a> StringParser<'a> {
374374
expression.push(ch);
375375
loop {
376376
let Some(c) = self.next_char() else {
377-
return Err(FStringError::new(UnterminatedString, self.get_pos()).into());
377+
return Err(
378+
FStringError::new(UnterminatedString, self.get_pos()).into()
379+
);
378380
};
379381
expression.push(c);
380382
if c == ch {
@@ -408,7 +410,7 @@ impl<'a> StringParser<'a> {
408410
spec_constructor.push(
409411
self.expr(
410412
ast::ExprConstant {
411-
value: constant_piece.drain(..).collect::<String>().into(),
413+
value: std::mem::take(&mut constant_piece).into(),
412414
kind: None,
413415
range: self.range(),
414416
}
@@ -433,7 +435,7 @@ impl<'a> StringParser<'a> {
433435
spec_constructor.push(
434436
self.expr(
435437
ast::ExprConstant {
436-
value: constant_piece.drain(..).collect::<String>().into(),
438+
value: std::mem::take(&mut constant_piece).into(),
437439
kind: None,
438440
range: self.range(),
439441
}
@@ -475,7 +477,7 @@ impl<'a> StringParser<'a> {
475477
values.push(
476478
self.expr(
477479
ast::ExprConstant {
478-
value: content.drain(..).collect::<String>().into(),
480+
value: std::mem::take(&mut content).into(),
479481
kind: None,
480482
range: self.range(),
481483
}

ruff_source_location/Cargo.toml

-17
This file was deleted.

ruff_text_size/Cargo.toml

-22
This file was deleted.

ruff_text_size/tests/auto_traits.rs

-18
This file was deleted.

ruff_text_size/tests/constructors.rs

-24
This file was deleted.

ruff_text_size/tests/indexing.rs

-8
This file was deleted.

ruff_text_size/tests/main.rs

-79
This file was deleted.

ruff_text_size/tests/serde.rs

-83
This file was deleted.

0 commit comments

Comments
 (0)