Skip to content

Continuation PR for #256: Implement std::error::Error for errors #262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Prev Previous commit
Next Next commit
Process CR and simplyly the PR
  • Loading branch information
dutchmartin committed Apr 27, 2020
commit 9b2246cb9a35dd8f15a5fee4f578005606a5b19f
56 changes: 28 additions & 28 deletions procedural-masquerade/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,33 +244,33 @@ macro_rules! define_invoke_proc_macro {
#[doc(hidden)]
#[macro_export]
macro_rules! $macro_name {
($proc_macro_name: ident ! $paren: tt) => {
#[derive($proc_macro_name)]
#[allow(unused)]
enum ProceduralMasqueradeDummyType {
// The magic happens here.
//
// We use an `enum` with an explicit discriminant
// because that is the only case where a type definition
// can contain a (const) expression.
//
// `(0, "foo").0` evalutes to 0, with the `"foo"` part ignored.
//
// By the time the `#[proc_macro_derive]` function
// implementing `#[derive($proc_macro_name)]` is called,
// `$paren` has already been replaced with the input of this inner macro,
// but `stringify!` has not been expanded yet.
//
// This how arbitrary tokens can be inserted
// in the input to the `#[proc_macro_derive]` function.
//
// Later, `stringify!(...)` is expanded into a string literal
// which is then ignored.
// Using `stringify!` enables passing arbitrary tokens
// rather than only what can be parsed as a const expression.
Input = (0, stringify! $paren ).0
}
}
}
($proc_macro_name: ident ! $paren: tt) => {
#[derive($proc_macro_name)]
#[allow(unused)]
enum ProceduralMasqueradeDummyType {
// The magic happens here.
//
// We use an `enum` with an explicit discriminant
// because that is the only case where a type definition
// can contain a (const) expression.
//
// `(0, "foo").0` evalutes to 0, with the `"foo"` part ignored.
//
// By the time the `#[proc_macro_derive]` function
// implementing `#[derive($proc_macro_name)]` is called,
// `$paren` has already been replaced with the input of this inner macro,
// but `stringify!` has not been expanded yet.
//
// This how arbitrary tokens can be inserted
// in the input to the `#[proc_macro_derive]` function.
//
// Later, `stringify!(...)` is expanded into a string literal
// which is then ignored.
// Using `stringify!` enables passing arbitrary tokens
// rather than only what can be parsed as a const expression.
Input = (0, stringify! $paren ).0
}
}
}
};
}
2 changes: 1 addition & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl<'i> BasicParseErrorKind<'i> {
fn description(&self) -> String {
match self {
Copy link
Member

Choose a reason for hiding this comment

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

Can we move this to Display::fmt?

Choose a reason for hiding this comment

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

Addressed in the last commit

BasicParseErrorKind::UnexpectedToken(token) => {
format!("Unexpected token: '{}'", token.description())
format!("Unexpected token: {:?}", token)
}
BasicParseErrorKind::EndOfInput => "End of input".to_owned(),
BasicParseErrorKind::AtRuleInvalid(message) => format!("Invalid @ rule: {}", message),
Expand Down
62 changes: 0 additions & 62 deletions src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,68 +191,6 @@ impl<'a> Token<'a> {
BadUrl(_) | BadString(_) | CloseParenthesis | CloseSquareBracket | CloseCurlyBracket
)
}

pub(crate) fn description(&self) -> String {
match self {
Ident(name) => format!("A ident token '{}'", name),
AtKeyword(value) => format!("The value '{}' does not include the `@` marker", value),
Hash(value) => format!("The value '{}' does not include the `#` marker", value),
IDHash(value) => format!(
"The value '{}' does not include the `#` marker, but has a valid ID selector",
value
),
QuotedString(value) => format!("The value '{}' does not include the quotes", value),
UnquotedUrl(value) => format!(
"The value '{}' does not include the `url(` `)` markers.",
value
),
Delim(character) => format!("'{}'", character),
Number {
has_sign, value, ..
} => {
let sign = if has_sign.clone() { '-' } else { '+' };
format!("{}{}", sign, value.to_string())
}
Percentage {
has_sign,
unit_value,
..
} => {
let sign = if has_sign.clone() { '-' } else { '+' };
format!("{}{}%", sign, unit_value.to_string())
}
Dimension {
has_sign,
value,
unit,
..
} => {
let sign = if has_sign.clone() { '-' } else { '+' };
format!("{}{} {}", sign, value.to_string(), unit)
}
WhiteSpace(whitespace) => format!("whitespace: '{}'", whitespace),
Comment(comment) => format!("The comment: '{}'", comment),
Colon => String::from(":"),
Semicolon => String::from(";"),
Comma => String::from(","),
IncludeMatch => String::from("~="),
DashMatch => String::from("|="),
PrefixMatch => String::from("^="),
SuffixMatch => String::from("$="),
SubstringMatch => String::from("*="),
CDO => String::from("<!--"),
CDC => String::from("-->"),
Function(name) => format!("The value ({}) does not include the `(` marker", name),
ParenthesisBlock => String::from("("),
SquareBracketBlock => String::from("["),
CurlyBracketBlock => String::from("{"),
BadUrl(url) => format!("Bad url: '{}'", url),
BadString(string) => format!("Bad string: '{}'", string),
CloseParenthesis => "Unclosed parenthesis".to_owned(),
CloseSquareBracket => "Unclosed square bracket".to_owned(),
CloseCurlyBracket => "Unclosed curly bracket".to_owned(),
}
}
}

#[derive(Clone)]
Expand Down