From 32cd0b4ea043c8b50867abff709dcdccb5d426b0 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Thu, 5 Apr 2018 08:43:52 +1000 Subject: [PATCH] Add source_location to CounterStyleRule. --- components/style/counter_style/mod.rs | 21 +++++++++++++-------- components/style/stylesheets/rule_parser.rs | 15 +++++++++++---- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/components/style/counter_style/mod.rs b/components/style/counter_style/mod.rs index 2f4607507708..451cbe183096 100644 --- a/components/style/counter_style/mod.rs +++ b/components/style/counter_style/mod.rs @@ -8,7 +8,7 @@ use Atom; use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser}; -use cssparser::{Parser, Token, CowRcStr}; +use cssparser::{Parser, Token, CowRcStr, SourceLocation}; use error_reporting::{ContextualParseError, ParseErrorReporter}; #[cfg(feature = "gecko")] use gecko::rules::CounterStyleDescriptors; #[cfg(feature = "gecko")] use gecko_bindings::structs::{ nsCSSCounterDesc, nsCSSValue }; @@ -70,15 +70,17 @@ pub fn parse_counter_style_name_definition<'i, 't>( } /// Parse the body (inside `{}`) of an @counter-style rule -pub fn parse_counter_style_body<'i, 't, R>(name: CustomIdent, - context: &ParserContext, - error_context: &ParserErrorContext, - input: &mut Parser<'i, 't>) - -> Result> +pub fn parse_counter_style_body<'i, 't, R>( + name: CustomIdent, + context: &ParserContext, + error_context: &ParserErrorContext, + input: &mut Parser<'i, 't>, + location: SourceLocation, +) -> Result> where R: ParseErrorReporter { let start = input.current_source_location(); - let mut rule = CounterStyleRuleData::empty(name); + let mut rule = CounterStyleRuleData::empty(name, location); { let parser = CounterStyleRuleParser { context: context, @@ -153,15 +155,18 @@ macro_rules! counter_style_descriptors { #[$doc] $ident: Option<$ty>, )+ + /// Line and column of the @counter-style rule source code. + pub source_location: SourceLocation, } impl CounterStyleRuleData { - fn empty(name: CustomIdent) -> Self { + fn empty(name: CustomIdent, source_location: SourceLocation) -> Self { CounterStyleRuleData { name: name, $( $ident: None, )+ + source_location, } } diff --git a/components/style/stylesheets/rule_parser.rs b/components/style/stylesheets/rule_parser.rs index 714a07308821..ff4a609ed6dd 100644 --- a/components/style/stylesheets/rule_parser.rs +++ b/components/style/stylesheets/rule_parser.rs @@ -114,7 +114,7 @@ pub enum AtRuleBlockPrelude { /// A @font-feature-values rule prelude, with its FamilyName list. FontFeatureValues(Vec, SourceLocation), /// A @counter-style rule prelude, with its counter style name. - CounterStyle(CustomIdent), + CounterStyle(CustomIdent, SourceLocation), /// A @media rule prelude, with its media queries. Media(Arc>, SourceLocation), /// An @supports rule, with its conditional @@ -382,7 +382,7 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a return Err(input.new_custom_error(StyleParseErrorKind::UnsupportedAtRule(name.clone()))) } let name = parse_counter_style_name_definition(input)?; - Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::CounterStyle(name))) + Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::CounterStyle(name, location))) }, "viewport" => { if viewport_rule::enabled() { @@ -455,7 +455,7 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a Ok(CssRule::FontFeatureValues(Arc::new(self.shared_lock.wrap( FontFeatureValuesRule::parse(&context, self.error_context, input, family_names, location))))) } - AtRuleBlockPrelude::CounterStyle(name) => { + AtRuleBlockPrelude::CounterStyle(name, location) => { let context = ParserContext::new_with_rule_type( self.context, CssRuleType::CounterStyle, @@ -463,7 +463,14 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a ); Ok(CssRule::CounterStyle(Arc::new(self.shared_lock.wrap( - parse_counter_style_body(name, &context, self.error_context, input)?.into())))) + parse_counter_style_body( + name, + &context, + self.error_context, + input, + location + )?.into() + )))) } AtRuleBlockPrelude::Media(media_queries, location) => { Ok(CssRule::Media(Arc::new(self.shared_lock.wrap(MediaRule {