mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Auto merge of #17139 - emilio:parsing-simplify, r=nox
style: Simplify a bit the parsing code. I plan to simplify it further, but this is worth landing on its own. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17139) <!-- Reviewable:end -->
This commit is contained in:
commit
fa158a78b6
3 changed files with 247 additions and 169 deletions
|
@ -1311,23 +1311,25 @@ impl Parse for Attr {
|
|||
|
||||
#[cfg(feature = "gecko")]
|
||||
/// Get the namespace id from the namespace map
|
||||
pub fn get_id_for_namespace(namespace: &Namespace, context: &ParserContext) -> Result<NamespaceId, ()> {
|
||||
if let Some(map) = context.namespaces {
|
||||
if let Some(ref entry) = map.read().prefixes.get(&namespace.0) {
|
||||
Ok(entry.1)
|
||||
} else {
|
||||
Err(())
|
||||
fn get_id_for_namespace(namespace: &Namespace, context: &ParserContext) -> Result<NamespaceId, ()> {
|
||||
let namespaces_map = match context.namespaces {
|
||||
Some(map) => map,
|
||||
None => {
|
||||
// If we don't have a namespace map (e.g. in inline styles)
|
||||
// we can't parse namespaces
|
||||
return Err(());
|
||||
}
|
||||
} else {
|
||||
// if we don't have a namespace map (e.g. in inline styles)
|
||||
// we can't parse namespaces
|
||||
Err(())
|
||||
};
|
||||
|
||||
match namespaces_map.prefixes.get(&namespace.0) {
|
||||
Some(entry) => Ok(entry.1),
|
||||
None => Err(()),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
/// Get the namespace id from the namespace map
|
||||
pub fn get_id_for_namespace(_: &Namespace, _: &ParserContext) -> Result<NamespaceId, ()> {
|
||||
fn get_id_for_namespace(_: &Namespace, _: &ParserContext) -> Result<NamespaceId, ()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -1340,27 +1342,28 @@ impl Attr {
|
|||
let first = input.try(|i| i.expect_ident()).ok();
|
||||
if let Ok(token) = input.try(|i| i.next_including_whitespace()) {
|
||||
match token {
|
||||
Token::Delim('|') => {
|
||||
// must be followed by an ident
|
||||
let second_token = match input.next_including_whitespace()? {
|
||||
Token::Ident(second) => second,
|
||||
_ => return Err(()),
|
||||
};
|
||||
let ns_with_id = if let Some(ns) = first {
|
||||
let ns: Namespace = ns.into();
|
||||
let id = get_id_for_namespace(&ns, context)?;
|
||||
Some((ns, id))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
return Ok(Attr {
|
||||
namespace: ns_with_id,
|
||||
attribute: second_token.into_owned(),
|
||||
})
|
||||
}
|
||||
_ => return Err(())
|
||||
Token::Delim('|') => {}
|
||||
_ => return Err(()),
|
||||
}
|
||||
// must be followed by an ident
|
||||
let second_token = match input.next_including_whitespace()? {
|
||||
Token::Ident(second) => second,
|
||||
_ => return Err(()),
|
||||
};
|
||||
|
||||
let ns_with_id = if let Some(ns) = first {
|
||||
let ns: Namespace = ns.into();
|
||||
let id = get_id_for_namespace(&ns, context)?;
|
||||
Some((ns, id))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
return Ok(Attr {
|
||||
namespace: ns_with_id,
|
||||
attribute: second_token.into_owned(),
|
||||
})
|
||||
}
|
||||
|
||||
if let Some(first) = first {
|
||||
Ok(Attr {
|
||||
namespace: None,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue