mirror of
https://github.com/servo/servo.git
synced 2025-08-16 19:05: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,
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ impl StylesheetContents {
|
|||
stylesheet_loader: Option<&StylesheetLoader>,
|
||||
error_reporter: &R,
|
||||
quirks_mode: QuirksMode,
|
||||
line_number_offset: u64
|
||||
line_number_offset: u32
|
||||
) -> Self {
|
||||
let namespaces = RwLock::new(Namespaces::default());
|
||||
let (rules, source_map_url) = Stylesheet::parse_rules(
|
||||
|
@ -311,7 +311,7 @@ impl Stylesheet {
|
|||
url_data: UrlExtraData,
|
||||
stylesheet_loader: Option<&StylesheetLoader>,
|
||||
error_reporter: &R,
|
||||
line_number_offset: u64)
|
||||
line_number_offset: u32)
|
||||
where R: ParseErrorReporter
|
||||
{
|
||||
let namespaces = RwLock::new(Namespaces::default());
|
||||
|
@ -349,17 +349,17 @@ impl Stylesheet {
|
|||
stylesheet_loader: Option<&StylesheetLoader>,
|
||||
error_reporter: &R,
|
||||
quirks_mode: QuirksMode,
|
||||
line_number_offset: u64
|
||||
line_number_offset: u32
|
||||
) -> (Vec<CssRule>, Option<String>) {
|
||||
let mut rules = Vec::new();
|
||||
let mut input = ParserInput::new(css);
|
||||
let mut input = ParserInput::new_with_line_number_offset(css, line_number_offset);
|
||||
let mut input = Parser::new(&mut input);
|
||||
|
||||
let context =
|
||||
ParserContext::new_with_line_number_offset(
|
||||
ParserContext::new(
|
||||
origin,
|
||||
url_data,
|
||||
line_number_offset,
|
||||
None,
|
||||
PARSING_MODE_DEFAULT,
|
||||
quirks_mode
|
||||
);
|
||||
|
@ -410,7 +410,7 @@ impl Stylesheet {
|
|||
stylesheet_loader: Option<&StylesheetLoader>,
|
||||
error_reporter: &R,
|
||||
quirks_mode: QuirksMode,
|
||||
line_number_offset: u64)
|
||||
line_number_offset: u32)
|
||||
-> Stylesheet
|
||||
{
|
||||
let contents = StylesheetContents::from_str(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue