Parses a Python expression for the given range in the source. This function allows to specify the range of the expression in the source code, other than that, it behaves exactly like [`parse_expression`]. # Example Parsing one of the numeric literal which is part of an addition expression: ``` use ruff_python_parser::parse_expression_range; # use ruff_text_size::{TextRange, TextSize}; let par
(
source: &str,
range: TextRange,
)
| 157 | /// assert!(parsed.is_ok()); |
| 158 | /// ``` |
| 159 | pub fn parse_expression_range( |
| 160 | source: &str, |
| 161 | range: TextRange, |
| 162 | ) -> Result<Parsed<ModExpression>, ParseError> { |
| 163 | let source = &source[..range.end().to_usize()]; |
| 164 | Parser::new_starts_at(source, range.start(), ParseOptions::from(Mode::Expression)) |
| 165 | .parse() |
| 166 | .try_into_expression() |
| 167 | .unwrap() |
| 168 | .into_result() |
| 169 | } |
| 170 | |
| 171 | /// Parses a Python expression as if it is parenthesized. |
| 172 | /// |
no test coverage detected