-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'refs/heads/main' into fork/crowlKats/hasRegExpGroups
- Loading branch information
Showing
10 changed files
with
97 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,80 @@ | ||
use derive_more::Display; | ||
use std::fmt; | ||
|
||
use crate::tokenizer::TokenType; | ||
|
||
/// A error occurring during URL pattern construction, or matching. | ||
#[derive(Display)] | ||
#[derive(Debug)] | ||
pub enum Error { | ||
#[display(fmt = "a relative input without a base URL is not valid")] | ||
BaseUrlRequired, | ||
|
||
#[display( | ||
fmt = "specifying both an init object, and a separate base URL is not valid" | ||
)] | ||
BaseUrlWithInit, | ||
|
||
#[display(fmt = "tokenizer error: {_0} (at char {_1})")] | ||
Tokenizer(TokenizerError, usize), | ||
|
||
#[display(fmt = "parser error: {_0}")] | ||
Parser(ParserError), | ||
|
||
Url(url::ParseError), | ||
|
||
#[display(fmt = "regexp error")] | ||
RegExp(()), | ||
} | ||
|
||
impl std::error::Error for Error {} | ||
|
||
impl std::fmt::Debug for Error { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
std::fmt::Display::fmt(self, f) | ||
impl fmt::Display for Error { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
Error::BaseUrlRequired => { | ||
f.write_str("a relative input without a base URL is not valid") | ||
} | ||
Error::BaseUrlWithInit => f.write_str( | ||
"specifying both an init object, and a separate base URL is not valid", | ||
), | ||
Error::Tokenizer(err, pos) => { | ||
write!(f, "tokenizer error: {err} (at char {pos})") | ||
} | ||
Error::Parser(err) => write!(f, "parser error: {err}"), | ||
Error::Url(err) => err.fmt(f), | ||
Error::RegExp(_) => f.write_str("regexp error"), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Display)] | ||
impl std::error::Error for Error {} | ||
|
||
#[derive(Debug)] | ||
pub enum TokenizerError { | ||
#[display(fmt = "incomplete escape code")] | ||
IncompleteEscapeCode, | ||
#[display(fmt = "invalid name; must be at least length 1")] | ||
InvalidName, | ||
#[display(fmt = "invalid regex: {_0}")] | ||
InvalidRegex(&'static str), | ||
} | ||
|
||
#[derive(Debug, Display)] | ||
impl fmt::Display for TokenizerError { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
Self::IncompleteEscapeCode => f.write_str("incomplete escape code"), | ||
Self::InvalidName => { | ||
f.write_str("invalid name; must be at least length 1") | ||
} | ||
Self::InvalidRegex(err) => write!(f, "invalid regex: {err}"), | ||
} | ||
} | ||
} | ||
|
||
impl std::error::Error for TokenizerError {} | ||
|
||
#[derive(Debug)] | ||
pub enum ParserError { | ||
#[display(fmt = "expected token {_0}, found '{_2}' of type {_1}")] | ||
ExpectedToken(TokenType, TokenType, String), | ||
|
||
#[display(fmt = "pattern contains duplicate name {_0}")] | ||
DuplicateName(String), | ||
} | ||
|
||
impl fmt::Display for ParserError { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
Self::ExpectedToken(expected_ty, found_ty, found_val) => { | ||
write!( | ||
f, | ||
"expected token {expected_ty:?}, found '{found_val}' of type {found_ty:?}" | ||
) | ||
} | ||
Self::DuplicateName(name) => { | ||
write!(f, "pattern contains duplicate name {name}") | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl std::error::Error for ParserError {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters