mirror of
https://github.com/servo/servo.git
synced 2025-08-09 07:25:35 +01:00
Update to cssparser 0.22 (source location in error types)
This commit is contained in:
parent
056e599562
commit
c0f8f15f39
90 changed files with 974 additions and 790 deletions
|
@ -4,17 +4,17 @@
|
|||
|
||||
//! [@supports rules](https://drafts.csswg.org/css-conditional-3/#at-supports)
|
||||
|
||||
use cssparser::{BasicParseError, ParseError as CssParseError, ParserInput};
|
||||
use cssparser::{Delimiter, parse_important, Parser, SourceLocation, Token};
|
||||
use cssparser::{ParseError as CssParseError, ParserInput};
|
||||
#[cfg(feature = "gecko")]
|
||||
use malloc_size_of::{MallocSizeOfOps, MallocUnconditionalShallowSizeOf};
|
||||
use parser::ParserContext;
|
||||
use properties::{PropertyId, PropertyDeclaration, PropertyParserContext, SourcePropertyDeclaration};
|
||||
use selectors::parser::SelectorParseError;
|
||||
use selectors::parser::SelectorParseErrorKind;
|
||||
use servo_arc::Arc;
|
||||
use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked, SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard};
|
||||
use std::fmt;
|
||||
use style_traits::{ToCss, ParseError, StyleParseError};
|
||||
use style_traits::{ToCss, ParseError};
|
||||
use stylesheets::{CssRuleType, CssRules};
|
||||
|
||||
/// An [`@supports`][supports] rule.
|
||||
|
@ -104,6 +104,7 @@ impl SupportsCondition {
|
|||
|
||||
let in_parens = SupportsCondition::parse_in_parens(input)?;
|
||||
|
||||
let location = input.current_source_location();
|
||||
let (keyword, wrapper) = match input.next() {
|
||||
Err(_) => {
|
||||
// End of input
|
||||
|
@ -113,10 +114,10 @@ impl SupportsCondition {
|
|||
match_ignore_ascii_case! { &ident,
|
||||
"and" => ("and", SupportsCondition::And as fn(_) -> _),
|
||||
"or" => ("or", SupportsCondition::Or as fn(_) -> _),
|
||||
_ => return Err(SelectorParseError::UnexpectedIdent(ident.clone()).into())
|
||||
_ => return Err(location.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(ident.clone())))
|
||||
}
|
||||
}
|
||||
Ok(t) => return Err(CssParseError::Basic(BasicParseError::UnexpectedToken(t.clone())))
|
||||
Ok(t) => return Err(location.new_unexpected_token_error(t.clone()))
|
||||
};
|
||||
|
||||
let mut conditions = Vec::with_capacity(2);
|
||||
|
@ -138,6 +139,7 @@ impl SupportsCondition {
|
|||
// but we want to not include it in `pos` for the SupportsCondition::FutureSyntax cases.
|
||||
while input.try(Parser::expect_whitespace).is_ok() {}
|
||||
let pos = input.position();
|
||||
let location = input.current_source_location();
|
||||
// FIXME: remove clone() when lifetimes are non-lexical
|
||||
match input.next()?.clone() {
|
||||
Token::ParenthesisBlock => {
|
||||
|
@ -149,7 +151,7 @@ impl SupportsCondition {
|
|||
}
|
||||
}
|
||||
Token::Function(_) => {}
|
||||
t => return Err(CssParseError::Basic(BasicParseError::UnexpectedToken(t))),
|
||||
t => return Err(location.new_unexpected_token_error(t)),
|
||||
}
|
||||
input.parse_nested_block(|i| consume_any_value(i))?;
|
||||
Ok(SupportsCondition::FutureSyntax(input.slice_from(pos).to_owned()))
|
||||
|
@ -258,18 +260,18 @@ impl Declaration {
|
|||
|
||||
let mut input = ParserInput::new(&self.0);
|
||||
let mut input = Parser::new(&mut input);
|
||||
input.parse_entirely(|input| {
|
||||
input.parse_entirely(|input| -> Result<(), CssParseError<()>> {
|
||||
let prop = input.expect_ident().unwrap().as_ref().to_owned();
|
||||
input.expect_colon().unwrap();
|
||||
|
||||
let property_context = PropertyParserContext::new(&context);
|
||||
let id = PropertyId::parse(&prop, Some(&property_context))
|
||||
.map_err(|_| StyleParseError::UnspecifiedError)?;
|
||||
.map_err(|()| input.new_custom_error(()))?;
|
||||
|
||||
let mut declarations = SourcePropertyDeclaration::new();
|
||||
input.parse_until_before(Delimiter::Bang, |input| {
|
||||
PropertyDeclaration::parse_into(&mut declarations, id, prop.into(), &context, input)
|
||||
.map_err(|e| StyleParseError::PropertyDeclaration(e).into())
|
||||
.map_err(|_| input.new_custom_error(()))
|
||||
})?;
|
||||
let _ = input.try(parse_important);
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue