mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Upgrade to rust-cssparser master.
* Use associated types * Avoid mutation to gather parsing results.
This commit is contained in:
parent
7359f99f20
commit
966af0030a
11 changed files with 183 additions and 165 deletions
|
@ -52,13 +52,21 @@ pub struct FontFaceRule {
|
|||
|
||||
pub fn parse_font_face_block(context: &ParserContext, input: &mut Parser)
|
||||
-> Result<FontFaceRule, ()> {
|
||||
let parser = FontFaceRuleParser {
|
||||
context: context,
|
||||
family: None,
|
||||
src: None,
|
||||
};
|
||||
match DeclarationListParser::new(input, parser).run() {
|
||||
FontFaceRuleParser { family: Some(family), src: Some(src), .. } => {
|
||||
let mut family = None;
|
||||
let mut src = None;
|
||||
for declaration in DeclarationListParser::new(input, FontFaceRuleParser { context: context }) {
|
||||
match declaration {
|
||||
Err(()) => {}
|
||||
Ok(FontFaceDescriptorDeclaration::Family(value)) => {
|
||||
family = Some(value);
|
||||
}
|
||||
Ok(FontFaceDescriptorDeclaration::Src(value)) => {
|
||||
src = Some(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
match (family, src) {
|
||||
(Some(family), Some(src)) => {
|
||||
Ok(FontFaceRule {
|
||||
family: family,
|
||||
sources: src,
|
||||
|
@ -68,30 +76,36 @@ pub fn parse_font_face_block(context: &ParserContext, input: &mut Parser)
|
|||
}
|
||||
}
|
||||
|
||||
enum FontFaceDescriptorDeclaration {
|
||||
Family(String),
|
||||
Src(Vec<Source>),
|
||||
}
|
||||
|
||||
|
||||
struct FontFaceRuleParser<'a, 'b: 'a> {
|
||||
context: &'a ParserContext<'b>,
|
||||
family: Option<String>,
|
||||
src: Option<Vec<Source>>,
|
||||
}
|
||||
|
||||
|
||||
/// Default methods reject all at rules.
|
||||
impl<'a, 'b> AtRuleParser<(), ()> for FontFaceRuleParser<'a, 'b> {}
|
||||
impl<'a, 'b> AtRuleParser for FontFaceRuleParser<'a, 'b> {
|
||||
type Prelude = ();
|
||||
type AtRule = FontFaceDescriptorDeclaration;
|
||||
}
|
||||
|
||||
|
||||
impl<'a, 'b> DeclarationParser<()> for FontFaceRuleParser<'a, 'b> {
|
||||
fn parse_value(&mut self, name: &str, input: &mut Parser) -> Result<(), ()> {
|
||||
impl<'a, 'b> DeclarationParser for FontFaceRuleParser<'a, 'b> {
|
||||
type Declaration = FontFaceDescriptorDeclaration;
|
||||
|
||||
fn parse_value(&self, name: &str, input: &mut Parser) -> Result<FontFaceDescriptorDeclaration, ()> {
|
||||
match_ignore_ascii_case! { name,
|
||||
"font-family" => {
|
||||
self.family = Some(try!(parse_one_non_generic_family_name(input)));
|
||||
Ok(())
|
||||
Ok(FontFaceDescriptorDeclaration::Family(try!(parse_one_non_generic_family_name(input))))
|
||||
},
|
||||
"src" => {
|
||||
self.src = Some(try!(input.parse_comma_separated(|input| {
|
||||
Ok(FontFaceDescriptorDeclaration::Src(try!(input.parse_comma_separated(|input| {
|
||||
parse_one_src(self.context, input)
|
||||
})));
|
||||
Ok(())
|
||||
}))))
|
||||
}
|
||||
_ => Err(())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue