Skip to content

Commit f47dfca

Browse files
committed
Rename compiler Location to TextSize
1 parent 58c35ab commit f47dfca

File tree

13 files changed

+9423
-9427
lines changed

13 files changed

+9423
-9427
lines changed

ast/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@ unparse = ["rustpython-literal"]
1616
[dependencies]
1717
rustpython-compiler-core = { path = "../core", version = "0.2.0" }
1818
rustpython-literal = { path = "../literal", version = "0.2.0", optional = true }
19-
ruff_text_size = { path = "../ruff_text_size" }
2019

2120
num-bigint = { workspace = true }

ast/asdl_rs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ def write_ast_def(mod, typeinfo, f):
718718
#![allow(clippy::derive_partial_eq_without_eq)]
719719
720720
pub use crate::constant::*;
721-
pub use ruff_text_size::{TextSize, TextRange};
721+
pub use rustpython_compiler_core::text_size::{TextSize, TextRange};
722722
723723
type Ident = String;
724724
\n

ast/src/ast_gen.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![allow(clippy::derive_partial_eq_without_eq)]
44

55
pub use crate::constant::*;
6-
pub use ruff_text_size::{TextRange, TextSize};
6+
pub use rustpython_compiler_core::text_size::{TextRange, TextSize};
77

88
type Ident = String;
99

core/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ pub use bytecode::*;
1111
pub use error::BaseError;
1212
pub use location::Location;
1313
pub use mode::Mode;
14+
15+
pub use ruff_text_size as text_size; // re-export mandatory and frequently accessed dependency

parser/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ tiny-keccak = { version = "2", features = ["sha3"] }
2121
[dependencies]
2222
rustpython-ast = { path = "../ast", version = "0.2.0" }
2323
rustpython-compiler-core = { path = "../core", version = "0.2.0" }
24-
ruff_text_size = { path = "../ruff_text_size" }
2524

2625
ahash = { workspace = true }
2726
itertools = { workspace = true }

parser/src/function.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
use crate::{
44
ast,
55
lexer::{LexicalError, LexicalErrorType},
6+
text_size::TextSize,
67
};
7-
use ruff_text_size::TextSize;
88
use rustc_hash::FxHashSet;
99

1010
pub(crate) struct ArgumentList {

parser/src/lexer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ use crate::{
3131
mode::Mode,
3232
soft_keywords::SoftKeywordTransformer,
3333
string::FStringErrorType,
34+
text_size::{TextLen, TextRange, TextSize},
3435
token::{StringKind, Tok},
3536
};
3637
use log::trace;
3738
use num_bigint::BigInt;
3839
use num_traits::{Num, Zero};
39-
use ruff_text_size::{TextLen, TextRange, TextSize};
4040
use std::{char, cmp::Ordering, ops::Index, slice::SliceIndex, str::FromStr};
4141
use unic_emoji_char::is_emoji_presentation;
4242
use unic_ucd_ident::{is_xid_continue, is_xid_start};

parser/src/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
#![doc(html_root_url = "https://docs.rs/rustpython-parser/")]
114114

115115
pub use rustpython_ast as ast;
116+
pub use rustpython_compiler_core::text_size;
116117
pub use rustpython_compiler_core::ConversionFlag;
117118

118119
mod function;
@@ -125,14 +126,11 @@ mod soft_keywords;
125126
mod string;
126127
mod token;
127128

128-
type Location = TextSize;
129-
130129
pub use mode::Mode;
131130
pub use parser::{
132131
parse, parse_expression, parse_expression_located, parse_located, parse_program, parse_tokens,
133132
ParseError, ParseErrorType,
134133
};
135-
use ruff_text_size::TextSize;
136134
pub use string::FStringErrorType;
137135
pub use token::{StringKind, Tok};
138136

parser/src/parser.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
//! [`Mode`]: crate::mode
1414
1515
use crate::{
16-
ast::{self},
16+
ast,
1717
lexer::{self, LexResult, LexicalError, LexicalErrorType},
1818
mode::Mode,
1919
python,
20+
text_size::TextSize,
2021
token::Tok,
21-
Location,
2222
};
2323
use itertools::Itertools;
2424
use std::iter;
@@ -70,7 +70,7 @@ pub fn parse_program(source: &str, source_path: &str) -> Result<ast::Suite, Pars
7070
///
7171
/// ```
7272
pub fn parse_expression(source: &str, path: &str) -> Result<ast::Expr, ParseError> {
73-
parse_expression_located(source, path, Location::default())
73+
parse_expression_located(source, path, TextSize::default())
7474
}
7575

7676
/// Parses a Python expression from a given location.
@@ -84,16 +84,15 @@ pub fn parse_expression(source: &str, path: &str) -> Result<ast::Expr, ParseErro
8484
/// somewhat silly, location:
8585
///
8686
/// ```
87-
/// use ruff_text_size::TextSize;
88-
/// use rustpython_parser::{parse_expression_located};
87+
/// use rustpython_parser::{text_size::TextSize, parse_expression_located};
8988
///
9089
/// let expr = parse_expression_located("1 + 2", "<embedded>", TextSize::from(400));
9190
/// assert!(expr.is_ok());
9291
/// ```
9392
pub fn parse_expression_located(
9493
source: &str,
9594
path: &str,
96-
location: Location,
95+
location: TextSize,
9796
) -> Result<ast::Expr, ParseError> {
9897
parse_located(source, Mode::Expression, path, location).map(|top| match top {
9998
ast::Mod::Expression(ast::ModExpression { body }) => *body,
@@ -133,7 +132,7 @@ pub fn parse_expression_located(
133132
/// assert!(program.is_ok());
134133
/// ```
135134
pub fn parse(source: &str, mode: Mode, source_path: &str) -> Result<ast::Mod, ParseError> {
136-
parse_located(source, mode, source_path, Location::default())
135+
parse_located(source, mode, source_path, TextSize::default())
137136
}
138137

139138
/// Parse the given Python source code using the specified [`Mode`] and [`Location`].
@@ -144,8 +143,7 @@ pub fn parse(source: &str, mode: Mode, source_path: &str) -> Result<ast::Mod, Pa
144143
/// # Example
145144
///
146145
/// ```
147-
/// use ruff_text_size::TextSize;
148-
/// use rustpython_parser::{Mode, parse_located};
146+
/// use rustpython_parser::{text_size::TextSize, Mode, parse_located};
149147
///
150148
/// let source = r#"
151149
/// def fib(i):
@@ -163,7 +161,7 @@ pub fn parse_located(
163161
source: &str,
164162
mode: Mode,
165163
source_path: &str,
166-
location: Location,
164+
location: TextSize,
167165
) -> Result<ast::Mod, ParseError> {
168166
let lxr = lexer::lex_located(source, mode, location);
169167
parse_tokens(lxr, mode, source_path)
@@ -226,7 +224,7 @@ impl std::error::Error for ParseErrorType {}
226224

227225
// Convert `lalrpop_util::ParseError` to our internal type
228226
fn parse_error_from_lalrpop(
229-
err: LalrpopError<Location, Tok, LexicalError>,
227+
err: LalrpopError<TextSize, Tok, LexicalError>,
230228
source_path: &str,
231229
) -> ParseError {
232230
let source_path = source_path.to_owned();

parser/src/python.lalrpop

+2-2
Original file line numberDiff line numberDiff line change
@@ -1721,7 +1721,7 @@ ArgumentList: ArgumentList = {
17211721
}
17221722
};
17231723

1724-
FunctionArgument: (Option<(crate::Location, crate::Location, Option<String>)>, ast::Expr) = {
1724+
FunctionArgument: (Option<(crate::text_size::TextSize, crate::text_size::TextSize, Option<String>)>, ast::Expr) = {
17251725
<location:@L> <e:NamedExpressionTest> <c:CompFor?> <end_location:@R> => {
17261726
let expr = match c {
17271727
Some(c) => ast::Expr::new(
@@ -1776,7 +1776,7 @@ Identifier: String = <s:name> => s;
17761776

17771777
// Hook external lexer:
17781778
extern {
1779-
type Location = crate::Location;
1779+
type Location = crate::text_size::TextSize;
17801780
type Error = LexicalError;
17811781

17821782
enum token::Tok {

0 commit comments

Comments
 (0)