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

Function parse_module

crates/ruff_python_parser/src/lib.rs:112–118  ·  view source on GitHub ↗

Parse a full Python module usually consisting of multiple lines. This is a convenience function that can be used to parse a full Python program without having to specify the [`Mode`] or the location. It is probably what you want to use most of the time. # Example For example, parsing a simple function definition and a call to that function: ``` use ruff_python_parser::parse_module; let source

(source: &str)

Source from the content-addressed store, hash-verified

110/// assert!(module.is_ok());
111/// ```
112pub fn parse_module(source: &str) -> Result<Parsed<ModModule>, ParseError> {
113 Parser::new(source, ParseOptions::from(Mode::Module))
114 .parse()
115 .try_into_module()
116 .unwrap()
117 .into_result()
118}
119
120/// Parses a single Python expression.
121///

Callers 15

visit_strMethod · 0.85
control_flow_graphFunction · 0.85
extract_else_rangeFunction · 0.85
extract_elif_else_rangeFunction · 0.85
test_no_parenthesesFunction · 0.85
test_single_parenthesesFunction · 0.85
test_double_parenthesesFunction · 0.85

Calls 3

into_resultMethod · 0.80
try_into_moduleMethod · 0.80
parseMethod · 0.45