style: Add a struct to represent import rules, and parse them correctly.

This commit is contained in:
Emilio Cobos Álvarez 2016-12-16 12:05:19 +01:00
parent e5d783c454
commit 444fef164e
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
3 changed files with 103 additions and 7 deletions

View file

@ -11,6 +11,7 @@ use parser::{Parse, ParserContext};
#[cfg(feature = "gecko")]
use parser::ParserContextExtraData;
use servo_url::ServoUrl;
use std::borrow::Cow;
use std::fmt::{self, Write};
use std::ptr;
use std::sync::Arc;
@ -76,7 +77,14 @@ pub struct SpecifiedUrl {
impl Parse for SpecifiedUrl {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
let url = try!(input.expect_url());
Self::parse_from_string(url, context)
}
}
impl SpecifiedUrl {
pub fn parse_from_string<'a>(url: Cow<'a, str>,
context: &ParserContext)
-> Result<Self, ()> {
let extra_data = match UrlExtraData::make_from(context) {
Some(extra_data) => extra_data,
None => {
@ -96,9 +104,7 @@ impl Parse for SpecifiedUrl {
extra_data: extra_data,
})
}
}
impl SpecifiedUrl {
pub fn extra_data(&self) -> &UrlExtraData {
&self.extra_data
}