Skip to content

Conversation

youknowone
Copy link
Member

No description provided.

Lib/ast.py Outdated


# XXX: Rustpython _ast includes parse()
#def parse(source, filename='<unknown>', mode='exec'):
Copy link
Member

Choose a reason for hiding this comment

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

Our ast.parse doesn't include a mode argument, could you maybe modify builtin_compile to accept PyCF_ONLY_AST? You could match on the mode and use rustpython_parser::parser::parse_program for exec and single or rustpython_parser::parser::parse_expression for eval. Maybe also enable builtin_compile even when the feature is off but just throw a runtime error if the caller doesn't pass PyCF_ONLY_AST so that ast.parse still works.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would like to add the mode optional argument to the rust parse function. Note that the mode can be retrieve because mode implements FromStr now. Please refer to the builtin compile function how this is done.

@youknowone youknowone force-pushed the ast-module branch 2 times, most recently from 9aa51b5 to d521d54 Compare August 27, 2019 17:16
@youknowone youknowone changed the title Ast module (WIP) Ast module Aug 27, 2019
@youknowone youknowone changed the title (WIP) Ast module ast module Aug 27, 2019

// compile mode but defined here
#[derive(Clone, Copy)]
pub enum Mode {
Copy link
Contributor

@windelbouwman windelbouwman Aug 27, 2019

Choose a reason for hiding this comment

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

I'm not too sure that this Mode enum should be contained in the parser crate. I feel it has its place in the compiler crate (where it was). The new parse function can be place in near the compile function in the builtins.rs in the vm crate.

Rationale: the mode is really a compiler thing. The parser should not be aware of the concept of mode, only parse code.

Copy link
Member Author

Choose a reason for hiding this comment

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

It seems Mode should be defined out of compile.rs because ast.parse works without #[cfg(feature = "rustpython-compiler")]. Any idea?

Copy link
Member Author

Choose a reason for hiding this comment

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

@windelbouwman any advice for proper place about this?

Copy link
Contributor

Choose a reason for hiding this comment

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

ast.parse should not work without the compiler crate, since when you have the compiler crate, the parser crate is implied. Vice versa is not true, but I think it makes sense to excluse ast.parse when the compiler feature is disabled. So I think we should place Mode in mode.rs in the rustpython-compiler crate.

@@ -73,6 +73,50 @@ pub fn parse_expression(source: &str) -> Result<ast::Expression, ParseError> {
do_lalr_parsing!(source, Expression, StartExpression)
}

pub fn parse(source: &str, mode: Mode) -> Result<ast::Top, ParseError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest to move this function to the builtins.rs in the vm crate.

Copy link
Member

@coolreader18 coolreader18 Aug 27, 2019

Choose a reason for hiding this comment

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

Or maybe util.rs?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, agreed, but in any case, this function should reside in the vm crate, since it uses a compilation mode.

@youknowone youknowone force-pushed the ast-module branch 3 times, most recently from db09eb7 to f1691a7 Compare October 12, 2019 08:26
@windelbouwman windelbouwman merged commit 336364c into RustPython:master Oct 12, 2019
ChJR added a commit to ChJR/RustPython that referenced this pull request Oct 13, 2019
windelbouwman added a commit that referenced this pull request Oct 13, 2019
Add build compatibility with rustc 1.36.0 since #1318 merged
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.

3 participants