Skip to main content

parse_module

Function parse_module 

Source
pub fn parse_module(source: &str) -> Result<Parsed<ModModule>, ParseError>
Expand description

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 = r#"
def foo():
   return 42

print(foo())
"#;

let module = parse_module(source);
assert!(module.is_ok());