mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Use cssparser's new_with_line_number_offset
cssparser provides a way to set the initial line number on a ParserInput. This patch changes servo to use this facility, rather than reimplement the same functionality itself.
This commit is contained in:
parent
a266e96d28
commit
546ecaeee9
11 changed files with 26 additions and 60 deletions
|
@ -160,10 +160,7 @@ impl<'a, 'i, R: ParseErrorReporter> AtRuleParser<'i> for TopLevelRuleParser<'a,
|
|||
name: CowRcStr<'i>,
|
||||
input: &mut Parser<'i, 't>
|
||||
) -> Result<AtRuleType<AtRulePrelude, CssRule>, ParseError<'i>> {
|
||||
let location = get_location_with_offset(
|
||||
input.current_source_location(),
|
||||
self.context.line_number_offset,
|
||||
);
|
||||
let location = get_location_with_offset(input.current_source_location());
|
||||
match_ignore_ascii_case! { &*name,
|
||||
"import" => {
|
||||
if self.state > State::Imports {
|
||||
|
@ -334,11 +331,7 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a
|
|||
name: CowRcStr<'i>,
|
||||
input: &mut Parser<'i, 't>
|
||||
) -> Result<AtRuleType<AtRulePrelude, CssRule>, ParseError<'i>> {
|
||||
let location =
|
||||
get_location_with_offset(
|
||||
input.current_source_location(),
|
||||
self.context.line_number_offset
|
||||
);
|
||||
let location = get_location_with_offset(input.current_source_location());
|
||||
|
||||
match_ignore_ascii_case! { &*name,
|
||||
"media" => {
|
||||
|
@ -545,8 +538,7 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for NestedRulePa
|
|||
url_data: Some(self.context.url_data),
|
||||
};
|
||||
|
||||
let location = get_location_with_offset(input.current_source_location(),
|
||||
self.context.line_number_offset);
|
||||
let location = get_location_with_offset(input.current_source_location());
|
||||
let selectors = SelectorList::parse(&selector_parser, input)?;
|
||||
|
||||
Ok(QualifiedRuleParserPrelude {
|
||||
|
@ -575,13 +567,10 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for NestedRulePa
|
|||
}
|
||||
}
|
||||
|
||||
/// Calculates the location of a rule's source given an offset.
|
||||
fn get_location_with_offset(
|
||||
location: SourceLocation,
|
||||
offset: u64
|
||||
) -> SourceLocation {
|
||||
/// Adjust a location's column to accommodate DevTools.
|
||||
fn get_location_with_offset(location: SourceLocation) -> SourceLocation {
|
||||
SourceLocation {
|
||||
line: location.line + offset as u32,
|
||||
line: location.line,
|
||||
// Column offsets are not yet supported, but Gecko devtools expect 1-based columns.
|
||||
column: location.column + 1,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue