-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Implement IndentationError #1512
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -416,7 +416,9 @@ impl VirtualMachine { | |
|
||
#[cfg(feature = "rustpython-compiler")] | ||
pub fn new_syntax_error(&self, error: &CompileError) -> PyObjectRef { | ||
let syntax_error_type = if error.is_tab_error() { | ||
let syntax_error_type = if error.is_indentation_error() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of using a sequence of I would prefer to use here match indeed, to create the proper matching python error based upon the match error {
CompilerErrorType::ParseError(parse) => {
match parse {
.... => self.ctx.exceptions.indentation_error.clone(),
.... => self.ctx.exceptions.tab_error.clone(),
}
},
... => syntaxError.clone()
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The main motivation of current design is to simplify compiler/VM public interface. In a sense {CompilerErrorType, ParseErrorType, LexicalErrorType} really are internal implementation details, the only thing VM needs is exception type, message, and location. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand the motivation, but I still feel, the vm is so much connected to the parser, it is actually fine to leak the internals of the parser into the vm code. In any case, let's go with the current design. |
||
self.ctx.exceptions.indentation_error.clone() | ||
} else if error.is_tab_error() { | ||
self.ctx.exceptions.tab_error.clone() | ||
} else { | ||
self.ctx.exceptions.syntax_error.clone() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be an opportunity to use the
first
function.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, because the intent is to get
None
ifexpected
has more than two elements.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, okay, I understand. Thank you!