Skip to content

Conversation

@palaviv
Copy link
Contributor

@palaviv palaviv commented Jul 5, 2019

Before the message was:

Traceback (most recent call last):
SyntaxError: 'Got unsupported token(s) at line 0'

And now it is:

Traceback (most recent call last):
SyntaxError: 'Got unexpected token \t at line 4 column 25'

@palaviv palaviv requested a review from windelbouwman July 5, 2019 08:04
// Print line number:
write!(f, " at line {:?}", self.location.row())
match &self.error {
CompileErrorType::Parse(..) => Ok(()),
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. This exception for the parse error is not ideal, but we can improve on this later.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please implement the todo at this line:

location: Default::default(), // TODO: extract location from parse error!

Then we have proper locations on all compiler errors (where possible).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

UnrecognizedToken(TokSpan, Vec<String>),
/// Maps to `User` type from `lalrpop-util`
Other,
Other(LexicalError),
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be good to rename this error variant into Lexical(LexicalError).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

InnerError::ExtraToken { token } => ParseError::ExtraToken(token),
// Inner field is a unit-like enum `LexicalError::StringError` with no useful info
InnerError::User { .. } => ParseError::Other,
InnerError::User { error } => ParseError::Other(error),
Copy link
Contributor

Choose a reason for hiding this comment

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

This is very good to propagate the lexer errors!

}
LexicalErrorType::OtherError(ref msg) => write!(f, "{}", msg),
}?;
write!(
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 prefer to add the line and column info later on, so in the Display method of the CompilerError struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@windelbouwman
Copy link
Contributor

This change looks very good now. The only thing left is to take a look at the wasm build.

@palaviv
Copy link
Contributor Author

palaviv commented Jul 6, 2019

I am trying to fix the wasm but the error currently look like:

SyntaxError: Error parsing Python code: Got unexpected token: DoubleStar at Location { row: 1, column: 8 } at line 0

Not sure why the fmt::Display I defined is not working.

);
}
}
let _ =
Copy link
Contributor

Choose a reason for hiding this comment

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

Well, adding the location attribute clearly was beneficial!

@windelbouwman windelbouwman merged commit 70c2054 into RustPython:master Jul 6, 2019
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