GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Docs.rs
  • rustpython-parser-0.4.0
  • Permalink
  • Docs.rs crate page
  • MIT
  • Repository
  • crates.io
  • Source
  • coolreader18
  • windelbouwman
  • github:rustpython:packaging
  • is-macro ^0.3.0 normal
  • itertools ^0.11.0 normal
  • lalrpop-util ^0.20.0 normal

This view

  • Original page
  • New address

GeezerVison is showing docs.rs — parse in rustpython_parser - Rust

rustpython_parser

Function parse 

Source
pub fn parse(
    source: &str,
    mode: Mode,
    source_path: &str,
) -> Result<Mod, ParseError>
Expand description

Parse the given Python source code using the specified Mode.

This function is the most general function to parse Python code. Based on the Mode supplied, it can be used to parse a single expression, a full Python program or an interactive expression.

§Example

If we want to parse a simple expression, we can use the Mode::Expression mode during parsing:

use rustpython_parser::{Mode, parse};

let expr = parse("1 + 2", Mode::Expression, "<embedded>");
assert!(expr.is_ok());

Alternatively, we can parse a full Python program consisting of multiple lines:

use rustpython_parser::{Mode, parse};

let source = r#"
class Greeter:

  def greet(self):
   print("Hello, world!")
"#;
let program = parse(source, Mode::Module, "<embedded>");
assert!(program.is_ok());
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.