Skip to content

Commit

Permalink
Update to cssparser 0.19, count line numbers during tokenization
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Aug 9, 2017
1 parent 32f8352 commit 7382dad
Show file tree
Hide file tree
Showing 33 changed files with 145 additions and 196 deletions.
26 changes: 13 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components/canvas/Cargo.toml
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion components/canvas_traits/Cargo.toml
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion components/script/Cargo.toml
Expand Up @@ -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"}
Expand Down
2 changes: 1 addition & 1 deletion components/script_layout_interface/Cargo.toml
Expand Up @@ -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"
Expand Down
16 changes: 6 additions & 10 deletions components/script_layout_interface/reporter.rs
Expand Up @@ -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;
Expand All @@ -22,18 +22,14 @@ pub struct CSSErrorReporter {
}

impl ParseErrorReporter for CSSErrorReporter {
fn report_error<'a>(&self,
input: &mut Parser,
position: SourcePosition,
error: ContextualParseError<'a>,
url: &ServoUrl,
line_number_offset: u64) {
let location = input.source_location(position);
let line_offset = location.line + line_number_offset as u32;
fn report_error(&self,
url: &ServoUrl,
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())
}
Expand Down
2 changes: 1 addition & 1 deletion components/selectors/Cargo.toml
Expand Up @@ -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"
Expand Down
28 changes: 14 additions & 14 deletions components/selectors/parser.rs
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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 {
Expand All @@ -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))),
Expand All @@ -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)
}
}
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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)) => {
Expand Down Expand Up @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/style/Cargo.toml
Expand Up @@ -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"
Expand Down
12 changes: 5 additions & 7 deletions components/style/counter_style/mod.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
}
}
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions components/style/custom_properties.rs
Expand Up @@ -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)
})
Expand Down Expand Up @@ -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!(")");
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7382dad

Please sign in to comment.