13
13
//! [`Mode`]: crate::mode
14
14
15
15
use crate :: {
16
- ast:: { self } ,
16
+ ast,
17
17
lexer:: { self , LexResult , LexicalError , LexicalErrorType } ,
18
18
mode:: Mode ,
19
19
python,
20
+ text_size:: TextSize ,
20
21
token:: Tok ,
21
- Location ,
22
22
} ;
23
23
use itertools:: Itertools ;
24
24
use std:: iter;
@@ -70,7 +70,7 @@ pub fn parse_program(source: &str, source_path: &str) -> Result<ast::Suite, Pars
70
70
///
71
71
/// ```
72
72
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 ( ) )
74
74
}
75
75
76
76
/// Parses a Python expression from a given location.
@@ -84,16 +84,15 @@ pub fn parse_expression(source: &str, path: &str) -> Result<ast::Expr, ParseErro
84
84
/// somewhat silly, location:
85
85
///
86
86
/// ```
87
- /// use ruff_text_size::TextSize;
88
- /// use rustpython_parser::{parse_expression_located};
87
+ /// use rustpython_parser::{text_size::TextSize, parse_expression_located};
89
88
///
90
89
/// let expr = parse_expression_located("1 + 2", "<embedded>", TextSize::from(400));
91
90
/// assert!(expr.is_ok());
92
91
/// ```
93
92
pub fn parse_expression_located (
94
93
source : & str ,
95
94
path : & str ,
96
- location : Location ,
95
+ location : TextSize ,
97
96
) -> Result < ast:: Expr , ParseError > {
98
97
parse_located ( source, Mode :: Expression , path, location) . map ( |top| match top {
99
98
ast:: Mod :: Expression ( ast:: ModExpression { body } ) => * body,
@@ -133,7 +132,7 @@ pub fn parse_expression_located(
133
132
/// assert!(program.is_ok());
134
133
/// ```
135
134
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 ( ) )
137
136
}
138
137
139
138
/// 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
144
143
/// # Example
145
144
///
146
145
/// ```
147
- /// use ruff_text_size::TextSize;
148
- /// use rustpython_parser::{Mode, parse_located};
146
+ /// use rustpython_parser::{text_size::TextSize, Mode, parse_located};
149
147
///
150
148
/// let source = r#"
151
149
/// def fib(i):
@@ -163,7 +161,7 @@ pub fn parse_located(
163
161
source : & str ,
164
162
mode : Mode ,
165
163
source_path : & str ,
166
- location : Location ,
164
+ location : TextSize ,
167
165
) -> Result < ast:: Mod , ParseError > {
168
166
let lxr = lexer:: lex_located ( source, mode, location) ;
169
167
parse_tokens ( lxr, mode, source_path)
@@ -226,7 +224,7 @@ impl std::error::Error for ParseErrorType {}
226
224
227
225
// Convert `lalrpop_util::ParseError` to our internal type
228
226
fn parse_error_from_lalrpop (
229
- err : LalrpopError < Location , Tok , LexicalError > ,
227
+ err : LalrpopError < TextSize , Tok , LexicalError > ,
230
228
source_path : & str ,
231
229
) -> ParseError {
232
230
let source_path = source_path. to_owned ( ) ;
0 commit comments