Remove RustPython fork (#523)

This commit is contained in:
Charlie Marsh 2022-10-30 18:04:05 -04:00 committed by GitHub
parent b060ae2f22
commit 2415d73260
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
173 changed files with 2071 additions and 2056 deletions

View file

@ -6,7 +6,10 @@ use std::path::Path;
use anyhow::Result;
#[cfg(not(target_family = "wasm"))]
use log::debug;
use rustpython_ast::{Mod, Suite};
use rustpython_parser::error::ParseError;
use rustpython_parser::lexer::LexResult;
use rustpython_parser::parser::Mode;
use rustpython_parser::{lexer, parser};
use crate::ast::types::Range;
@ -36,6 +39,17 @@ pub(crate) fn tokenize(contents: &str) -> Vec<LexResult> {
tokens
}
/// Parse a full Python program from its tokens.
pub(crate) fn parse_program_tokens(
lxr: Vec<LexResult>,
source_path: &str,
) -> Result<Suite, ParseError> {
parser::parse_tokens(lxr, Mode::Module, source_path).map(|top| match top {
Mod::Module { body, .. } => body,
_ => unreachable!(),
})
}
pub(crate) fn check_path(
path: &Path,
contents: &str,
@ -65,7 +79,7 @@ pub(crate) fn check_path(
.iter()
.any(|check_code| matches!(check_code.lint_source(), LintSource::AST))
{
match parser::parse_program_tokens(tokens, "<filename>") {
match parse_program_tokens(tokens, "<filename>") {
Ok(python_ast) => {
checks.extend(check_ast(&python_ast, &locator, settings, autofix, path))
}
@ -220,7 +234,7 @@ pub fn autoformat_path(path: &Path) -> Result<()> {
let tokens: Vec<LexResult> = tokenize(&contents);
// Generate the AST.
let python_ast = parser::parse_program_tokens(tokens, "<filename>")?;
let python_ast = parse_program_tokens(tokens, "<filename>")?;
let mut generator: SourceGenerator = Default::default();
generator.unparse_suite(&python_ast)?;
write(path, generator.generate()?)?;