parse_expression{=>_starts}_at

This commit is contained in:
Jeong YunWon 2023-05-10 21:25:58 +09:00
parent aa101e4f26
commit 822cac5aa0
3 changed files with 8 additions and 8 deletions

View file

@ -125,8 +125,8 @@ mod string;
mod token;
pub use parser::{
parse, parse_expression, parse_expression_at, parse_program, parse_starts_at, parse_tokens,
ParseError, ParseErrorType,
parse, parse_expression, parse_expression_starts_at, parse_program, parse_starts_at,
parse_tokens, ParseError, ParseErrorType,
};
pub use string::FStringErrorType;
pub use token::{StringKind, Tok};

View file

@ -70,7 +70,7 @@ pub fn parse_program(source: &str, source_path: &str) -> Result<ast::Suite, Pars
///
/// ```
pub fn parse_expression(source: &str, path: &str) -> Result<ast::Expr, ParseError> {
parse_expression_at(source, path, TextSize::default())
parse_expression_starts_at(source, path, TextSize::default())
}
/// Parses a Python expression from a given location.
@ -84,12 +84,12 @@ pub fn parse_expression(source: &str, path: &str) -> Result<ast::Expr, ParseErro
/// somewhat silly, location:
///
/// ```
/// use rustpython_parser::{text_size::TextSize, parse_expression_at};
/// use rustpython_parser::{text_size::TextSize, parse_expression_starts_at};
///
/// let expr = parse_expression_at("1 + 2", "<embedded>", TextSize::from(400));
/// let expr = parse_expression_starts_at("1 + 2", "<embedded>", TextSize::from(400));
/// assert!(expr.is_ok());
/// ```
pub fn parse_expression_at(
pub fn parse_expression_starts_at(
source: &str,
path: &str,
offset: TextSize,

View file

@ -6,7 +6,7 @@
use crate::{
ast::{self, Constant, Expr, ExprKind, Int},
lexer::{LexicalError, LexicalErrorType},
parser::{parse_expression_at, LalrpopError, ParseError, ParseErrorType},
parser::{parse_expression_starts_at, LalrpopError, ParseError, ParseErrorType},
token::{StringKind, Tok},
};
use itertools::Itertools;
@ -575,7 +575,7 @@ impl<'a> StringParser<'a> {
fn parse_fstring_expr(source: &str, location: TextSize) -> Result<Expr, ParseError> {
let fstring_body = format!("({source})");
let start = location - TextSize::from(1);
parse_expression_at(&fstring_body, "<fstring>", start)
parse_expression_starts_at(&fstring_body, "<fstring>", start)
}
fn parse_string(