Skip to content
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

Error wrapping #183

Merged
merged 21 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions src/css.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,8 @@ impl Selector {
false
}
SelectorComponent::Element(name) => match &node.data {
Element { name: eltname, .. } => {
if name == eltname.expanded().local.deref() {
Self::do_matches(&comps[1..], node)
} else {
false
}
Element { name: eltname, .. } if name == eltname.expanded().local.deref() => {
Self::do_matches(&comps[1..], node)
}
_ => false,
},
Expand Down Expand Up @@ -306,11 +302,11 @@ impl StyleData {

pub(crate) fn computed_style(
&self,
parent_style: &ComputedStyle,
parent_style: ComputedStyle,
handle: &Handle,
use_doc_css: bool,
) -> ComputedStyle {
let mut result = *parent_style;
let mut result = parent_style;

for (origin, ruleset) in [
(StyleOrigin::Agent, &self.agent_rules),
Expand Down Expand Up @@ -425,9 +421,9 @@ impl StyleData {
}
}

fn pending<'a, F>(handle: Handle, f: F) -> TreeMapResult<'a, (), Handle, Vec<String>>
fn pending<F>(handle: Handle, f: F) -> TreeMapResult<'static, (), Handle, Vec<String>>
where
for<'r> F: Fn(&'r mut (), Vec<Vec<String>>) -> Result<Option<Vec<String>>> + 'static,
F: Fn(&mut (), Vec<Vec<String>>) -> Result<Option<Vec<String>>> + 'static,
{
TreeMapResult::PendingChildren {
children: handle.children.borrow().clone(),
Expand All @@ -451,10 +447,10 @@ fn combine_vecs(vecs: Vec<Vec<String>>) -> Vec<String> {
}
}

fn extract_style_nodes<'a, T: Write>(
fn extract_style_nodes<T: Write>(
handle: Handle,
_err_out: &mut T,
) -> TreeMapResult<'a, (), Handle, Vec<String>> {
) -> TreeMapResult<'static, (), Handle, Vec<String>> {
use TreeMapResult::*;

match handle.clone().data {
Expand All @@ -467,7 +463,7 @@ fn extract_style_nodes<'a, T: Write>(
// Assume just a flat text node
for child in handle.children.borrow().iter() {
if let NodeData::Text { ref contents } = child.data {
result += &String::from(contents.borrow().deref());
result += &contents.borrow();
}
}
Finished(vec![result])
Expand Down
33 changes: 15 additions & 18 deletions src/css/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,12 @@ fn parse_token_not_semicolon(text: &str) -> IResult<&str, Token> {
fn parse_value(text: &str) -> IResult<&str, RawValue> {
let (rest, mut tokens) = many0(parse_token_not_semicolon)(text)?;
let mut important = false;
if tokens.len() >= 2
&& tokens[tokens.len() - 2..] == [Token::Delim('!'), Token::Ident("important".into())]
{
tokens.pop();
tokens.pop();
important = true;
if let [.., Token::Delim('!'), Token::Ident(x)] = &tokens[..] {
if x == "important" {
tokens.pop();
tokens.pop();
important = true;
}
}
Ok((rest, RawValue { tokens, important }))
}
Expand Down Expand Up @@ -492,21 +492,18 @@ fn parse_color(tokens: &[Token]) -> Result<Colour, nom::Err<nom::error::Error<&'
};
Ok(colour)
}
[Token::Function(name), .., Token::CloseRound] => {
[Token::Function(name), rgb_args @ .., Token::CloseRound] => {
use Token::*;
match name.deref() {
"rgb" => {
let rgb_args = &tokens[1..tokens.len() - 1];
match rgb_args {
[Number(r), Comma, Number(g), Comma, Number(b)] => {
let r = r.parse().map_err(|_e| empty_fail())?;
let g = g.parse().map_err(|_e| empty_fail())?;
let b = b.parse().map_err(|_e| empty_fail())?;
Ok(Colour::Rgb(r, g, b))
}
_ => Err(empty_fail()),
"rgb" => match rgb_args {
[Number(r), Comma, Number(g), Comma, Number(b)] => {
let r = r.parse().map_err(|_e| empty_fail())?;
let g = g.parse().map_err(|_e| empty_fail())?;
let b = b.parse().map_err(|_e| empty_fail())?;
Ok(Colour::Rgb(r, g, b))
}
}
_ => Err(empty_fail()),
},
_ => Err(empty_fail()),
}
}
Expand Down
Loading
Loading