Skip to content

Commit

Permalink
stylo: set location for NestedRuleParser during prelude parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ferjm committed Jun 15, 2017
1 parent 18653f6 commit 7334298
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
31 changes: 20 additions & 11 deletions components/style/stylesheets/rule_parser.rs
Expand Up @@ -257,15 +257,19 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> {
}
}

pub struct QualifiedRuleParserPrelude {
selectors: SelectorList<SelectorImpl>,
source_location: SourceLocation,
}

impl<'a, 'i> QualifiedRuleParser<'i> for TopLevelRuleParser<'a> {
type Prelude = SelectorList<SelectorImpl>;
type Prelude = QualifiedRuleParserPrelude;
type QualifiedRule = CssRule;
type Error = SelectorParseError<'i, StyleParseError<'i>>;

#[inline]
fn parse_prelude<'t>(&mut self, input: &mut Parser<'i, 't>)
-> Result<SelectorList<SelectorImpl>, ParseError<'i>> {
-> Result<QualifiedRuleParserPrelude, ParseError<'i>> {
self.state = State::Body;

// "Freeze" the namespace map (no more namespace rules can be parsed
Expand All @@ -281,7 +285,7 @@ impl<'a, 'i> QualifiedRuleParser<'i> for TopLevelRuleParser<'a> {
#[inline]
fn parse_block<'t>(
&mut self,
prelude: SelectorList<SelectorImpl>,
prelude: QualifiedRuleParserPrelude,
input: &mut Parser<'i, 't>
) -> Result<CssRule, ParseError<'i>> {
QualifiedRuleParser::parse_block(&mut self.nested(), prelude, input)
Expand Down Expand Up @@ -482,33 +486,38 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
}

impl<'a, 'b, 'i> QualifiedRuleParser<'i> for NestedRuleParser<'a, 'b> {
type Prelude = SelectorList<SelectorImpl>;
type Prelude = QualifiedRuleParserPrelude;
type QualifiedRule = CssRule;
type Error = SelectorParseError<'i, StyleParseError<'i>>;

fn parse_prelude<'t>(&mut self, input: &mut Parser<'i, 't>)
-> Result<SelectorList<SelectorImpl>, ParseError<'i>> {
-> Result<QualifiedRuleParserPrelude, ParseError<'i>> {
let selector_parser = SelectorParser {
stylesheet_origin: self.stylesheet_origin,
namespaces: self.context.namespaces.unwrap(),
};

SelectorList::parse(&selector_parser, input)
let location = get_location_with_offset(input.current_source_location(),
self.context.line_number_offset);
let selectors = SelectorList::parse(&selector_parser, input)?;

Ok(QualifiedRuleParserPrelude {
selectors: selectors,
source_location: location,
})
}

fn parse_block<'t>(
&mut self,
prelude: SelectorList<SelectorImpl>,
prelude: QualifiedRuleParserPrelude,
input: &mut Parser<'i, 't>
) -> Result<CssRule, ParseError<'i>> {
let location = get_location_with_offset(input.current_source_location(),
self.context.line_number_offset);
let context = ParserContext::new_with_rule_type(self.context, Some(CssRuleType::Style));
let declarations = parse_property_declaration_list(&context, input);
Ok(CssRule::Style(Arc::new(self.shared_lock.wrap(StyleRule {
selectors: prelude,
selectors: prelude.selectors,
block: Arc::new(self.shared_lock.wrap(declarations)),
source_location: location,
source_location: prelude.source_location,
}))))
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/style/stylesheets.rs
Expand Up @@ -116,7 +116,7 @@ fn test_parse_stylesheet() {
]))),
source_location: SourceLocation {
line: 3,
column: 31,
column: 9,
},
}))),
CssRule::Style(Arc::new(stylesheet.shared_lock.wrap(StyleRule {
Expand All @@ -143,7 +143,7 @@ fn test_parse_stylesheet() {
]))),
source_location: SourceLocation {
line: 11,
column: 27,
column: 9,
},
}))),
CssRule::Style(Arc::new(stylesheet.shared_lock.wrap(StyleRule {
Expand Down Expand Up @@ -205,7 +205,7 @@ fn test_parse_stylesheet() {
]))),
source_location: SourceLocation {
line: 15,
column: 20,
column: 9,
},
}))),
CssRule::Keyframes(Arc::new(stylesheet.shared_lock.wrap(KeyframesRule {
Expand Down

0 comments on commit 7334298

Please sign in to comment.