Update cssparser to 0.18

https://github.com/servo/rust-cssparser/pull/171
This commit is contained in:
Simon Sapin 2017-07-20 21:03:53 +02:00
parent 30d6d6024b
commit eb98ae6e04
64 changed files with 541 additions and 512 deletions

View file

@ -7,7 +7,7 @@
#![deny(missing_docs)]
use context::QuirksMode;
use cssparser::{DeclarationListParser, parse_important, ParserInput, CompactCowStr};
use cssparser::{DeclarationListParser, parse_important, ParserInput, CowRcStr};
use cssparser::{Parser, AtRuleParser, DeclarationParser, Delimiter, ParseError as CssParseError};
use error_reporting::{ParseErrorReporter, ContextualParseError};
use parser::{ParserContext, log_css_error};
@ -945,7 +945,7 @@ impl<'a, 'b, 'i> DeclarationParser<'i> for PropertyDeclarationParser<'a, 'b> {
type Declaration = Importance;
type Error = SelectorParseError<'i, StyleParseError<'i>>;
fn parse_value<'t>(&mut self, name: CompactCowStr<'i>, input: &mut Parser<'i, 't>)
fn parse_value<'t>(&mut self, name: CowRcStr<'i>, input: &mut Parser<'i, 't>)
-> Result<Importance, ParseError<'i>> {
let id = match PropertyId::parse(&name) {
Ok(id) => id,

View file

@ -2808,7 +2808,7 @@ fn static_assert() {
if atom.is_empty() {
AnimationName(None)
} else {
AnimationName(Some(KeyframesName::from_ident(atom.to_string())))
AnimationName(Some(KeyframesName::from_ident(&atom.to_string())))
}
}
pub fn copy_animation_name_from(&mut self, other: &Self) {

View file

@ -286,7 +286,7 @@ impl TransitionProperty {
match supported {
Ok(Some(property)) => Ok(property),
Ok(None) => CustomIdent::from_ident(ident, &[]).map(TransitionProperty::Unsupported),
Err(()) => Err(SelectorParseError::UnexpectedIdent(ident).into()),
Err(()) => Err(SelectorParseError::UnexpectedIdent(ident.clone()).into()),
}
}

View file

@ -122,14 +122,14 @@ ${helpers.predefined_type("background-image", "ImageLayer",
pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<SpecifiedValue, ParseError<'i>> {
let ident = input.expect_ident()?;
let ident = input.expect_ident_cloned()?;
(match_ignore_ascii_case! { &ident,
"repeat-x" => Ok(SpecifiedValue::RepeatX),
"repeat-y" => Ok(SpecifiedValue::RepeatY),
_ => Err(()),
}).or_else(|()| {
let horizontal: Result<_, ParseError> = RepeatKeyword::from_ident(&ident)
.map_err(|()| SelectorParseError::UnexpectedIdent(ident).into());
.map_err(|()| SelectorParseError::UnexpectedIdent(ident.clone()).into());
let horizontal = horizontal?;
let vertical = input.try(RepeatKeyword::parse).ok();
Ok(SpecifiedValue::Other(horizontal, vertical))

View file

@ -1025,7 +1025,7 @@ ${helpers.predefined_type(
}
Ok(SpecifiedValue(Space::parse(input, |input| {
let function = input.expect_function()?;
let function = input.expect_function()?.clone();
input.parse_nested_block(|input| {
let result = match_ignore_ascii_case! { &function,
"matrix" => {
@ -1217,7 +1217,7 @@ ${helpers.predefined_type(
_ => Err(()),
};
result
.map_err(|()| StyleParseError::UnexpectedFunction(function).into())
.map_err(|()| StyleParseError::UnexpectedFunction(function.clone()).into())
})
})?))
}
@ -1764,7 +1764,7 @@ ${helpers.predefined_type("transform-origin",
return Ok(result)
}
while let Ok(name) = input.try(|input| input.expect_ident()) {
while let Ok(name) = input.try(|i| i.expect_ident_cloned()) {
let flag = match_ignore_ascii_case! { &name,
"layout" => Some(LAYOUT),
"style" => Some(STYLE),
@ -1773,7 +1773,7 @@ ${helpers.predefined_type("transform-origin",
};
let flag = match flag {
Some(flag) if !result.contains(flag) => flag,
_ => return Err(SelectorParseError::UnexpectedIdent(name).into())
_ => return Err(SelectorParseError::UnexpectedIdent(name.clone()).into())
};
result.insert(flag);
}
@ -1960,7 +1960,8 @@ ${helpers.predefined_type("shape-outside", "basic_shape::FloatAreaShape",
pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<SpecifiedValue, ParseError<'i>> {
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
// FIXME: remove clone() when lifetimes are non-lexical
try_match_ident_ignore_ascii_case! { input.expect_ident()?.clone(),
"auto" => Ok(TOUCH_ACTION_AUTO),
"none" => Ok(TOUCH_ACTION_NONE),
"manipulation" => Ok(TOUCH_ACTION_MANIPULATION),

View file

@ -134,7 +134,7 @@
if let Some(color) = color_name(&ident) {
Ok(*color)
} else {
Err(SelectorParseError::UnexpectedIdent(ident).into())
Err(SelectorParseError::UnexpectedIdent(ident.clone()).into())
}
}
}

View file

@ -179,21 +179,22 @@
continue;
}
% endif
match input.next() {
Ok(Token::QuotedString(value)) => {
content.push(ContentItem::String(value.into_owned()))
// FIXME: remove clone() when lifetimes are non-lexical
match input.next().map(|t| t.clone()) {
Ok(Token::QuotedString(ref value)) => {
content.push(ContentItem::String(value.as_ref().to_owned()))
}
Ok(Token::Function(name)) => {
Ok(Token::Function(ref name)) => {
let result = match_ignore_ascii_case! { &name,
"counter" => Some(input.parse_nested_block(|input| {
let name = input.expect_ident()?.into_owned();
let name = input.expect_ident()?.as_ref().to_owned();
let style = parse_counter_style(context, input);
Ok(ContentItem::Counter(name, style))
})),
"counters" => Some(input.parse_nested_block(|input| {
let name = input.expect_ident()?.into_owned();
let name = input.expect_ident()?.as_ref().to_owned();
input.expect_comma()?;
let separator = input.expect_string()?.into_owned();
let separator = input.expect_string()?.as_ref().to_owned();
let style = parse_counter_style(context, input);
Ok(ContentItem::Counters(name, separator, style))
})),
@ -206,10 +207,10 @@
};
match result {
Some(result) => content.push(result?),
None => return Err(StyleParseError::UnexpectedFunction(name).into())
None => return Err(StyleParseError::UnexpectedFunction(name.clone()).into())
}
}
Ok(Token::Ident(ident)) => {
Ok(Token::Ident(ref ident)) => {
let valid = match_ignore_ascii_case! { &ident,
"open-quote" => { content.push(ContentItem::OpenQuote); true },
"close-quote" => { content.push(ContentItem::CloseQuote); true },
@ -219,7 +220,7 @@
_ => false,
};
if !valid {
return Err(SelectorParseError::UnexpectedIdent(ident).into())
return Err(SelectorParseError::UnexpectedIdent(ident.clone()).into())
}
}
Err(_) => break,
@ -333,8 +334,8 @@
let mut counters = Vec::new();
loop {
let counter_name = match input.next() {
Ok(Token::Ident(ident)) => CustomIdent::from_ident(ident, &["none"])?,
Ok(t) => return Err(BasicParseError::UnexpectedToken(t).into()),
Ok(&Token::Ident(ref ident)) => CustomIdent::from_ident(ident, &["none"])?,
Ok(t) => return Err(BasicParseError::UnexpectedToken(t.clone()).into()),
Err(_) => break,
};
let counter_delta = input.try(|input| specified::parse_integer(context, input))

View file

@ -145,13 +145,13 @@ macro_rules! impl_gecko_keyword_conversions {
/// Parse a font-family value
pub fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
if let Ok(value) = input.try(|input| input.expect_string()) {
if let Ok(value) = input.try(|i| i.expect_string_cloned()) {
return Ok(FontFamily::FamilyName(FamilyName {
name: Atom::from(&*value),
quoted: true,
}))
}
let first_ident = input.expect_ident()?;
let first_ident = input.expect_ident()?.clone();
// FIXME(bholley): The fast thing to do here would be to look up the
// string (as lowercase) in the static atoms table. We don't have an
@ -181,7 +181,7 @@ macro_rules! impl_gecko_keyword_conversions {
_ => {}
}
let mut value = first_ident.into_owned();
let mut value = first_ident.as_ref().to_owned();
// These keywords are not allowed by themselves.
// The only way this value can be valid with with another keyword.
if css_wide_keyword {
@ -189,7 +189,7 @@ macro_rules! impl_gecko_keyword_conversions {
value.push_str(" ");
value.push_str(&ident);
}
while let Ok(ident) = input.try(|input| input.expect_ident()) {
while let Ok(ident) = input.try(|i| i.expect_ident_cloned()) {
value.push_str(" ");
value.push_str(&ident);
}
@ -1189,7 +1189,8 @@ ${helpers.single_keyword_system("font-variant-caps",
pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<SpecifiedValue, ParseError<'i>> {
let mut result = SpecifiedValue { weight: false, style: false };
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
// FIXME: remove clone() when lifetimes are non-lexical
try_match_ident_ignore_ascii_case! { input.expect_ident()?.clone(),
"none" => Ok(result),
"weight" => {
result.weight = true;
@ -1411,9 +1412,10 @@ ${helpers.single_keyword_system("font-kerning",
)
);
while let Ok(_) = input.try(|input| {
match input.next()? {
Token::Ident(ident) => {
if ident == "historical-forms" {
// FIXME: remove clone() when lifetimes are non-lexical
match input.next()?.clone() {
Token::Ident(ref ident) => {
if *ident == "historical-forms" {
check_if_parsed!(HISTORICAL_FORMS);
alternates.push(VariantAlternates::HistoricalForms);
Ok(())
@ -1421,7 +1423,7 @@ ${helpers.single_keyword_system("font-kerning",
return Err(StyleParseError::UnspecifiedError.into());
}
},
Token::Function(name) => {
Token::Function(ref name) => {
input.parse_nested_block(|i| {
match_ignore_ascii_case! { &name,
% for value in "swash stylistic ornaments annotation".split():
@ -2136,8 +2138,8 @@ https://drafts.csswg.org/css-fonts-4/#low-level-font-variation-settings-control-
if input.try(|input| input.expect_ident_matching("normal")).is_ok() {
Ok(SpecifiedValue::Normal)
} else {
input.expect_string().map(|cow| {
SpecifiedValue::Override(cow.into_owned())
input.expect_string().map(|s| {
SpecifiedValue::Override(s.as_ref().to_owned())
}).map_err(|e| e.into())
}
}

View file

@ -590,9 +590,9 @@ ${helpers.predefined_type(
return Ok(SpecifiedValue::None);
}
if let Ok(s) = input.try(|input| input.expect_string()) {
if let Ok(s) = input.try(|i| i.expect_string().map(|s| s.as_ref().to_owned())) {
// Handle <string>
return Ok(SpecifiedValue::String(s.into_owned()));
return Ok(SpecifiedValue::String(s));
}
// Handle a pair of keywords

View file

@ -94,7 +94,7 @@ ${helpers.single_keyword("list-style-position", "outside inside", animation_valu
Ok(if let Ok(style) = input.try(|i| CounterStyleOrNone::parse(context, i)) {
SpecifiedValue::CounterStyle(style)
} else {
SpecifiedValue::String(input.expect_string()?.into_owned())
SpecifiedValue::String(input.expect_string()?.as_ref().to_owned())
})
}
</%helpers:longhand>
@ -197,13 +197,13 @@ ${helpers.single_keyword("list-style-position", "outside inside", animation_valu
let mut quotes = Vec::new();
loop {
let first = match input.next() {
Ok(Token::QuotedString(value)) => value.into_owned(),
Ok(t) => return Err(BasicParseError::UnexpectedToken(t).into()),
Ok(&Token::QuotedString(ref value)) => value.as_ref().to_owned(),
Ok(t) => return Err(BasicParseError::UnexpectedToken(t.clone()).into()),
Err(_) => break,
};
let second = match input.next() {
Ok(Token::QuotedString(value)) => value.into_owned(),
Ok(t) => return Err(BasicParseError::UnexpectedToken(t).into()),
Ok(&Token::QuotedString(ref value)) => value.as_ref().to_owned(),
Ok(t) => return Err(BasicParseError::UnexpectedToken(t.clone()).into()),
Err(e) => return Err(e.into()),
};
quotes.push((first, second))

View file

@ -101,7 +101,7 @@
} else {
Cursor::from_css_keyword(&ident)
.map(computed_value::Keyword::Cursor)
.map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
.map_err(|()| SelectorParseError::UnexpectedIdent(ident.clone()).into())
}
}
}

View file

@ -361,7 +361,7 @@ ${helpers.predefined_type("object-position",
_ => false
};
if !success {
return Err(SelectorParseError::UnexpectedIdent(ident).into());
return Err(SelectorParseError::UnexpectedIdent(ident.clone()).into());
}
}
@ -463,8 +463,8 @@ ${helpers.predefined_type("object-position",
fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Self, ParseError<'i>> {
let mut strings = vec![];
while let Ok(string) = input.try(Parser::expect_string) {
strings.push(string.into_owned().into_boxed_str());
while let Ok(string) = input.try(|i| i.expect_string().map(|s| s.as_ref().into())) {
strings.push(string);
}
TemplateAreas::from_vec(strings)

View file

@ -117,17 +117,17 @@
impl Parse for Side {
fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Side, ParseError<'i>> {
match input.next()? {
Token::Ident(ident) => {
match *input.next()? {
Token::Ident(ref ident) => {
try_match_ident_ignore_ascii_case! { ident,
"clip" => Ok(Side::Clip),
"ellipsis" => Ok(Side::Ellipsis),
}
}
Token::QuotedString(v) => {
Ok(Side::String(v.into_owned().into_boxed_str()))
Token::QuotedString(ref v) => {
Ok(Side::String(v.as_ref().to_owned().into_boxed_str()))
}
other => Err(BasicParseError::UnexpectedToken(other).into()),
ref t => Err(BasicParseError::UnexpectedToken(t.clone()).into()),
}
}
}
@ -236,7 +236,7 @@ ${helpers.single_keyword("unicode-bidi",
"blink" => if result.contains(BLINK) { Err(()) }
else { empty = false; result.insert(BLINK); Ok(()) },
_ => Err(())
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident.clone()).into())
}
Err(e) => return Err(e.into())
}

View file

@ -422,7 +422,7 @@ impl CSSWideKeyword {
impl Parse for CSSWideKeyword {
fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
let ident = input.expect_ident()?;
let ident = input.expect_ident()?.clone();
input.expect_exhausted()?;
CSSWideKeyword::from_ident(&ident)
.ok_or(SelectorParseError::UnexpectedIdent(ident).into())

View file

@ -278,12 +278,11 @@
% endfor
let first_line_names = input.try(parse_line_names).unwrap_or(vec![].into_boxed_slice());
if let Ok(s) = input.try(Parser::expect_string) {
if let Ok(mut string) = input.try(|i| i.expect_string().map(|s| s.as_ref().into())) {
let mut strings = vec![];
let mut values = vec![];
let mut line_names = vec![];
let mut names = first_line_names.into_vec();
let mut string = s.into_owned().into_boxed_str();
loop {
line_names.push(names.into_boxed_slice());
strings.push(string);
@ -294,8 +293,8 @@
names.extend(v.into_vec());
}
string = match input.try(Parser::expect_string) {
Ok(s) => s.into_owned().into_boxed_str(),
string = match input.try(|i| i.expect_string().map(|s| s.as_ref().into())) {
Ok(s) => s,
_ => { // only the named area determines whether we should bail out
line_names.push(names.into_boxed_slice());
break