Pass more information in user defined parse error#1106
Pass more information in user defined parse error#1106windelbouwman merged 3 commits intoRustPython:masterfrom
Conversation
compiler/src/error.rs
Outdated
| // Print line number: | ||
| write!(f, " at line {:?}", self.location.row()) | ||
| match &self.error { | ||
| CompileErrorType::Parse(..) => Ok(()), |
There was a problem hiding this comment.
Hmm. This exception for the parse error is not ideal, but we can improve on this later.
There was a problem hiding this comment.
Please implement the todo at this line:
RustPython/compiler/src/error.rs
Line 17 in ef1d543
Then we have proper locations on all compiler errors (where possible).
parser/src/error.rs
Outdated
| UnrecognizedToken(TokSpan, Vec<String>), | ||
| /// Maps to `User` type from `lalrpop-util` | ||
| Other, | ||
| Other(LexicalError), |
There was a problem hiding this comment.
It might be good to rename this error variant into Lexical(LexicalError).
parser/src/error.rs
Outdated
| 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), |
There was a problem hiding this comment.
This is very good to propagate the lexer errors!
parser/src/lexer.rs
Outdated
| } | ||
| LexicalErrorType::OtherError(ref msg) => write!(f, "{}", msg), | ||
| }?; | ||
| write!( |
There was a problem hiding this comment.
I would prefer to add the line and column info later on, so in the Display method of the CompilerError struct.
|
This change looks very good now. The only thing left is to take a look at the wasm build. |
|
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 0Not sure why the |
| ); | ||
| } | ||
| } | ||
| let _ = |
There was a problem hiding this comment.
Well, adding the location attribute clearly was beneficial!
Before the message was:
And now it is: