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 = [ dependencies = [
"azure 0.20.0 (git+https://github.com/servo/rust-azure)", "azure 0.20.0 (git+https://github.com/servo/rust-azure)",
"canvas_traits 0.0.1", "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)", "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)", "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)", "ipc-channel 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -340,7 +340,7 @@ dependencies = [
name = "canvas_traits" name = "canvas_traits"
version = "0.0.1" version = "0.0.1"
dependencies = [ 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)", "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 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)", "heapsize_derive 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -586,7 +586,7 @@ dependencies = [
[[package]] [[package]]
name = "cssparser" name = "cssparser"
version = "0.18.0" version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"cssparser-macros 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser-macros 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1026,7 +1026,7 @@ name = "geckoservo"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1094,7 +1094,7 @@ dependencies = [
name = "gfx_tests" name = "gfx_tests"
version = "0.0.1" version = "0.0.1"
dependencies = [ 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", "gfx 0.0.1",
"ipc-channel 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1", "style 0.0.1",
@ -2467,7 +2467,7 @@ dependencies = [
"caseless 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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", "deny_public_fields 0.0.1",
"devtools_traits 0.0.1", "devtools_traits 0.0.1",
"dom_struct 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)", "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)", "atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"canvas_traits 0.0.1", "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)", "euclid 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx_traits 0.0.1", "gfx_traits 0.0.1",
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2614,7 +2614,7 @@ name = "selectors"
version = "0.19.0" version = "0.19.0"
dependencies = [ dependencies = [
"bitflags 0.7.0 (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)",
"fnv 1.0.5 (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)", "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)", "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)", "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)", "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)", "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)", "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)", "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)", "fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3068,7 +3068,7 @@ version = "0.0.1"
dependencies = [ dependencies = [
"app_units 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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)", "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)", "parking_lot 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3090,7 +3090,7 @@ version = "0.0.1"
dependencies = [ dependencies = [
"app_units 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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 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)", "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" version = "0.0.1"
dependencies = [ dependencies = [
"atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "euclid 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
"geckoservo 0.0.1", "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-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-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 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 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 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" "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] [dependencies]
azure = {git = "https://github.com/servo/rust-azure"} azure = {git = "https://github.com/servo/rust-azure"}
canvas_traits = {path = "../canvas_traits"} canvas_traits = {path = "../canvas_traits"}
cssparser = "0.18" cssparser = "0.19"
euclid = "0.15" euclid = "0.15"
gleam = "0.4" gleam = "0.4"
ipc-channel = "0.8" ipc-channel = "0.8"

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -5,7 +5,7 @@
//! The context within which CSS code is parsed. //! The context within which CSS code is parsed.
use context::QuirksMode; use context::QuirksMode;
use cssparser::{Parser, SourcePosition, UnicodeRange}; use cssparser::{Parser, SourceLocation, UnicodeRange};
use error_reporting::{ParseErrorReporter, ContextualParseError}; use error_reporting::{ParseErrorReporter, ContextualParseError};
use style_traits::{OneOrMoreSeparated, ParseError, ParsingMode, Separator}; use style_traits::{OneOrMoreSeparated, ParseError, ParsingMode, Separator};
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
@ -133,20 +133,15 @@ impl<'a> ParserContext<'a> {
pub fn rule_type(&self) -> CssRuleType { pub fn rule_type(&self) -> CssRuleType {
self.rule_type.expect("Rule type expected, but none was found.") self.rule_type.expect("Rule type expected, but none was found.")
} }
}
/// Defaults to a no-op. /// Record a CSS parse error with this contexts error reporting.
/// Set a `RUST_LOG=style::errors` environment variable pub fn log_css_error(&self, location: SourceLocation, error: ContextualParseError) {
/// to log CSS parse errors to stderr. let location = SourceLocation {
pub fn log_css_error<'a>(input: &mut Parser, line: location.line + self.line_number_offset as u32,
position: SourcePosition, column: location.column,
error: ContextualParseError<'a>, };
parsercontext: &ParserContext) { self.error_reporter.report_error(self.url_data, location, error)
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);
} }
// XXXManishearth Replace all specified value parse impls with impls of this // 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::{DeclarationListParser, parse_important, ParserInput, CowRcStr};
use cssparser::{Parser, AtRuleParser, DeclarationParser, Delimiter, ParseError as CssParseError}; use cssparser::{Parser, AtRuleParser, DeclarationParser, Delimiter, ParseError as CssParseError};
use error_reporting::{ParseErrorReporter, ContextualParseError}; use error_reporting::{ParseErrorReporter, ContextualParseError};
use parser::{ParserContext, log_css_error}; use parser::ParserContext;
use properties::animated_properties::AnimationValue; use properties::animated_properties::AnimationValue;
use selectors::parser::SelectorParseError; use selectors::parser::SelectorParseError;
use shared_lock::Locked; use shared_lock::Locked;
@ -909,15 +909,15 @@ pub fn parse_one_declaration_into(declarations: &mut SourcePropertyDeclaration,
quirks_mode); quirks_mode);
let mut input = ParserInput::new(input); let mut input = ParserInput::new(input);
let mut parser = Parser::new(&mut 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| { parser.parse_entirely(|parser| {
PropertyDeclaration::parse_into(declarations, id, &context, parser) PropertyDeclaration::parse_into(declarations, id, &context, parser)
.map_err(|e| e.into()) .map_err(|e| e.into())
}).map_err(|err| { }).map_err(|err| {
let end = parser.position();
let error = ContextualParseError::UnsupportedPropertyDeclaration( let error = ContextualParseError::UnsupportedPropertyDeclaration(
parser.slice(start..end), err); parser.slice_from(start_position), err);
log_css_error(&mut parser, start, error, &context); context.log_css_error(start_location, error);
}) })
} }
@ -1000,10 +1000,8 @@ pub fn parse_property_declaration_list(context: &ParserContext,
continue; continue;
} }
let pos = err.span.start; let error = ContextualParseError::UnsupportedPropertyDeclaration(err.slice, err.error);
let error = ContextualParseError::UnsupportedPropertyDeclaration( context.log_css_error(err.location, error);
iter.input.slice(err.span), err.error);
log_css_error(iter.input, pos, error, &context);
} }
} }
} }

View file

@ -1502,12 +1502,12 @@ impl PropertyDeclaration {
PropertyDeclaration::CSSWideKeyword(id, keyword) PropertyDeclaration::CSSWideKeyword(id, keyword)
}).or_else(|()| { }).or_else(|()| {
input.look_for_var_functions(); input.look_for_var_functions();
let start = input.position(); let start = input.state();
input.parse_entirely(|input| id.parse_value(context, input)) input.parse_entirely(|input| id.parse_value(context, input))
.or_else(|err| { .or_else(|err| {
while let Ok(_) = input.next() {} // Look for var() after the error. while let Ok(_) = input.next() {} // Look for var() after the error.
if input.seen_var_functions() { if input.seen_var_functions() {
input.reset(start); input.reset(&start);
let (first_token_type, css) = let (first_token_type, css) =
::custom_properties::parse_non_custom_with_var(input).map_err(|e| { ::custom_properties::parse_non_custom_with_var(input).map_err(|e| {
PropertyDeclarationParseError::InvalidValue(id.name().into(), PropertyDeclarationParseError::InvalidValue(id.name().into(),
@ -1540,13 +1540,13 @@ impl PropertyDeclaration {
Ok(()) Ok(())
} else { } else {
input.look_for_var_functions(); input.look_for_var_functions();
let start = input.position(); let start = input.state();
// Not using parse_entirely here: each ${shorthand.ident}::parse_into function // Not using parse_entirely here: each ${shorthand.ident}::parse_into function
// needs to do so *before* pushing to `declarations`. // needs to do so *before* pushing to `declarations`.
id.parse_into(declarations, context, input).or_else(|err| { id.parse_into(declarations, context, input).or_else(|err| {
while let Ok(_) = input.next() {} // Look for var() after the error. while let Ok(_) = input.next() {} // Look for var() after the error.
if input.seen_var_functions() { if input.seen_var_functions() {
input.reset(start); input.reset(&start);
let (first_token_type, css) = let (first_token_type, css) =
::custom_properties::parse_non_custom_with_var(input).map_err(|e| { ::custom_properties::parse_non_custom_with_var(input).map_err(|e| {
PropertyDeclarationParseError::InvalidValue(id.name().into(), 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::{AtRuleParser, AtRuleType, BasicParseError, DeclarationListParser, DeclarationParser, Parser};
use cssparser::{CowRcStr, RuleListParser, SourceLocation, QualifiedRuleParser, Token, serialize_identifier}; use cssparser::{CowRcStr, RuleListParser, SourceLocation, QualifiedRuleParser, Token, serialize_identifier};
use error_reporting::ContextualParseError; use error_reporting::ContextualParseError;
use parser::{ParserContext, log_css_error, Parse}; use parser::{ParserContext, Parse};
use selectors::parser::SelectorParseError; use selectors::parser::SelectorParseError;
use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard}; use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard};
use std::fmt; use std::fmt;
@ -222,10 +222,8 @@ macro_rules! font_feature_values_blocks {
}); });
while let Some(result) = iter.next() { while let Some(result) = iter.next() {
if let Err(err) = result { if let Err(err) = result {
let pos = err.span.start; let error = ContextualParseError::UnsupportedRule(err.slice, err.error);
let error = ContextualParseError::UnsupportedRule( context.log_css_error(err.location, error);
iter.input.slice(err.span), err.error);
log_css_error(iter.input, pos, error, context);
} }
} }
} }
@ -338,10 +336,9 @@ macro_rules! font_feature_values_blocks {
let mut iter = DeclarationListParser::new(input, parser); let mut iter = DeclarationListParser::new(input, parser);
while let Some(declaration) = iter.next() { while let Some(declaration) = iter.next() {
if let Err(err) = declaration { if let Err(err) = declaration {
let pos = err.span.start;
let error = ContextualParseError::UnsupportedKeyframePropertyDeclaration( let error = ContextualParseError::UnsupportedKeyframePropertyDeclaration(
iter.input.slice(err.span), err.error); err.slice, err.error);
log_css_error(iter.input, pos, error, &context); context.log_css_error(err.location, error);
} }
} }
}, },

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -12,7 +12,7 @@ doctest = false
[dependencies] [dependencies]
byteorder = "1.0" byteorder = "1.0"
app_units = "0.5" app_units = "0.5"
cssparser = "0.18" cssparser = "0.19"
euclid = "0.15" euclid = "0.15"
html5ever = "0.18" html5ever = "0.18"
parking_lot = "0.4" 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 * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use cssparser::{Parser, SourcePosition}; use cssparser::SourceLocation;
use euclid::ScaleFactor; use euclid::ScaleFactor;
use euclid::TypedSize2D; use euclid::TypedSize2D;
use servo_arc::Arc; use servo_arc::Arc;
@ -21,12 +21,10 @@ use style_traits::ToCss;
pub struct CSSErrorReporterTest; pub struct CSSErrorReporterTest;
impl ParseErrorReporter for CSSErrorReporterTest { impl ParseErrorReporter for CSSErrorReporterTest {
fn report_error<'a>(&self, fn report_error(&self,
_input: &mut Parser, _url: &ServoUrl,
_position: SourcePosition, _location: SourceLocation,
_error: ContextualParseError<'a>, _error: ContextualParseError) {
_url: &ServoUrl,
_line_number_offset: u64) {
} }
} }

View file

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

View file

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

View file

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

View file

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