mirror of
https://github.com/RustPython/Parser.git
synced 2025-08-26 13:24:42 +00:00
parse_expression{=>_starts}_at
This commit is contained in:
parent
aa101e4f26
commit
822cac5aa0
3 changed files with 8 additions and 8 deletions
|
@ -125,8 +125,8 @@ mod string;
|
||||||
mod token;
|
mod token;
|
||||||
|
|
||||||
pub use parser::{
|
pub use parser::{
|
||||||
parse, parse_expression, parse_expression_at, parse_program, parse_starts_at, parse_tokens,
|
parse, parse_expression, parse_expression_starts_at, parse_program, parse_starts_at,
|
||||||
ParseError, ParseErrorType,
|
parse_tokens, ParseError, ParseErrorType,
|
||||||
};
|
};
|
||||||
pub use string::FStringErrorType;
|
pub use string::FStringErrorType;
|
||||||
pub use token::{StringKind, Tok};
|
pub use token::{StringKind, Tok};
|
||||||
|
|
|
@ -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> {
|
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.
|
/// 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:
|
/// 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());
|
/// assert!(expr.is_ok());
|
||||||
/// ```
|
/// ```
|
||||||
pub fn parse_expression_at(
|
pub fn parse_expression_starts_at(
|
||||||
source: &str,
|
source: &str,
|
||||||
path: &str,
|
path: &str,
|
||||||
offset: TextSize,
|
offset: TextSize,
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{self, Constant, Expr, ExprKind, Int},
|
ast::{self, Constant, Expr, ExprKind, Int},
|
||||||
lexer::{LexicalError, LexicalErrorType},
|
lexer::{LexicalError, LexicalErrorType},
|
||||||
parser::{parse_expression_at, LalrpopError, ParseError, ParseErrorType},
|
parser::{parse_expression_starts_at, LalrpopError, ParseError, ParseErrorType},
|
||||||
token::{StringKind, Tok},
|
token::{StringKind, Tok},
|
||||||
};
|
};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
@ -575,7 +575,7 @@ impl<'a> StringParser<'a> {
|
||||||
fn parse_fstring_expr(source: &str, location: TextSize) -> Result<Expr, ParseError> {
|
fn parse_fstring_expr(source: &str, location: TextSize) -> Result<Expr, ParseError> {
|
||||||
let fstring_body = format!("({source})");
|
let fstring_body = format!("({source})");
|
||||||
let start = location - TextSize::from(1);
|
let start = location - TextSize::from(1);
|
||||||
parse_expression_at(&fstring_body, "<fstring>", start)
|
parse_expression_starts_at(&fstring_body, "<fstring>", start)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_string(
|
fn parse_string(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue