Skip to content

Use ast::Suite::parse instead of deprecated parse_program. #5186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions compiler/codegen/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2941,7 +2941,8 @@ impl ToU32 for usize {
#[cfg(test)]
mod tests {
use super::*;
use rustpython_parser as parser;
use rustpython_parser::ast::Suite;
use rustpython_parser::Parse;
use rustpython_parser_core::source_code::LinearLocator;

fn compile_exec(source: &str) -> CodeObject {
Expand All @@ -2952,7 +2953,7 @@ mod tests {
"source_path".to_owned(),
"<module>".to_owned(),
);
let ast = parser::parse_program(source, "<test>").unwrap();
let ast = Suite::parse(source, "<test>").unwrap();
let ast = locator.fold(ast).unwrap();
let symbol_scope = SymbolTable::scan_program(&ast).unwrap();
compiler.compile_program(&ast, symbol_scope).unwrap();
Expand Down
6 changes: 3 additions & 3 deletions examples/parse_folder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extern crate env_logger;
extern crate log;

use clap::{App, Arg};
use rustpython_parser::{self as parser, ast};
use rustpython_parser::{self as parser, ast, Parse};
use std::{
path::Path,
time::{Duration, Instant},
Expand Down Expand Up @@ -85,8 +85,8 @@ fn parse_python_file(filename: &Path) -> ParsedFile {
},
Ok(source) => {
let num_lines = source.lines().count();
let result = parser::parse_program(&source, &filename.to_string_lossy())
.map_err(|e| e.to_string());
let result =
ast::Suite::parse(&source, &filename.to_string_lossy()).map_err(|e| e.to_string());
ParsedFile {
// filename: Box::new(filename.to_path_buf()),
// code: source.to_string(),
Expand Down