Skip to content

Commit 32a70c2

Browse files
committed
Let located only for python located stuff
1 parent 5d82243 commit 32a70c2

File tree

7 files changed

+38
-38
lines changed

7 files changed

+38
-38
lines changed

ast/asdl_rs.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,9 @@ def visitModule(self, mod, depth):
391391
)
392392
self.emit(
393393
"""
394-
fn map_located<T>(&mut self, located: Attributed<T, U>) -> Result<Attributed<T, Self::TargetU>, Self::Error> {
395-
let custom = self.map_user(located.custom)?;
396-
Ok(Attributed { range: located.range, custom, node: located.node })
394+
fn map_attributed<T>(&mut self, attributed: Attributed<T, U>) -> Result<Attributed<T, Self::TargetU>, Self::Error> {
395+
let custom = self.map_user(attributed.custom)?;
396+
Ok(Attributed { range: attributed.range, custom, node: attributed.node })
397397
}""",
398398
depth + 1,
399399
)
@@ -423,11 +423,11 @@ def visitType(self, type, depth):
423423
class FoldImplVisitor(EmitVisitor):
424424
def visitModule(self, mod, depth):
425425
self.emit(
426-
"fn fold_located<U, F: Fold<U> + ?Sized, T, MT>(folder: &mut F, node: Attributed<T, U>, f: impl FnOnce(&mut F, T) -> Result<MT, F::Error>) -> Result<Attributed<MT, F::TargetU>, F::Error> {",
426+
"fn fold_attributed<U, F: Fold<U> + ?Sized, T, MT>(folder: &mut F, node: Attributed<T, U>, f: impl FnOnce(&mut F, T) -> Result<MT, F::Error>) -> Result<Attributed<MT, F::TargetU>, F::Error> {",
427427
depth,
428428
)
429429
self.emit(
430-
"let node = folder.map_located(node)?; Ok(Attributed { custom: node.custom, range: node.range, node: f(folder, node.node)? })",
430+
"let node = folder.map_attributed(node)?; Ok(Attributed { custom: node.custom, range: node.range, node: f(folder, node.node)? })",
431431
depth + 1,
432432
)
433433
self.emit("}", depth)
@@ -459,7 +459,7 @@ def visitSum(self, sum, name, depth):
459459
depth,
460460
)
461461
if typeinfo.has_attributes:
462-
self.emit("fold_located(folder, node, |folder, node| {", depth)
462+
self.emit("fold_attributed(folder, node, |folder, node| {", depth)
463463

464464
self.emit("match node {", depth + 1)
465465
for cons in sum.types:
@@ -501,7 +501,7 @@ def visitProduct(self, product, name, depth):
501501
depth,
502502
)
503503
if has_attributes:
504-
self.emit("fold_located(folder, node, |folder, node| {", depth)
504+
self.emit("fold_attributed(folder, node, |folder, node| {", depth)
505505
rustname = structname + "Data"
506506
else:
507507
rustname = structname

ast/src/gen/generic.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -1020,15 +1020,15 @@ pub mod fold {
10201020
type Error;
10211021
fn map_user(&mut self, user: U) -> Result<Self::TargetU, Self::Error>;
10221022

1023-
fn map_located<T>(
1023+
fn map_attributed<T>(
10241024
&mut self,
1025-
located: Attributed<T, U>,
1025+
attributed: Attributed<T, U>,
10261026
) -> Result<Attributed<T, Self::TargetU>, Self::Error> {
1027-
let custom = self.map_user(located.custom)?;
1027+
let custom = self.map_user(attributed.custom)?;
10281028
Ok(Attributed {
1029-
range: located.range,
1029+
range: attributed.range,
10301030
custom,
1031-
node: located.node,
1031+
node: attributed.node,
10321032
})
10331033
}
10341034

@@ -1114,12 +1114,12 @@ pub mod fold {
11141114
fold_type_ignore(self, node)
11151115
}
11161116
}
1117-
fn fold_located<U, F: Fold<U> + ?Sized, T, MT>(
1117+
fn fold_attributed<U, F: Fold<U> + ?Sized, T, MT>(
11181118
folder: &mut F,
11191119
node: Attributed<T, U>,
11201120
f: impl FnOnce(&mut F, T) -> Result<MT, F::Error>,
11211121
) -> Result<Attributed<MT, F::TargetU>, F::Error> {
1122-
let node = folder.map_located(node)?;
1122+
let node = folder.map_attributed(node)?;
11231123
Ok(Attributed {
11241124
custom: node.custom,
11251125
range: node.range,
@@ -1171,7 +1171,7 @@ pub mod fold {
11711171
#[allow(unused)] folder: &mut F,
11721172
node: Stmt<U>,
11731173
) -> Result<Stmt<F::TargetU>, F::Error> {
1174-
fold_located(folder, node, |folder, node| match node {
1174+
fold_attributed(folder, node, |folder, node| match node {
11751175
StmtKind::FunctionDef(StmtFunctionDef {
11761176
name,
11771177
args,
@@ -1375,7 +1375,7 @@ pub mod fold {
13751375
#[allow(unused)] folder: &mut F,
13761376
node: Expr<U>,
13771377
) -> Result<Expr<F::TargetU>, F::Error> {
1378-
fold_located(folder, node, |folder, node| match node {
1378+
fold_attributed(folder, node, |folder, node| match node {
13791379
ExprKind::BoolOp(ExprBoolOp { op, values }) => Ok(ExprKind::BoolOp(ExprBoolOp {
13801380
op: Foldable::fold(op, folder)?,
13811381
values: Foldable::fold(values, folder)?,
@@ -1675,7 +1675,7 @@ pub mod fold {
16751675
#[allow(unused)] folder: &mut F,
16761676
node: Excepthandler<U>,
16771677
) -> Result<Excepthandler<F::TargetU>, F::Error> {
1678-
fold_located(folder, node, |folder, node| match node {
1678+
fold_attributed(folder, node, |folder, node| match node {
16791679
ExcepthandlerKind::ExceptHandler(ExcepthandlerExceptHandler { type_, name, body }) => {
16801680
Ok(ExcepthandlerKind::ExceptHandler(
16811681
ExcepthandlerExceptHandler {
@@ -1732,7 +1732,7 @@ pub mod fold {
17321732
#[allow(unused)] folder: &mut F,
17331733
node: Arg<U>,
17341734
) -> Result<Arg<F::TargetU>, F::Error> {
1735-
fold_located(folder, node, |folder, node| {
1735+
fold_attributed(folder, node, |folder, node| {
17361736
let ArgData {
17371737
arg,
17381738
annotation,
@@ -1758,7 +1758,7 @@ pub mod fold {
17581758
#[allow(unused)] folder: &mut F,
17591759
node: Keyword<U>,
17601760
) -> Result<Keyword<F::TargetU>, F::Error> {
1761-
fold_located(folder, node, |folder, node| {
1761+
fold_attributed(folder, node, |folder, node| {
17621762
let KeywordData { arg, value } = node;
17631763
Ok(KeywordData {
17641764
arg: Foldable::fold(arg, folder)?,
@@ -1779,7 +1779,7 @@ pub mod fold {
17791779
#[allow(unused)] folder: &mut F,
17801780
node: Alias<U>,
17811781
) -> Result<Alias<F::TargetU>, F::Error> {
1782-
fold_located(folder, node, |folder, node| {
1782+
fold_attributed(folder, node, |folder, node| {
17831783
let AliasData { name, asname } = node;
17841784
Ok(AliasData {
17851785
name: Foldable::fold(name, folder)?,
@@ -1846,7 +1846,7 @@ pub mod fold {
18461846
#[allow(unused)] folder: &mut F,
18471847
node: Pattern<U>,
18481848
) -> Result<Pattern<F::TargetU>, F::Error> {
1849-
fold_located(folder, node, |folder, node| match node {
1849+
fold_attributed(folder, node, |folder, node| match node {
18501850
PatternKind::MatchValue(PatternMatchValue { value }) => {
18511851
Ok(PatternKind::MatchValue(PatternMatchValue {
18521852
value: Foldable::fold(value, folder)?,

ast/src/source_locator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ impl crate::fold::Fold<()> for SourceLocator<'_> {
77

88
#[cold]
99
fn map_user(&mut self, _user: ()) -> Result<Self::TargetU, Self::Error> {
10-
unreachable!("implemented map_located");
10+
unreachable!("implemented map_attributed");
1111
}
1212

13-
fn map_located<T>(
13+
fn map_attributed<T>(
1414
&mut self,
1515
node: Attributed<T, ()>,
1616
) -> Result<Attributed<T, Self::TargetU>, Self::Error> {

parser/src/lexer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,12 @@ pub type LexResult = Result<Spanned, LexicalError>;
203203
/// ```
204204
#[inline]
205205
pub fn lex(source: &str, mode: Mode) -> impl Iterator<Item = LexResult> + '_ {
206-
lex_located(source, mode, TextSize::default())
206+
lex_starts_at(source, mode, TextSize::default())
207207
}
208208

209209
/// Create a new lexer from a source string, starting at a given location.
210210
/// You probably want to use [`lex`] instead.
211-
pub fn lex_located(
211+
pub fn lex_starts_at(
212212
source: &str,
213213
mode: Mode,
214214
start_offset: TextSize,

parser/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ mod string;
125125
mod token;
126126

127127
pub use parser::{
128-
parse, parse_expression, parse_expression_located, parse_located, parse_program, parse_tokens,
128+
parse, parse_expression, parse_expression_at, parse_program, parse_starts_at, parse_tokens,
129129
ParseError, ParseErrorType,
130130
};
131131
pub use string::FStringErrorType;

parser/src/parser.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -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, TextSize::default())
73+
parse_expression_at(source, path, TextSize::default())
7474
}
7575

7676
/// Parses a Python expression from a given location.
@@ -84,17 +84,17 @@ pub fn parse_expression(source: &str, path: &str) -> Result<ast::Expr, ParseErro
8484
/// somewhat silly, location:
8585
///
8686
/// ```
87-
/// use rustpython_parser::{text_size::TextSize, parse_expression_located};
87+
/// use rustpython_parser::{text_size::TextSize, parse_expression_at};
8888
///
89-
/// let expr = parse_expression_located("1 + 2", "<embedded>", TextSize::from(400));
89+
/// let expr = parse_expression_at("1 + 2", "<embedded>", TextSize::from(400));
9090
/// assert!(expr.is_ok());
9191
/// ```
92-
pub fn parse_expression_located(
92+
pub fn parse_expression_at(
9393
source: &str,
9494
path: &str,
9595
offset: TextSize,
9696
) -> Result<ast::Expr, ParseError> {
97-
parse_located(source, Mode::Expression, path, offset).map(|top| match top {
97+
parse_starts_at(source, Mode::Expression, path, offset).map(|top| match top {
9898
ast::Mod::Expression(ast::ModExpression { body }) => *body,
9999
_ => unreachable!(),
100100
})
@@ -132,7 +132,7 @@ pub fn parse_expression_located(
132132
/// assert!(program.is_ok());
133133
/// ```
134134
pub fn parse(source: &str, mode: Mode, source_path: &str) -> Result<ast::Mod, ParseError> {
135-
parse_located(source, mode, source_path, TextSize::default())
135+
parse_starts_at(source, mode, source_path, TextSize::default())
136136
}
137137

138138
/// Parse the given Python source code using the specified [`Mode`] and [`Location`].
@@ -143,7 +143,7 @@ pub fn parse(source: &str, mode: Mode, source_path: &str) -> Result<ast::Mod, Pa
143143
/// # Example
144144
///
145145
/// ```
146-
/// use rustpython_parser::{text_size::TextSize, Mode, parse_located};
146+
/// use rustpython_parser::{text_size::TextSize, Mode, parse_starts_at};
147147
///
148148
/// let source = r#"
149149
/// def fib(i):
@@ -154,16 +154,16 @@ pub fn parse(source: &str, mode: Mode, source_path: &str) -> Result<ast::Mod, Pa
154154
///
155155
/// print(fib(42))
156156
/// "#;
157-
/// let program = parse_located(source, Mode::Module, "<embedded>", TextSize::from(0));
157+
/// let program = parse_starts_at(source, Mode::Module, "<embedded>", TextSize::from(0));
158158
/// assert!(program.is_ok());
159159
/// ```
160-
pub fn parse_located(
160+
pub fn parse_starts_at(
161161
source: &str,
162162
mode: Mode,
163163
source_path: &str,
164164
offset: TextSize,
165165
) -> Result<ast::Mod, ParseError> {
166-
let lxr = lexer::lex_located(source, mode, offset);
166+
let lxr = lexer::lex_starts_at(source, mode, offset);
167167
parse_tokens(lxr, mode, source_path)
168168
}
169169

parser/src/string.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use crate::{
77
ast::{self, Constant, Expr, ExprKind},
88
lexer::{LexicalError, LexicalErrorType},
9-
parser::{parse_expression_located, LalrpopError, ParseError, ParseErrorType},
9+
parser::{parse_expression_at, LalrpopError, ParseError, ParseErrorType},
1010
token::{StringKind, Tok},
1111
};
1212
use itertools::Itertools;
@@ -575,7 +575,7 @@ impl<'a> StringParser<'a> {
575575
fn parse_fstring_expr(source: &str, location: TextSize) -> Result<Expr, ParseError> {
576576
let fstring_body = format!("({source})");
577577
let start = location - TextSize::from(1);
578-
parse_expression_located(&fstring_body, "<fstring>", start)
578+
parse_expression_at(&fstring_body, "<fstring>", start)
579579
}
580580

581581
fn parse_string(

0 commit comments

Comments
 (0)