8000 Expose a method to parse AST from tokens directly by charliermarsh · Pull Request #4229 · RustPython/RustPython · GitHub
[go: up one dir, main page]

Skip to content

Expose a method to parse AST from tokens directly #4229

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 2 commits into from
Oct 17, 2022

Conversation

charliermarsh
Copy link
Collaborator

I'm using this in Ruff where it's useful to be able to generate the token stream once upfront, use it in a few places, then pass it to the parser without re-tokenizing the entire stream.

@@ -5,9 +5,11 @@
//! parse a whole program, a single statement, or a single
//! expression.

use std::iter;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

we like to depend on formatter than human

@@ -23,6 +25,17 @@ pub fn parse_program(source: &str, source_path: &str) -> Result<ast::Suite, Pars
})
}

/// Parse the token stream for a full python program.
pub fn parse_program_tokens(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand we'd better to add parse_tokens for some use case. But parse_program_tokens too?
This is a very specific use case which can be also covered by parse_program_tokens.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

@youknowone youknowone merged commit 8fbab2e into RustPython:main Oct 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0