MCPcopy Create free account
hub / github.com/astral-sh/ruff / parse_expression

Function parse_expression

crates/ruff_python_parser/src/lib.rs:135–141  ·  view source on GitHub ↗

Parses a single Python expression. This convenience function can be used to parse a single expression without having to specify the Mode or the location. # Example For example, parsing a single expression denoting the addition of two numbers: ``` use ruff_python_parser::parse_expression; let expr = parse_expression("1 + 2"); assert!(expr.is_ok()); ```

(source: &str)

Source from the content-addressed store, hash-verified

133/// assert!(expr.is_ok());
134/// ```
135pub fn parse_expression(source: &str) -> Result<Parsed<ModExpression>, ParseError> {
136 Parser::new(source, ParseOptions::from(Mode::Expression))
137 .parse()
138 .try_into_expression()
139 .unwrap()
140 .into_result()
141}
142
143/// Parses a Python expression for the given range in the source.
144///

Callers 15

parseFunction · 0.85
assert_comparableFunction · 0.85
assert_noncomparableFunction · 0.85
assert_hashable_equalFunction · 0.85
assert_hashable_unequalFunction · 0.85
test_parenthesized_nameFunction · 0.85

Calls 3

into_resultMethod · 0.80
try_into_expressionMethod · 0.80
parseMethod · 0.45