Skip to content

Conversation

sanxiyn
Copy link
Contributor

@sanxiyn sanxiyn commented Oct 11, 2019

cc #1385

LalrpopError::UnrecognizedToken { token, expected } => {
// Hacky, but it's how CPython does it. See PyParser_AddToken,
// in particular "Only one possible expected token" comment.
let expected = if expected.len() == 1 {
Copy link
Contributor

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.

Copy link
Contributor Author

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 if expected has more than two elements.

Copy link
Contributor

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!

@@ -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() {
Copy link
Contributor

@windelbouwman windelbouwman Oct 11, 2019

Choose a reason for hiding this comment

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

Instead of using a sequence of if statements, we could use here match statements on the error variable to check all it's variants.

I would prefer to use here match indeed, to create the proper matching python error based upon the CompilerErrorType variant, and even the inner LexicalErrorType.

match error {
    CompilerErrorType::ParseError(parse) => {
        match parse {
            .... => self.ctx.exceptions.indentation_error.clone(),
            .... => self.ctx.exceptions.tab_error.clone(),

        }
    },
    ... => syntaxError.clone()
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

@sanxiyn
Copy link
Contributor Author

sanxiyn commented Oct 11, 2019

I took suggestions for compiler/src/error.rs. Thanks!

@windelbouwman windelbouwman merged commit 242f0ff into RustPython:master Oct 12, 2019
@sanxiyn sanxiyn deleted the indent branch October 12, 2019 22:59
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