Update to cssparser 0.19, count line numbers during tokenization

This commit is contained in:
Simon Sapin 2017-08-09 18:14:02 +02:00
parent 32f835260c
commit 7382dad939
33 changed files with 145 additions and 196 deletions

26
Cargo.lock generated
View file

@ -325,7 +325,7 @@ version = "0.0.1"
dependencies = [
"azure 0.20.0 (git+https://github.com/servo/rust-azure)",
"canvas_traits 0.0.1",
"cssparser 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -340,7 +340,7 @@ dependencies = [
name = "canvas_traits"
version = "0.0.1"
dependencies = [
"cssparser 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize_derive 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -586,7 +586,7 @@ dependencies = [
[[package]]
name = "cssparser"
version = "0.18.0"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cssparser-macros 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1026,7 +1026,7 @@ name = "geckoservo"
version = "0.0.1"
dependencies = [
"atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1094,7 +1094,7 @@ dependencies = [
name = "gfx_tests"
version = "0.0.1"
dependencies = [
"cssparser 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx 0.0.1",
"ipc-channel 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1",
@ -2467,7 +2467,7 @@ dependencies = [
"caseless 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"cmake 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
"cookie 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
"deny_public_fields 0.0.1",
"devtools_traits 0.0.1",
"dom_struct 0.0.1",
@ -2540,7 +2540,7 @@ dependencies = [
"app_units 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"canvas_traits 0.0.1",
"cssparser 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx_traits 0.0.1",
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2614,7 +2614,7 @@ name = "selectors"
version = "0.19.0"
dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3013,7 +3013,7 @@ dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
"encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3068,7 +3068,7 @@ version = "0.0.1"
dependencies = [
"app_units 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
"html5ever 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3090,7 +3090,7 @@ version = "0.0.1"
dependencies = [
"app_units 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize_derive 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3105,7 +3105,7 @@ name = "stylo_tests"
version = "0.0.1"
dependencies = [
"atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
"geckoservo 0.0.1",
@ -3694,7 +3694,7 @@ dependencies = [
"checksum core-foundation-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "41115a6aa5d3e1e5ef98148373f25971d1fad53818553f216495f9e67e90a624"
"checksum core-graphics 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a9f841e9637adec70838c537cae52cb4c751cc6514ad05669b51d107c2021c79"
"checksum core-text 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "16ce16d9ed00181016c11ff48e561314bec92bfbce9fe48f319366618d4e5de6"
"checksum cssparser 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7cf65dc20c985b085db316cf6e824fbccd4fa2c4641b57b8f42e06b0edb1052d"
"checksum cssparser 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f3a5464ebae36626f28254b60d1abbba951417383192bcea65578b40fbec1a47"
"checksum cssparser-macros 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "079adec4af52bb5275eadd004292028c79eb3c5f5b4ee8086a36d4197032f6df"
"checksum dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97590ba53bcb8ac28279161ca943a924d1fd4a8fb3fa63302591647c4fc5b850"
"checksum dbus 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4aee01fb76ada3e5e7ca642ea6664ebf7308a810739ca2aca44909a1191ac254"

View file

@ -12,7 +12,7 @@ path = "lib.rs"
[dependencies]
azure = {git = "https://github.com/servo/rust-azure"}
canvas_traits = {path = "../canvas_traits"}
cssparser = "0.18"
cssparser = "0.19"
euclid = "0.15"
gleam = "0.4"
ipc-channel = "0.8"

View file

@ -10,7 +10,7 @@ name = "canvas_traits"
path = "lib.rs"
[dependencies]
cssparser = "0.18"
cssparser = "0.19"
euclid = "0.15"
heapsize = "0.4"
heapsize_derive = "0.1"

View file

@ -34,7 +34,7 @@ byteorder = "1.0"
canvas_traits = {path = "../canvas_traits"}
caseless = "0.1.0"
cookie = "0.6"
cssparser = "0.18"
cssparser = "0.19"
deny_public_fields = {path = "../deny_public_fields"}
devtools_traits = {path = "../devtools_traits"}
dom_struct = {path = "../dom_struct"}

View file

@ -13,7 +13,7 @@ path = "lib.rs"
app_units = "0.5"
atomic_refcell = "0.1"
canvas_traits = {path = "../canvas_traits"}
cssparser = "0.18"
cssparser = "0.19"
euclid = "0.15"
gfx_traits = {path = "../gfx_traits"}
heapsize = "0.4"

View file

@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use cssparser::{Parser, SourcePosition};
use cssparser::SourceLocation;
use ipc_channel::ipc::IpcSender;
use log;
use msg::constellation_msg::PipelineId;
@ -22,18 +22,14 @@ pub struct CSSErrorReporter {
}
impl ParseErrorReporter for CSSErrorReporter {
fn report_error<'a>(&self,
input: &mut Parser,
position: SourcePosition,
error: ContextualParseError<'a>,
fn report_error(&self,
url: &ServoUrl,
line_number_offset: u64) {
let location = input.source_location(position);
let line_offset = location.line + line_number_offset as u32;
location: SourceLocation,
error: ContextualParseError) {
if log_enabled!(log::LogLevel::Info) {
info!("Url:\t{}\n{}:{} {}",
url.as_str(),
line_offset,
location.line,
location.column,
error.to_string())
}

View file

@ -25,7 +25,7 @@ unstable = []
[dependencies]
bitflags = "0.7"
matches = "0.1"
cssparser = "0.18"
cssparser = "0.19"
log = "0.3"
fnv = "1.0"
phf = "0.7.18"

View file

@ -1050,7 +1050,7 @@ fn parse_selector<'i, 't, P, E, Impl>(
let combinator;
let mut any_whitespace = false;
loop {
let position = input.position();
let before_this_token = input.state();
match input.next_including_whitespace() {
Err(_e) => break 'outer_loop,
Ok(&Token::WhiteSpace(_)) => any_whitespace = true,
@ -1067,7 +1067,7 @@ fn parse_selector<'i, 't, P, E, Impl>(
break
}
Ok(_) => {
input.reset(position);
input.reset(&before_this_token);
if any_whitespace {
combinator = Combinator::Descendant;
break
@ -1207,11 +1207,11 @@ fn parse_qualified_name<'i, 't, P, E, Impl>
}
};
let position = input.position();
let start = input.state();
// FIXME: remove clone() when lifetimes are non-lexical
match input.next_including_whitespace().map(|t| t.clone()) {
Ok(Token::Ident(value)) => {
let position = input.position();
let after_ident = input.state();
match input.next_including_whitespace() {
Ok(&Token::Delim('|')) => {
let prefix = value.as_ref().into();
@ -1221,7 +1221,7 @@ fn parse_qualified_name<'i, 't, P, E, Impl>
explicit_namespace(input, QNamePrefix::ExplicitNamespace(prefix, url))
},
_ => {
input.reset(position);
input.reset(&after_ident);
if in_attr_selector {
Ok(Some((QNamePrefix::ImplicitNoNamespace, Some(value))))
} else {
@ -1231,14 +1231,14 @@ fn parse_qualified_name<'i, 't, P, E, Impl>
}
},
Ok(Token::Delim('*')) => {
let position = input.position();
let after_star = input.state();
// FIXME: remove clone() when lifetimes are non-lexical
match input.next_including_whitespace().map(|t| t.clone()) {
Ok(Token::Delim('|')) => {
explicit_namespace(input, QNamePrefix::ExplicitAnyNamespace)
}
result => {
input.reset(position);
input.reset(&after_star);
if in_attr_selector {
match result {
Ok(t) => Err(ParseError::Basic(BasicParseError::UnexpectedToken(t))),
@ -1254,7 +1254,7 @@ fn parse_qualified_name<'i, 't, P, E, Impl>
explicit_namespace(input, QNamePrefix::ExplicitNoNamespace)
}
_ => {
input.reset(position);
input.reset(&start);
Ok(None)
}
}
@ -1427,9 +1427,9 @@ fn parse_negation<'i, 't, P, E, Impl>(parser: &P,
// Consume any leading whitespace.
loop {
let position = input.position();
let before_this_token = input.state();
if !matches!(input.next_including_whitespace(), Ok(&Token::WhiteSpace(_))) {
input.reset(position);
input.reset(&before_this_token);
break
}
}
@ -1470,9 +1470,9 @@ fn parse_compound_selector<'i, 't, P, E, Impl>(
{
// Consume any leading whitespace.
loop {
let position = input.position();
let before_this_token = input.state();
if !matches!(input.next_including_whitespace(), Ok(&Token::WhiteSpace(_))) {
input.reset(position);
input.reset(&before_this_token);
break
}
}
@ -1604,7 +1604,7 @@ fn parse_one_simple_selector<'i, 't, P, E, Impl>(parser: &P,
ParseError<'i, SelectorParseError<'i, E>>>
where P: Parser<'i, Impl=Impl, Error=E>, Impl: SelectorImpl
{
let start_position = input.position();
let start = input.state();
// FIXME: remove clone() when lifetimes are non-lexical
match input.next_including_whitespace().map(|t| t.clone()) {
Ok(Token::IDHash(id)) => {
@ -1657,7 +1657,7 @@ fn parse_one_simple_selector<'i, 't, P, E, Impl>(parser: &P,
}
}
_ => {
input.reset(start_position);
input.reset(&start);
Ok(None)
}
}

View file

@ -37,7 +37,7 @@ bitflags = "0.7"
bit-vec = "0.4.3"
byteorder = "1.0"
cfg-if = "0.1.0"
cssparser = "0.18"
cssparser = "0.19"
encoding = {version = "0.2", optional = true}
euclid = "0.15"
fnv = "1.0"

View file

@ -12,7 +12,7 @@ use cssparser::{Parser, Token, serialize_identifier, BasicParseError, CowRcStr};
use error_reporting::ContextualParseError;
#[cfg(feature = "gecko")] use gecko::rules::CounterStyleDescriptors;
#[cfg(feature = "gecko")] use gecko_bindings::structs::nsCSSCounterDesc;
use parser::{ParserContext, log_css_error, Parse};
use parser::{ParserContext, Parse};
use selectors::parser::SelectorParseError;
use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard};
use std::ascii::AsciiExt;
@ -52,7 +52,7 @@ pub fn parse_counter_style_name<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Cu
/// Parse the body (inside `{}`) of an @counter-style rule
pub fn parse_counter_style_body<'i, 't>(name: CustomIdent, context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<CounterStyleRuleData, ParseError<'i>> {
let start = input.position();
let start = input.current_source_location();
let mut rule = CounterStyleRuleData::empty(name);
{
let parser = CounterStyleRuleParser {
@ -62,10 +62,8 @@ pub fn parse_counter_style_body<'i, 't>(name: CustomIdent, context: &ParserConte
let mut iter = DeclarationListParser::new(input, parser);
while let Some(declaration) = iter.next() {
if let Err(err) = declaration {
let pos = err.span.start;
let error = ContextualParseError::UnsupportedCounterStyleDescriptorDeclaration(
iter.input.slice(err.span), err.error);
log_css_error(iter.input, pos, error, context);
let error = ContextualParseError::UnsupportedCounterStyleDescriptorDeclaration(err.slice, err.error);
context.log_css_error(err.location, error)
}
}
}
@ -97,7 +95,7 @@ pub fn parse_counter_style_body<'i, 't>(name: CustomIdent, context: &ParserConte
_ => None
};
if let Some(error) = error {
log_css_error(input, start, error, context);
context.log_css_error(start, error);
Err(StyleParseError::UnspecifiedError.into())
} else {
Ok(rule)

View file

@ -234,9 +234,9 @@ fn parse_declaration_value<'i, 't>
-> Result<(TokenSerializationType, TokenSerializationType), ParseError<'i>> {
input.parse_until_before(Delimiter::Bang | Delimiter::Semicolon, |input| {
// Need at least one token
let start_position = input.position();
let start = input.state();
input.next_including_whitespace()?;
input.reset(start_position);
input.reset(&start);
parse_declaration_value_block(input, references, missing_closing_characters)
})
@ -293,11 +293,11 @@ fn parse_declaration_value_block<'i, 't>
return Err(StyleParseError::UnbalancedCloseCurlyBracketInDeclarationValueBlock.into()),
Token::Function(ref name) => {
if name.eq_ignore_ascii_case("var") {
let position = input.position();
let args_start = input.state();
input.parse_nested_block(|input| {
parse_var_function(input, references)
})?;
input.reset(position);
input.reset(&args_start);
}
nested!();
check_closed!(")");
@ -629,13 +629,13 @@ fn substitute_block<'i, 't, F>(input: &mut Parser<'i, 't>,
while let Ok(_) = input.next() {}
} else {
input.expect_comma()?;
let position = input.position();
let after_comma = input.state();
let first_token_type = input.next_including_whitespace_and_comments()
// parse_var_function() ensures that .unwrap() will not fail.
.unwrap()
.serialization_type();
input.reset(position);
let mut position = (position, first_token_type);
input.reset(&after_comma);
let mut position = (after_comma.position(), first_token_type);
last_token_type = substitute_block(
input, &mut position, partial_computed_value, substitute_one)?;
partial_computed_value.push_from(position, input, last_token_type);

View file

@ -6,7 +6,7 @@
#![deny(missing_docs)]
use cssparser::{Parser, SourcePosition, BasicParseError, Token};
use cssparser::{BasicParseError, Token, SourceLocation};
use cssparser::ParseError as CssParseError;
use log;
use style_traits::ParseError;
@ -152,14 +152,12 @@ impl<'a> ContextualParseError<'a> {
pub trait ParseErrorReporter {
/// Called when the style engine detects an error.
///
/// Returns the current input being parsed, the source position it was
/// Returns the current input being parsed, the source location it was
/// reported from, and a message.
fn report_error<'a>(&self,
input: &mut Parser,
position: SourcePosition,
error: ContextualParseError<'a>,
fn report_error(&self,
url: &UrlExtraData,
line_number_offset: u64);
location: SourceLocation,
error: ContextualParseError);
}
/// An error reporter that uses [the `log` crate](https://github.com/rust-lang-nursery/log)
@ -171,16 +169,12 @@ pub trait ParseErrorReporter {
pub struct RustLogReporter;
impl ParseErrorReporter for RustLogReporter {
fn report_error<'a>(&self,
input: &mut Parser,
position: SourcePosition,
error: ContextualParseError<'a>,
fn report_error(&self,
url: &UrlExtraData,
line_number_offset: u64) {
location: SourceLocation,
error: ContextualParseError) {
if log_enabled!(log::LogLevel::Info) {
let location = input.source_location(position);
let line_offset = location.line + line_number_offset as u32;
info!("Url:\t{}\n{}:{} {}", url.as_str(), line_offset, location.column, error.to_string())
info!("Url:\t{}\n{}:{} {}", url.as_str(), location.line, location.column, error.to_string())
}
}
}
@ -189,12 +183,10 @@ impl ParseErrorReporter for RustLogReporter {
pub struct NullReporter;
impl ParseErrorReporter for NullReporter {
fn report_error<'a>(&self,
_: &mut Parser,
_: SourcePosition,
_: ContextualParseError<'a>,
_: &UrlExtraData,
_: u64) {
fn report_error(&self,
_url: &UrlExtraData,
_location: SourceLocation,
_error: ContextualParseError) {
// do nothing
}
}

View file

@ -16,7 +16,7 @@ use cssparser::{SourceLocation, CowRcStr};
use error_reporting::ContextualParseError;
#[cfg(feature = "gecko")] use gecko_bindings::structs::CSSFontFaceDescriptors;
#[cfg(feature = "gecko")] use cssparser::UnicodeRange;
use parser::{ParserContext, log_css_error, Parse};
use parser::{ParserContext, Parse};
#[cfg(feature = "gecko")]
use properties::longhands::font_language_override;
use selectors::parser::SelectorParseError;
@ -119,10 +119,8 @@ pub fn parse_font_face_block(context: &ParserContext, input: &mut Parser, locati
let mut iter = DeclarationListParser::new(input, parser);
while let Some(declaration) = iter.next() {
if let Err(err) = declaration {
let pos = err.span.start;
let error = ContextualParseError::UnsupportedFontFaceDescriptor(
iter.input.slice(err.span), err.error);
log_css_error(iter.input, pos, error, context);
let error = ContextualParseError::UnsupportedFontFaceDescriptor(err.slice, err.error);
context.log_css_error(err.location, error)
}
}
}

View file

@ -5,7 +5,7 @@
//! The context within which CSS code is parsed.
use context::QuirksMode;
use cssparser::{Parser, SourcePosition, UnicodeRange};
use cssparser::{Parser, SourceLocation, UnicodeRange};
use error_reporting::{ParseErrorReporter, ContextualParseError};
use style_traits::{OneOrMoreSeparated, ParseError, ParsingMode, Separator};
#[cfg(feature = "gecko")]
@ -133,20 +133,15 @@ impl<'a> ParserContext<'a> {
pub fn rule_type(&self) -> CssRuleType {
self.rule_type.expect("Rule type expected, but none was found.")
}
}
/// Defaults to a no-op.
/// Set a `RUST_LOG=style::errors` environment variable
/// to log CSS parse errors to stderr.
pub fn log_css_error<'a>(input: &mut Parser,
position: SourcePosition,
error: ContextualParseError<'a>,
parsercontext: &ParserContext) {
let url_data = parsercontext.url_data;
let line_number_offset = parsercontext.line_number_offset;
parsercontext.error_reporter.report_error(input, position,
error, url_data,
line_number_offset);
/// Record a CSS parse error with this contexts error reporting.
pub fn log_css_error(&self, location: SourceLocation, error: ContextualParseError) {
let location = SourceLocation {
line: location.line + self.line_number_offset as u32,
column: location.column,
};
self.error_reporter.report_error(self.url_data, location, error)
}
}
// XXXManishearth Replace all specified value parse impls with impls of this

View file

@ -10,7 +10,7 @@ use context::QuirksMode;
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};
use parser::ParserContext;
use properties::animated_properties::AnimationValue;
use selectors::parser::SelectorParseError;
use shared_lock::Locked;
@ -909,15 +909,15 @@ pub fn parse_one_declaration_into(declarations: &mut SourcePropertyDeclaration,
quirks_mode);
let mut input = ParserInput::new(input);
let mut parser = Parser::new(&mut input);
let start = parser.position();
let start_position = parser.position();
let start_location = parser.current_source_location();
parser.parse_entirely(|parser| {
PropertyDeclaration::parse_into(declarations, id, &context, parser)
.map_err(|e| e.into())
}).map_err(|err| {
let end = parser.position();
let error = ContextualParseError::UnsupportedPropertyDeclaration(
parser.slice(start..end), err);
log_css_error(&mut parser, start, error, &context);
parser.slice_from(start_position), err);
context.log_css_error(start_location, error);
})
}
@ -1000,10 +1000,8 @@ pub fn parse_property_declaration_list(context: &ParserContext,
continue;
}
let pos = err.span.start;
let error = ContextualParseError::UnsupportedPropertyDeclaration(
iter.input.slice(err.span), err.error);
log_css_error(iter.input, pos, error, &context);
let error = ContextualParseError::UnsupportedPropertyDeclaration(err.slice, err.error);
context.log_css_error(err.location, error);
}
}
}

View file

@ -1502,12 +1502,12 @@ impl PropertyDeclaration {
PropertyDeclaration::CSSWideKeyword(id, keyword)
}).or_else(|()| {
input.look_for_var_functions();
let start = input.position();
let start = input.state();
input.parse_entirely(|input| id.parse_value(context, input))
.or_else(|err| {
while let Ok(_) = input.next() {} // Look for var() after the error.
if input.seen_var_functions() {
input.reset(start);
input.reset(&start);
let (first_token_type, css) =
::custom_properties::parse_non_custom_with_var(input).map_err(|e| {
PropertyDeclarationParseError::InvalidValue(id.name().into(),
@ -1540,13 +1540,13 @@ impl PropertyDeclaration {
Ok(())
} else {
input.look_for_var_functions();
let start = input.position();
let start = input.state();
// Not using parse_entirely here: each ${shorthand.ident}::parse_into function
// needs to do so *before* pushing to `declarations`.
id.parse_into(declarations, context, input).or_else(|err| {
while let Ok(_) = input.next() {} // Look for var() after the error.
if input.seen_var_functions() {
input.reset(start);
input.reset(&start);
let (first_token_type, css) =
::custom_properties::parse_non_custom_with_var(input).map_err(|e| {
PropertyDeclarationParseError::InvalidValue(id.name().into(),

View file

@ -11,7 +11,7 @@ use computed_values::font_family::FamilyName;
use cssparser::{AtRuleParser, AtRuleType, BasicParseError, DeclarationListParser, DeclarationParser, Parser};
use cssparser::{CowRcStr, RuleListParser, SourceLocation, QualifiedRuleParser, Token, serialize_identifier};
use error_reporting::ContextualParseError;
use parser::{ParserContext, log_css_error, Parse};
use parser::{ParserContext, Parse};
use selectors::parser::SelectorParseError;
use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard};
use std::fmt;
@ -222,10 +222,8 @@ macro_rules! font_feature_values_blocks {
});
while let Some(result) = iter.next() {
if let Err(err) = result {
let pos = err.span.start;
let error = ContextualParseError::UnsupportedRule(
iter.input.slice(err.span), err.error);
log_css_error(iter.input, pos, error, context);
let error = ContextualParseError::UnsupportedRule(err.slice, err.error);
context.log_css_error(err.location, error);
}
}
}
@ -338,10 +336,9 @@ macro_rules! font_feature_values_blocks {
let mut iter = DeclarationListParser::new(input, parser);
while let Some(declaration) = iter.next() {
if let Err(err) = declaration {
let pos = err.span.start;
let error = ContextualParseError::UnsupportedKeyframePropertyDeclaration(
iter.input.slice(err.span), err.error);
log_css_error(iter.input, pos, error, &context);
err.slice, err.error);
context.log_css_error(err.location, error);
}
}
},

View file

@ -7,7 +7,7 @@
use cssparser::{AtRuleParser, Parser, QualifiedRuleParser, RuleListParser, ParserInput, CowRcStr};
use cssparser::{DeclarationListParser, DeclarationParser, parse_one_rule, SourceLocation};
use error_reporting::{NullReporter, ContextualParseError};
use parser::{ParserContext, log_css_error};
use parser::ParserContext;
use properties::{Importance, PropertyDeclaration, PropertyDeclarationBlock, PropertyId};
use properties::{PropertyDeclarationId, LonghandId, SourcePropertyDeclaration};
use properties::LonghandIdSet;
@ -473,12 +473,13 @@ impl<'a, 'i> QualifiedRuleParser<'i> for KeyframeListParser<'a> {
type Error = SelectorParseError<'i, StyleParseError<'i>>;
fn parse_prelude<'t>(&mut self, input: &mut Parser<'i, 't>) -> Result<Self::Prelude, ParseError<'i>> {
let start = input.position();
let start_position = input.position();
let start_location = input.current_source_location();
match KeyframeSelector::parse(input) {
Ok(sel) => Ok(sel),
Err(e) => {
let error = ContextualParseError::InvalidKeyframeRule(input.slice_from(start), e.clone());
log_css_error(input, start, error, self.context);
let error = ContextualParseError::InvalidKeyframeRule(input.slice_from(start_position), e.clone());
self.context.log_css_error(start_location, error);
Err(e)
}
}
@ -500,10 +501,8 @@ impl<'a, 'i> QualifiedRuleParser<'i> for KeyframeListParser<'a> {
}
Err(err) => {
iter.parser.declarations.clear();
let pos = err.span.start;
let error = ContextualParseError::UnsupportedKeyframePropertyDeclaration(
iter.input.slice(err.span), err.error);
log_css_error(iter.input, pos, error, &context);
let error = ContextualParseError::UnsupportedKeyframePropertyDeclaration(err.slice, err.error);
context.log_css_error(err.location, error);
}
}
// `parse_important` is not called here, `!important` is not allowed in keyframe blocks.

View file

@ -12,7 +12,7 @@ use cssparser::{CowRcStr, SourceLocation, BasicParseError};
use error_reporting::ContextualParseError;
use font_face::parse_font_face_block;
use media_queries::{parse_media_query_list, MediaList};
use parser::{Parse, ParserContext, log_css_error};
use parser::{Parse, ParserContext};
use properties::parse_property_declaration_list;
use selector_parser::{SelectorImpl, SelectorParser};
use selectors::SelectorList;
@ -318,10 +318,8 @@ impl<'a, 'b> NestedRuleParser<'a, 'b> {
match result {
Ok(rule) => rules.push(rule),
Err(err) => {
let pos = err.span.start;
let error = ContextualParseError::UnsupportedRule(
iter.input.slice(err.span), err.error);
log_css_error(iter.input, pos, error, self.context);
let error = ContextualParseError::UnsupportedRule(err.slice, err.error);
self.context.log_css_error(err.location, error);
}
}
}

View file

@ -9,7 +9,7 @@ use error_reporting::{ParseErrorReporter, ContextualParseError};
use fnv::FnvHashMap;
use media_queries::{MediaList, Device};
use parking_lot::RwLock;
use parser::{ParserContext, log_css_error};
use parser::ParserContext;
use servo_arc::Arc;
use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked, SharedRwLock, SharedRwLockReadGuard};
use std::mem;
@ -351,10 +351,8 @@ impl Stylesheet {
match result {
Ok(rule) => rules.push(rule),
Err(err) => {
let pos = err.span.start;
let error = ContextualParseError::InvalidRule(
iter.input.slice(err.span), err.error);
log_css_error(iter.input, pos, error, iter.parser.context());
let error = ContextualParseError::InvalidRule(err.slice, err.error);
iter.parser.context().log_css_error(err.location, error);
}
}
}

View file

@ -15,7 +15,7 @@ use error_reporting::ContextualParseError;
use euclid::TypedSize2D;
use font_metrics::get_metrics_provider_for_product;
use media_queries::Device;
use parser::{Parse, ParserContext, log_css_error};
use parser::{Parse, ParserContext};
use properties::StyleBuilder;
use selectors::parser::SelectorParseError;
use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard};
@ -360,10 +360,8 @@ impl Parse for ViewportRule {
}
}
Err(err) => {
let pos = err.span.start;
let error = ContextualParseError::UnsupportedViewportDescriptorDeclaration(
parser.input.slice(err.span), err.error);
log_css_error(parser.input, pos, error, &context);
let error = ContextualParseError::UnsupportedViewportDescriptorDeclaration(err.slice, err.error);
context.log_css_error(err.location, error);
}
}
}

View file

@ -194,7 +194,7 @@ impl CalcNode {
let mut root = Self::parse_product(context, input, expected_unit)?;
loop {
let position = input.position();
let start = input.state();
match input.next_including_whitespace() {
Ok(&Token::WhiteSpace(_)) => {
if input.is_exhausted() {
@ -220,7 +220,7 @@ impl CalcNode {
}
}
_ => {
input.reset(position);
input.reset(&start);
break
}
}
@ -247,7 +247,7 @@ impl CalcNode {
let mut root = Self::parse_one(context, input, expected_unit)?;
loop {
let position = input.position();
let start = input.state();
match input.next() {
Ok(&Token::Delim('*')) => {
let rhs = Self::parse_one(context, input, expected_unit)?;
@ -261,7 +261,7 @@ impl CalcNode {
root = new_root;
}
_ => {
input.reset(position);
input.reset(&start);
break
}
}

View file

@ -70,12 +70,12 @@ impl Parse for Color {
// Currently we only store authored value for color keywords,
// because all browsers serialize those values as keywords for
// specified value.
let start_position = input.position();
let start = input.state();
let authored = match input.next() {
Ok(&Token::Ident(ref s)) => Some(s.to_lowercase().into_boxed_str()),
_ => None,
};
input.reset(start_position);
input.reset(&start);
match input.try(CSSParserColor::parse) {
Ok(value) =>
Ok(match value {

View file

@ -16,7 +16,7 @@ gecko = []
[dependencies]
app_units = "0.5"
bitflags = "0.7"
cssparser = "0.18"
cssparser = "0.19"
euclid = "0.15"
heapsize = {version = "0.4", optional = true}
heapsize_derive = {version = "0.1", optional = true}

View file

@ -15,7 +15,7 @@ gecko_debug = ["style/gecko_debug"]
[dependencies]
atomic_refcell = "0.1"
cssparser = "0.18"
cssparser = "0.19"
env_logger = {version = "0.4", default-features = false} # disable `regex` to reduce code size
libc = "0.2"
log = {version = "0.3.5", features = ["release_max_level_info"]}

View file

@ -6,7 +6,7 @@
#![allow(unsafe_code)]
use cssparser::{Parser, SourcePosition, ParseError as CssParseError, Token, BasicParseError};
use cssparser::{SourceLocation, ParseError as CssParseError, Token, BasicParseError};
use cssparser::CowRcStr;
use selectors::parser::SelectorParseError;
use std::ptr;
@ -330,15 +330,10 @@ impl<'a> ErrorHelpers<'a> for ContextualParseError<'a> {
}
impl ParseErrorReporter for ErrorReporter {
fn report_error<'a>(&self,
input: &mut Parser,
position: SourcePosition,
error: ContextualParseError<'a>,
fn report_error(&self,
_url: &UrlExtraData,
line_number_offset: u64) {
let location = input.source_location(position);
let line_number = location.line + line_number_offset as u32;
location: SourceLocation,
error: ContextualParseError) {
let (pre, name, action) = error.to_gecko_message();
let suffix = match action {
Action::Nothing => ptr::null(),
@ -362,8 +357,8 @@ impl ParseErrorReporter for ErrorReporter {
suffix as *const _,
source.as_ptr() as *const _,
source.len() as u32,
line_number as u32,
location.column as u32);
location.line,
location.column);
}
}
}

View file

@ -10,7 +10,7 @@ path = "lib.rs"
doctest = false
[dependencies]
cssparser = "0.18"
cssparser = "0.19"
gfx = {path = "../../../components/gfx"}
ipc-channel = "0.8"
style = {path = "../../../components/style"}

View file

@ -12,7 +12,7 @@ doctest = false
[dependencies]
byteorder = "1.0"
app_units = "0.5"
cssparser = "0.18"
cssparser = "0.19"
euclid = "0.15"
html5ever = "0.18"
parking_lot = "0.4"

View file

@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use cssparser::{Parser, SourcePosition};
use cssparser::SourceLocation;
use euclid::ScaleFactor;
use euclid::TypedSize2D;
use servo_arc::Arc;
@ -21,12 +21,10 @@ use style_traits::ToCss;
pub struct CSSErrorReporterTest;
impl ParseErrorReporter for CSSErrorReporterTest {
fn report_error<'a>(&self,
_input: &mut Parser,
_position: SourcePosition,
_error: ContextualParseError<'a>,
fn report_error(&self,
_url: &ServoUrl,
_line_number_offset: u64) {
_location: SourceLocation,
_error: ContextualParseError) {
}
}

View file

@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use cssparser::{Parser, SourcePosition};
use cssparser::SourceLocation;
use rayon;
use servo_arc::Arc;
use servo_url::ServoUrl;
@ -18,15 +18,11 @@ use test::{self, Bencher};
struct ErrorringErrorReporter;
impl ParseErrorReporter for ErrorringErrorReporter {
fn report_error<'a>(&self,
input: &mut Parser,
position: SourcePosition,
error: ContextualParseError<'a>,
fn report_error(&self,
url: &ServoUrl,
line_number_offset: u64) {
let location = input.source_location(position);
let line_offset = location.line + line_number_offset as u32;
panic!("CSS error: {}\t\n{}:{} {}", url.as_str(), line_offset, location.column, error.to_string());
location: SourceLocation,
error: ContextualParseError) {
panic!("CSS error: {}\t\n{}:{} {}", url.as_str(), location.line, location.column, error.to_string());
}
}

View file

@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use cssparser::{self, Parser as CssParser, SourcePosition, SourceLocation};
use cssparser::{self, SourceLocation};
use html5ever::{Namespace as NsAtom};
use media_queries::CSSErrorReporterTest;
use parking_lot::RwLock;
@ -270,21 +270,15 @@ impl CSSInvalidErrorReporterTest {
}
impl ParseErrorReporter for CSSInvalidErrorReporterTest {
fn report_error<'a>(&self,
input: &mut CssParser,
position: SourcePosition,
error: ContextualParseError<'a>,
fn report_error(&self,
url: &ServoUrl,
line_number_offset: u64) {
let location = input.source_location(position);
let line_offset = location.line + line_number_offset as u32;
location: SourceLocation,
error: ContextualParseError) {
let mut errors = self.errors.lock().unwrap();
errors.push(
CSSError{
url: url.clone(),
line: line_offset,
line: location.line,
column: location.column,
message: error.to_string()
}

View file

@ -14,7 +14,6 @@ use style::context::QuirksMode;
use style::media_queries::{Device, MediaType};
use style::properties::{PropertyDeclarationBlock, PropertyDeclaration};
use style::properties::{longhands, Importance};
use style::rule_tree::CascadeLevel;
use style::selector_map::{self, SelectorMap};
use style::selector_parser::{SelectorImpl, SelectorParser};
use style::shared_lock::SharedRwLock;

View file

@ -13,7 +13,7 @@ doctest = false
[dependencies]
atomic_refcell = "0.1"
cssparser = "0.18"
cssparser = "0.19"
env_logger = "0.4"
euclid = "0.15"
geckoservo = {path = "../../../ports/geckolib"}