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:
Tom Tromey 2017-08-24 07:37:02 -06:00
parent a266e96d28
commit 546ecaeee9
11 changed files with 26 additions and 60 deletions

View file

@ -53,8 +53,6 @@ pub struct ParserContext<'a> {
pub url_data: &'a UrlExtraData,
/// The current rule type, if any.
pub rule_type: Option<CssRuleType>,
/// Line number offsets for inline stylesheets
pub line_number_offset: u64,
/// The mode to use when parsing.
pub parsing_mode: ParsingMode,
/// The quirks mode of this stylesheet.
@ -76,7 +74,6 @@ impl<'a> ParserContext<'a> {
stylesheet_origin: stylesheet_origin,
url_data: url_data,
rule_type: rule_type,
line_number_offset: 0u64,
parsing_mode: parsing_mode,
quirks_mode: quirks_mode,
namespaces: None,
@ -109,32 +106,12 @@ impl<'a> ParserContext<'a> {
stylesheet_origin: context.stylesheet_origin,
url_data: context.url_data,
rule_type: Some(rule_type),
line_number_offset: context.line_number_offset,
parsing_mode: context.parsing_mode,
quirks_mode: context.quirks_mode,
namespaces: Some(namespaces),
}
}
/// Create a parser context for inline CSS which accepts additional line offset argument.
pub fn new_with_line_number_offset(
stylesheet_origin: Origin,
url_data: &'a UrlExtraData,
line_number_offset: u64,
parsing_mode: ParsingMode,
quirks_mode: QuirksMode,
) -> ParserContext<'a> {
ParserContext {
stylesheet_origin: stylesheet_origin,
url_data: url_data,
rule_type: None,
line_number_offset: line_number_offset,
parsing_mode: parsing_mode,
quirks_mode: quirks_mode,
namespaces: None,
}
}
/// Get the rule type, which assumes that one is available.
pub fn rule_type(&self) -> CssRuleType {
self.rule_type.expect("Rule type expected, but none was found.")
@ -148,7 +125,7 @@ impl<'a> ParserContext<'a> {
where R: ParseErrorReporter
{
let location = SourceLocation {
line: location.line + self.line_number_offset as u32,
line: location.line,
column: location.column,
};
context.error_reporter.report_error(self.url_data, location, error)