Commit 7483f2df authored by Emilio Cobos Álvarez 's avatar Emilio Cobos Álvarez
Browse files

Bug 1680558 - Update cssparser to get ParserState in rule parser. r=heycam, a=RyanVM

The changes should be trivial.

The third_party changes are up for review in
https://github.com/servo/rust-cssparser/pull/277 (and of course I'll
land with a bump to 0.28 rather than the override after that gets r+'d).

The basic idea is that with this we have the actual start offset of the
rule, so we wouldn't include html comments or other invalid stuff we
discard during sanitization in bug 1680084. But that's a separate
change.

Differential Revision: https://phabricator.services.mozilla.com/D98677
parent 4537b1c6
......@@ -898,9 +898,9 @@ dependencies = [
[[package]]
name = "cssparser"
version = "0.27.2"
version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "754b69d351cdc2d8ee09ae203db831e005560fc6030da058f86ad60c92a9cb0a"
checksum = "809d22aba9ffd53e9028f2d37261f1826ef613d0e96b1a5ddeefa97cde82bcca"
dependencies = [
"cssparser-macros",
"dtoa-short",
......
......@@ -30,7 +30,7 @@
let tests = [
{ sheetNo: 0, ruleNo: 0, lineNo: 1, columnNo: 1 },
{ sheetNo: 1, ruleNo: 0, lineNo: 2, columnNo: 14 },
{ sheetNo: 1, ruleNo: 0, lineNo: 2, columnNo: 5 },
{ sheetNo: 1, ruleNo: 1, lineNo: 8, columnNo: 5 },
{ sheetNo: 2, ruleNo: 0, lineNo: 1, columnNo: 1 },
{ sheetNo: 2, ruleNo: 1, lineNo: 0, columnNo: 1 },
......
......@@ -31,7 +31,7 @@ accountable-refcell = { version = "0.2.0", optional = true }
app_units = "0.7"
content-security-policy = {version = "0.3.0", features = ["serde"], optional = true}
crossbeam-channel = { version = "0.3", optional = true }
cssparser = "0.27"
cssparser = "0.28"
euclid = "0.20"
hashglobe = { path = "../hashglobe" }
hyper = { version = "0.12", optional = true }
......
......@@ -22,7 +22,7 @@ bench = []
[dependencies]
bitflags = "1.0"
matches = "0.1"
cssparser = "0.27"
cssparser = "0.28"
derive_more = "0.99"
log = "0.4"
fxhash = "0.2"
......
......@@ -32,7 +32,7 @@ arrayvec = "0.5"
atomic_refcell = "0.1"
bitflags = "1.0"
byteorder = "1.0"
cssparser = "0.27"
cssparser = "0.28"
crossbeam-channel = { version = "0.4", optional = true }
derive_more = "0.99"
new_debug_unreachable = "1.0"
......
......@@ -20,7 +20,7 @@ use crate::values::serialize_atom_identifier;
use crate::Atom;
use cssparser::{AtRuleParser, AtRuleType, BasicParseErrorKind, CowRcStr};
use cssparser::{DeclarationListParser, DeclarationParser, Parser};
use cssparser::{QualifiedRuleParser, RuleListParser, SourceLocation, Token};
use cssparser::{QualifiedRuleParser, RuleListParser, SourceLocation, ParserState, Token};
use std::fmt::{self, Write};
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
......@@ -413,7 +413,7 @@ macro_rules! font_feature_values_blocks {
fn parse_block<'t>(
&mut self,
prelude: BlockType,
_location: SourceLocation,
_: &ParserState,
input: &mut Parser<'i, 't>
) -> Result<Self::AtRule, ParseError<'i>> {
debug_assert_eq!(self.context.rule_type(), CssRuleType::FontFeatureValues);
......
......@@ -17,7 +17,7 @@ use crate::str::CssStringWriter;
use crate::stylesheets::rule_parser::VendorPrefix;
use crate::stylesheets::{CssRuleType, StylesheetContents};
use crate::values::{serialize_percentage, KeyframesName};
use cssparser::{parse_one_rule, DeclarationListParser, DeclarationParser, SourceLocation, Token};
use cssparser::{parse_one_rule, DeclarationListParser, DeclarationParser, ParserState, SourceLocation, Token};
use cssparser::{AtRuleParser, CowRcStr, Parser, ParserInput, QualifiedRuleParser, RuleListParser};
use servo_arc::Arc;
use std::fmt::{self, Write};
......@@ -533,7 +533,7 @@ impl<'a, 'i> QualifiedRuleParser<'i> for KeyframeListParser<'a> {
fn parse_block<'t>(
&mut self,
selector: Self::Prelude,
source_location: SourceLocation,
start: &ParserState,
input: &mut Parser<'i, 't>,
) -> Result<Self::QualifiedRule, ParseError<'i>> {
let context = ParserContext::new_with_rule_type(
......@@ -566,7 +566,7 @@ impl<'a, 'i> QualifiedRuleParser<'i> for KeyframeListParser<'a> {
Ok(Arc::new(self.shared_lock.wrap(Keyframe {
selector,
block: Arc::new(self.shared_lock.wrap(block)),
source_location,
source_location: start.source_location(),
})))
}
}
......
......@@ -27,7 +27,7 @@ use crate::values::computed::font::FamilyName;
use crate::values::{CssUrl, CustomIdent, KeyframesName};
use crate::{Namespace, Prefix};
use cssparser::{AtRuleParser, AtRuleType, Parser, QualifiedRuleParser, RuleListParser};
use cssparser::{BasicParseError, BasicParseErrorKind, CowRcStr, SourceLocation};
use cssparser::{BasicParseError, BasicParseErrorKind, CowRcStr, ParserState};
use selectors::SelectorList;
use servo_arc::Arc;
use style_traits::{ParseError, StyleParseErrorKind};
......@@ -251,10 +251,10 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> {
fn parse_block<'t>(
&mut self,
prelude: AtRuleBlockPrelude,
location: SourceLocation,
start: &ParserState,
input: &mut Parser<'i, 't>,
) -> Result<CssRule, ParseError<'i>> {
AtRuleParser::parse_block(&mut self.nested(), prelude, location, input).map(|rule| {
AtRuleParser::parse_block(&mut self.nested(), prelude, start, input).map(|rule| {
self.state = State::Body;
rule
})
......@@ -264,8 +264,8 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> {
fn rule_without_block(
&mut self,
prelude: AtRuleNonBlockPrelude,
source_location: SourceLocation,
) -> CssRule {
start: &ParserState,
) -> Self::AtRule {
match prelude {
AtRuleNonBlockPrelude::Import(url, media) => {
let loader = self
......@@ -274,7 +274,7 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> {
let import_rule = loader.request_stylesheet(
url,
source_location,
start.source_location(),
&self.context,
&self.shared_lock,
media,
......@@ -296,7 +296,7 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> {
CssRule::Namespace(Arc::new(self.shared_lock.wrap(NamespaceRule {
prefix,
url,
source_location,
source_location: start.source_location(),
})))
},
}
......@@ -324,10 +324,10 @@ impl<'a, 'i> QualifiedRuleParser<'i> for TopLevelRuleParser<'a> {
fn parse_block<'t>(
&mut self,
prelude: Self::Prelude,
location: SourceLocation,
start: &ParserState,
input: &mut Parser<'i, 't>,
) -> Result<CssRule, ParseError<'i>> {
QualifiedRuleParser::parse_block(&mut self.nested(), prelude, location, input).map(
QualifiedRuleParser::parse_block(&mut self.nested(), prelude, start, input).map(
|result| {
self.state = State::Body;
result
......@@ -461,7 +461,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
fn parse_block<'t>(
&mut self,
prelude: AtRuleBlockPrelude,
source_location: SourceLocation,
start: &ParserState,
input: &mut Parser<'i, 't>,
) -> Result<CssRule, ParseError<'i>> {
match prelude {
......@@ -473,7 +473,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
);
Ok(CssRule::FontFace(Arc::new(self.shared_lock.wrap(
parse_font_face_block(&context, input, source_location).into(),
parse_font_face_block(&context, input, start.source_location()).into(),
))))
},
AtRuleBlockPrelude::FontFeatureValues(family_names) => {
......@@ -484,7 +484,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
);
Ok(CssRule::FontFeatureValues(Arc::new(self.shared_lock.wrap(
FontFeatureValuesRule::parse(&context, input, family_names, source_location),
FontFeatureValuesRule::parse(&context, input, family_names, start.source_location()),
))))
},
AtRuleBlockPrelude::CounterStyle(name) => {
......@@ -495,14 +495,14 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
);
Ok(CssRule::CounterStyle(Arc::new(self.shared_lock.wrap(
parse_counter_style_body(name, &context, input, source_location)?.into(),
parse_counter_style_body(name, &context, input, start.source_location())?.into(),
))))
},
AtRuleBlockPrelude::Media(media_queries) => {
Ok(CssRule::Media(Arc::new(self.shared_lock.wrap(MediaRule {
media_queries,
rules: self.parse_nested_rules(input, CssRuleType::Media),
source_location,
source_location: start.source_location(),
}))))
},
AtRuleBlockPrelude::Supports(condition) => {
......@@ -518,7 +518,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
condition,
rules: self.parse_nested_rules(input, CssRuleType::Supports),
enabled,
source_location,
source_location: start.source_location(),
},
))))
},
......@@ -545,7 +545,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
name,
keyframes: parse_keyframe_list(&context, input, self.shared_lock),
vendor_prefix,
source_location,
source_location: start.source_location(),
},
))))
},
......@@ -559,7 +559,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
let declarations = parse_property_declaration_list(&context, input, None);
Ok(CssRule::Page(Arc::new(self.shared_lock.wrap(PageRule {
block: Arc::new(self.shared_lock.wrap(declarations)),
source_location,
source_location: start.source_location(),
}))))
},
AtRuleBlockPrelude::Document(condition) => {
......@@ -570,7 +570,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
DocumentRule {
condition,
rules: self.parse_nested_rules(input, CssRuleType::Document),
source_location,
source_location: start.source_location(),
},
))))
},
......@@ -598,7 +598,7 @@ impl<'a, 'b, 'i> QualifiedRuleParser<'i> for NestedRuleParser<'a, 'b> {
fn parse_block<'t>(
&mut self,
selectors: Self::Prelude,
source_location: SourceLocation,
start: &ParserState,
input: &mut Parser<'i, 't>,
) -> Result<CssRule, ParseError<'i>> {
let context =
......@@ -609,7 +609,7 @@ impl<'a, 'b, 'i> QualifiedRuleParser<'i> for NestedRuleParser<'a, 'b> {
Ok(CssRule::Style(Arc::new(self.shared_lock.wrap(StyleRule {
selectors,
block,
source_location,
source_location: start.source_location(),
}))))
}
}
......@@ -15,7 +15,7 @@ gecko = []
[dependencies]
app_units = "0.7"
cssparser = "0.27"
cssparser = "0.28"
bitflags = "1.0"
euclid = "0.20"
lazy_static = "1"
......
......@@ -14,7 +14,7 @@ servo = ["cssparser/serde", "string_cache"]
gecko = []
[dependencies]
cssparser = "0.27"
cssparser = "0.28"
servo_arc = { path = "../servo_arc" }
smallbitvec = "2.1.1"
smallvec = "1.0"
......
......@@ -16,7 +16,7 @@ gecko_refcount_logging = ["style/gecko_refcount_logging", "servo_arc/gecko_refco
[dependencies]
atomic_refcell = "0.1"
bincode = "1.0"
cssparser = "0.27"
cssparser = "0.28"
cstr = "0.1.2"
libc = "0.2"
log = {version = "0.4", features = ["release_max_level_info"]}
......
......@@ -11,7 +11,7 @@ doctest = false
[dependencies]
atomic_refcell = "0.1"
cssparser = "0.27"
cssparser = "0.28"
cstr = "0.1.2"
env_logger = { version = "0.6", default-features = false }
geckoservo = {path = "../../../ports/geckolib"}
......
......@@ -12,7 +12,7 @@ doctest = false
[dependencies]
byteorder = "1.0"
app_units = "0.7"
cssparser = "0.27"
cssparser = "0.28"
euclid = "0.20"
html5ever = "0.22"
parking_lot = "0.10"
......
{"files":{"Cargo.toml":"53761c6ce14b954599553cc780908f422dc9e48b6183876a7be0e435fd200fa0","LICENSE":"fab3dd6bdab226f1c08630b1dd917e11fcb4ec5e1e020e2c16f83a0a13863e85","README.md":"a533b45a9c43083c6a6000a9c99a1acfed123d6430b232352ae02f1144a09f12","build.rs":"a9619dbf086f20d3cbfee2b05c1a761f683acb30191d7286d24ad53617e9043b","build/match_byte.rs":"f57faf0597cb7b3e32999c5fb1215a43a5603121588c67d5031f720362171e1c","docs/404.html":"025861f76f8d1f6d67c20ab624c6e418f4f824385e2dd8ad8732c4ea563c6a2e","docs/index.html":"025861f76f8d1f6d67c20ab624c6e418f4f824385e2dd8ad8732c4ea563c6a2e","src/color.rs":"d2e14b341fbc2d141b1fed4b4a91b31e32bf92461b067036bd4227cda19e4e72","src/cow_rc_str.rs":"89b5dff5cf80eef3fcff0c11799e54a978d02d8b8963a621fbb999d35e7c03a3","src/from_bytes.rs":"b1cf15c4e975523fef46b575598737a39f3c63e5ce0b2bfd6ec627c69c6ea54a","src/lib.rs":"2b20764b713020d59b7533ee686ef688ad70e85f61d2b3fab70e1af0f409f8e4","src/macros.rs":"cc5b13b5c605cd138b8311a9484d184fa3d063189e75d291223178f9eafe53c7","src/nth.rs":"2490db52a28d09009d73474336f12738ef5f0ffbbc4f1b49ee1e56ca9ca8b34b","src/parser.rs":"3bfeeda068567699e6ff5a6967c95473bc99910aedceb406347e05a98339cdac","src/rules_and_declarations.rs":"19d0079eca3e1776823ef8a16a0afd1619b9f7a392068c583487d891674225b2","src/serializer.rs":"c3b810e0970688a40d279101c379cfee110b100e1ff1a2cc40363971fd7bf591","src/size_of_tests.rs":"acd10556e060e4149e9f565f36058ca26bf3b3296d512d45127845fa12b94539","src/tests.rs":"247b0b332e77c1703ffbaaad9b5540571609e0fdc49f91998171820619d06f03","src/tokenizer.rs":"76360e46c0efceff82b6336b3522c95bdb8ef96379a617e7eed12eec9bad7ab7","src/unicode_range.rs":"20d96f06fbb73921e308cc340c9fe065e27f19843005689fb259007a6a372bcc"},"package":"754b69d351cdc2d8ee09ae203db831e005560fc6030da058f86ad60c92a9cb0a"}
\ No newline at end of file
{"files":{"Cargo.toml":"3433246693b26ae30214281dadded990707a23c70bc915ee2ca5b1482f15b05c","LICENSE":"fab3dd6bdab226f1c08630b1dd917e11fcb4ec5e1e020e2c16f83a0a13863e85","README.md":"a533b45a9c43083c6a6000a9c99a1acfed123d6430b232352ae02f1144a09f12","build.rs":"a9619dbf086f20d3cbfee2b05c1a761f683acb30191d7286d24ad53617e9043b","build/match_byte.rs":"f57faf0597cb7b3e32999c5fb1215a43a5603121588c67d5031f720362171e1c","docs/404.html":"025861f76f8d1f6d67c20ab624c6e418f4f824385e2dd8ad8732c4ea563c6a2e","docs/index.html":"025861f76f8d1f6d67c20ab624c6e418f4f824385e2dd8ad8732c4ea563c6a2e","src/color.rs":"d8f574e2b6b3f5c144e5030037eb5e9db31d96d484a60e6503ca98395fd7f3af","src/cow_rc_str.rs":"89b5dff5cf80eef3fcff0c11799e54a978d02d8b8963a621fbb999d35e7c03a3","src/from_bytes.rs":"b1cf15c4e975523fef46b575598737a39f3c63e5ce0b2bfd6ec627c69c6ea54a","src/lib.rs":"2b20764b713020d59b7533ee686ef688ad70e85f61d2b3fab70e1af0f409f8e4","src/macros.rs":"cc5b13b5c605cd138b8311a9484d184fa3d063189e75d291223178f9eafe53c7","src/nth.rs":"ae2f8b0f2c9e8b1ffb3cb842ca78c0060829a7d2e0762d1eb427f40188686ba1","src/parser.rs":"5c8ed6ccc069d0d2526016aeeba7200275b5fb1d8271926ccdb7a848124cde45","src/rules_and_declarations.rs":"1f171431f5f4d0d6bd631deeb7c684100c6e15f10e06b8fff1e6d676567c27c3","src/serializer.rs":"c3b810e0970688a40d279101c379cfee110b100e1ff1a2cc40363971fd7bf591","src/size_of_tests.rs":"acd10556e060e4149e9f565f36058ca26bf3b3296d512d45127845fa12b94539","src/tests.rs":"8022811a7fc90199e1f775fb1cf567ac15fca8a00d5f2cf934863a8b36997cba","src/tokenizer.rs":"76360e46c0efceff82b6336b3522c95bdb8ef96379a617e7eed12eec9bad7ab7","src/unicode_range.rs":"20d96f06fbb73921e308cc340c9fe065e27f19843005689fb259007a6a372bcc"},"package":"809d22aba9ffd53e9028f2d37261f1826ef613d0e96b1a5ddeefa97cde82bcca"}
\ No newline at end of file
......@@ -13,7 +13,7 @@
[package]
edition = "2018"
name = "cssparser"
version = "0.27.2"
version = "0.28.0"
authors = ["Simon Sapin <simon.sapin@exyr.org>"]
build = "build.rs"
exclude = ["src/css-parsing-tests/**", "src/big-data-url.css"]
......
......@@ -291,7 +291,7 @@ impl Color {
let name = name.clone();
return input.parse_nested_block(|arguments| {
parse_color_function(component_parser, &*name, arguments)
})
});
}
_ => Err(()),
}
......
......@@ -73,12 +73,12 @@ pub fn parse_nth<'i, 't>(input: &mut Parser<'i, 't>) -> Result<(i32, i32), Basic
ref token => {
let token = token.clone();
Err(input.new_basic_unexpected_token_error(token))
},
}
},
ref token => {
let token = token.clone();
Err(input.new_basic_unexpected_token_error(token))
},
}
}
}
......
......@@ -933,17 +933,15 @@ impl<'i: 't, 't> Parser<'i, 't> {
Ok(&Token::Function(_))
| Ok(&Token::ParenthesisBlock)
| Ok(&Token::SquareBracketBlock)
| Ok(&Token::CurlyBracketBlock) => {
self.parse_nested_block(|input| {
input.expect_no_error_token().map_err(Into::into)
}).map_err(ParseError::<()>::basic)?
}
| Ok(&Token::CurlyBracketBlock) => self
.parse_nested_block(|input| input.expect_no_error_token().map_err(Into::into))
.map_err(ParseError::<()>::basic)?,
Ok(t) => {
// FIXME: maybe these should be separate variants of
// BasicParseError instead?
if t.is_parse_error() {
let token = t.clone();
return Err(self.new_basic_unexpected_token_error(token))
return Err(self.new_basic_unexpected_token_error(token));
}
}
Err(_) => return Ok(()),
......
......@@ -5,7 +5,7 @@
// https://drafts.csswg.org/css-syntax/#parsing
use super::{BasicParseError, BasicParseErrorKind, Delimiter};
use super::{ParseError, Parser, SourceLocation, Token};
use super::{ParseError, Parser, Token};
use crate::cow_rc_str::CowRcStr;
use crate::parser::{parse_nested_block, parse_until_after, parse_until_before, ParserState};
......@@ -130,10 +130,10 @@ pub trait AtRuleParser<'i> {
fn rule_without_block(
&mut self,
prelude: Self::PreludeNoBlock,
location: SourceLocation,
start: &ParserState,
) -> Self::AtRule {
let _ = prelude;
let _ = location;
let _ = start;
panic!(
"The `AtRuleParser::rule_without_block` method must be overriden \
if `AtRuleParser::parse_prelude` ever returns `AtRuleType::WithoutBlock`."
......@@ -153,11 +153,11 @@ pub trait AtRuleParser<'i> {
fn parse_block<'t>(
&mut self,
prelude: Self::PreludeBlock,
location: SourceLocation,
start: &ParserState,
input: &mut Parser<'i, 't>,
) -> Result<Self::AtRule, ParseError<'i, Self::Error>> {
let _ = prelude;
let _ = location;
let _ = start;
let _ = input;
Err(input.new_error(BasicParseErrorKind::AtRuleBodyInvalid))
}
......@@ -210,11 +210,11 @@ pub trait QualifiedRuleParser<'i> {
fn parse_block<'t>(
&mut self,
prelude: Self::Prelude,
location: SourceLocation,
start: &ParserState,
input: &mut Parser<'i, 't>,
) -> Result<Self::QualifiedRule, ParseError<'i, Self::Error>> {
let _ = prelude;
let _ = location;
let _ = start;
let _ = input;
Err(input.new_error(BasicParseErrorKind::QualifiedRuleInvalid))
}
......@@ -267,7 +267,9 @@ where
loop {
let start = self.input.state();
match self.input.next_including_whitespace_and_comments() {
Ok(&Token::WhiteSpace(_)) | Ok(&Token::Comment(_)) | Ok(&Token::Semicolon) => continue,
Ok(&Token::WhiteSpace(_)) | Ok(&Token::Comment(_)) | Ok(&Token::Semicolon) => {
continue
}
Ok(&Token::Ident(ref name)) => {
let name = name.clone();
let result = {
......@@ -288,9 +290,7 @@ where
Ok(token) => {
let token = token.clone();
let result = self.input.parse_until_after(Delimiter::Semicolon, |_| {
Err(start
.source_location()
.new_unexpected_token_error(token))
Err(start.source_location().new_unexpected_token_error(token))
});
return Some(result.map_err(|e| (e, self.input.slice_from(start.position()))));
}
......@@ -370,15 +370,13 @@ where
let start = self.input.state();
let at_keyword = match self.input.next_byte()? {
b'@' => {
match self.input.next_including_whitespace_and_comments() {
Ok(&Token::AtKeyword(ref name)) => Some(name.clone()),
_ => {
self.input.reset(&start);
None
},
b'@' => match self.input.next_including_whitespace_and_comments() {
Ok(&Token::AtKeyword(ref name)) => Some(name.clone()),
_ => {
self.input.reset(&start);
None
}
}
},
_ => None,
};
......@@ -465,14 +463,13 @@ fn parse_at_rule<'i, 't, P, E>(
where
P: AtRuleParser<'i, Error = E>,
{
let location = input.current_source_location();
let delimiters = Delimiter::Semicolon | Delimiter::CurlyBracketBlock;
// FIXME: https://github.com/servo/rust-cssparser/issues/254
let callback = |input: &mut Parser<'i, '_>| parser.parse_prelude(name, input);
let result = parse_until_before(input, delimiters, callback);
match result {
Ok(AtRuleType::WithoutBlock(prelude)) => match input.next() {
Ok(&Token::Semicolon) | Err(_) => Ok(parser.rule_without_block(prelude, location)),
Ok(&Token::Semicolon) | Err(_) => Ok(parser.rule_without_block(prelude, start)),
Ok(&Token::CurlyBracketBlock) => Err((
input.new_unexpected_token_error(Token::CurlyBracketBlock),
input.slice_from(start.position()),
......@@ -484,7 +481,7 @@ where
Ok(&Token::CurlyBracketBlock) => {
// FIXME: https://github.com/servo/rust-cssparser/issues/254
let callback =
|input: &mut Parser<'i, '_>| parser.parse_block(prelude, location, input);
|input: &mut Parser<'i, '_>| parser.parse_block(prelude, start, input);
parse_nested_block(input, callback)
.map_err(|e| (e, input.slice_from(start.position())))
}
......@@ -514,7 +511,7 @@ fn parse_qualified_rule<'i, 't, P, E>(
where
P: QualifiedRuleParser<'i, Error = E>,
{
let location = input.current_source_location();
let start = input.state();
// FIXME: https://github.com/servo/rust-cssparser/issues/254
let callback = |input: &mut Parser<'i, '_>| parser.parse_prelude(input);
let prelude = parse_until_before(input, Delimiter::CurlyBracketBlock, callback);
......@@ -523,8 +520,7 @@ where
// Do this here so that we consume the `{` even if the prelude is `Err`.
let prelude = prelude?;
// FIXME: https://github.com/servo/rust-cssparser/issues/254
let callback =
|input: &mut Parser<'i, '_>| parser.parse_block(prelude, location, input);
let callback = |input: &mut Parser<'i, '_>| parser.parse_block(prelude, &start, input);
parse_nested_block(input, callback)
}
_ => unreachable!(),
......
......@@ -16,8 +16,8 @@ use super::{
parse_important, parse_nth, parse_one_declaration, parse_one_rule, stylesheet_encoding,
AtRuleParser, AtRuleType, BasicParseError, BasicParseErrorKind, Color, CowRcStr,
DeclarationListParser, DeclarationParser, Delimiter, EncodingSupport, ParseError,
ParseErrorKind, Parser, ParserInput, QualifiedRuleParser, RuleListParser, SourceLocation,
ToCss, Token, TokenSerializationType, UnicodeRange, RGBA,
ParseErrorKind, Parser, ParserInput, ParserState, QualifiedRuleParser, RuleListParser,
SourceLocation, ToCss, Token, TokenSerializationType, UnicodeRange, RGBA,
};
macro_rules! JArray {
......@@ -469,11 +469,10 @@ fn serializer(preserve_comments: bool) {
_ => None,
};
if let Some(closing_token) = closing_token {
let result: Result<_, ParseError<()>> =
input.parse_nested_block(|input| {
write_to(previous_token, input, string, preserve_comments);
Ok(())
});
let result: Result<_, ParseError<()>> = input.parse_nested_block(|input| {
write_to(previous_token, input, string, preserve_comments);
Ok(())
});
result.unwrap();
closing_token.to_css(string).unwrap();
}
......@@ -947,7 +946,7 @@ impl<'i> AtRuleParser<'i> for JsonParser {
}
}
fn rule_without_block(&mut self, mut prelude: Vec<Value>, _location: SourceLocation) -> Value {
fn rule_without_block(&mut self, mut prelude: Vec<Value>, _: &ParserState) -> Value {
prelude.push(Value::Null);
Value::Array(prelude)
}
......@@ -955,7 +954,7 @@ impl<'i> AtRuleParser<'i> for JsonParser {
fn parse_block<'t>(
&mut self,
mut prelude: Vec<Value>,
_location: SourceLocation,
_: &ParserState,
input: &mut Parser<'i, 't>,
) -> Result<Value, ParseError<'i, ()>> {
prelude.push(Value::Array(component_values_to_json(input)));
......@@ -978,7 +977,7 @@ impl<'i> QualifiedRuleParser<'i> for JsonParser {
fn parse_block<'t>(
&mut self,
prelude: Vec<Value>,
_location: SourceLocation,
_: &ParserState,
input: &mut Parser<'i, 't>,
) -> Result<Value, ParseError<'i, ()>> {
Ok(JArray![
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment