mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-24 21:44:45 +00:00
Merge pull request #4409 from harupy/improve-error-conversion-in-string-parser
Improve error conversion in `string_parsers.rs`
This commit is contained in:
commit
2858c315bf
2 changed files with 116 additions and 89 deletions
|
@ -12,6 +12,12 @@ pub struct LexicalError {
|
|||
pub location: Location,
|
||||
}
|
||||
|
||||
impl LexicalError {
|
||||
pub fn new(error: LexicalErrorType, location: Location) -> Self {
|
||||
Self { error, location }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum LexicalErrorType {
|
||||
StringError,
|
||||
|
@ -85,6 +91,21 @@ pub struct FStringError {
|
|||
pub location: Location,
|
||||
}
|
||||
|
||||
impl FStringError {
|
||||
pub fn new(error: FStringErrorType, location: Location) -> Self {
|
||||
Self { error, location }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<FStringError> for LexicalError {
|
||||
fn from(err: FStringError) -> Self {
|
||||
LexicalError {
|
||||
error: LexicalErrorType::FStringError(err.error),
|
||||
location: err.location,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum FStringErrorType {
|
||||
UnclosedLbrace,
|
||||
|
@ -101,15 +122,6 @@ pub enum FStringErrorType {
|
|||
UnterminatedString,
|
||||
}
|
||||
|
||||
impl FStringErrorType {
|
||||
pub fn to_lexical_error(self, location: Location) -> LexicalError {
|
||||
LexicalError {
|
||||
error: LexicalErrorType::FStringError(self),
|
||||
location,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for FStringErrorType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue