mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
style: Move the error reporter into ParserContext.
Summary: This should make it easier to report errors, and also reduce codesize. The reason this was so generic is that error reporting was unconditionally enabled and was super-hot, but now that's no longer the case after bug 1452143, so we can afford the virtual call in the "error reporting enabled" case. This opens the possibility of simplifying a lot the error setup as well, though this patch doesn't do it. Test Plan: No behavior change, so no new tests. Reviewers: xidorn Bug #: 1469957 Differential Revision: https://phabricator.services.mozilla.com/D1734 MozReview-Commit-ID: F3wTdhX9MB5
This commit is contained in:
parent
bab7be63b2
commit
3a0c3224b9
13 changed files with 128 additions and 194 deletions
|
@ -9,8 +9,8 @@
|
||||||
use Atom;
|
use Atom;
|
||||||
use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser};
|
use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser};
|
||||||
use cssparser::{CowRcStr, Parser, SourceLocation, Token};
|
use cssparser::{CowRcStr, Parser, SourceLocation, Token};
|
||||||
use error_reporting::{ContextualParseError, ParseErrorReporter};
|
use error_reporting::ContextualParseError;
|
||||||
use parser::{Parse, ParserContext, ParserErrorContext};
|
use parser::{Parse, ParserContext};
|
||||||
use selectors::parser::SelectorParseErrorKind;
|
use selectors::parser::SelectorParseErrorKind;
|
||||||
use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard};
|
use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard};
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
|
@ -73,16 +73,12 @@ pub fn parse_counter_style_name_definition<'i, 't>(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse the body (inside `{}`) of an @counter-style rule
|
/// Parse the body (inside `{}`) of an @counter-style rule
|
||||||
pub fn parse_counter_style_body<'i, 't, R>(
|
pub fn parse_counter_style_body<'i, 't>(
|
||||||
name: CustomIdent,
|
name: CustomIdent,
|
||||||
context: &ParserContext,
|
context: &ParserContext,
|
||||||
error_context: &ParserErrorContext<R>,
|
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
location: SourceLocation,
|
location: SourceLocation,
|
||||||
) -> Result<CounterStyleRuleData, ParseError<'i>>
|
) -> Result<CounterStyleRuleData, ParseError<'i>> {
|
||||||
where
|
|
||||||
R: ParseErrorReporter,
|
|
||||||
{
|
|
||||||
let start = input.current_source_location();
|
let start = input.current_source_location();
|
||||||
let mut rule = CounterStyleRuleData::empty(name, location);
|
let mut rule = CounterStyleRuleData::empty(name, location);
|
||||||
{
|
{
|
||||||
|
@ -98,7 +94,7 @@ where
|
||||||
slice,
|
slice,
|
||||||
error,
|
error,
|
||||||
);
|
);
|
||||||
context.log_css_error(error_context, location, error)
|
context.log_css_error(location, error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,7 +130,7 @@ where
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
if let Some(error) = error {
|
if let Some(error) = error {
|
||||||
context.log_css_error(error_context, start, error);
|
context.log_css_error(start, error);
|
||||||
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||||
} else {
|
} else {
|
||||||
Ok(rule)
|
Ok(rule)
|
||||||
|
|
|
@ -249,17 +249,3 @@ impl ParseErrorReporter for RustLogReporter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Error reporter which silently forgets errors
|
|
||||||
pub struct NullReporter;
|
|
||||||
|
|
||||||
impl ParseErrorReporter for NullReporter {
|
|
||||||
fn report_error(
|
|
||||||
&self,
|
|
||||||
_url: &UrlExtraData,
|
|
||||||
_location: SourceLocation,
|
|
||||||
_error: ContextualParseError,
|
|
||||||
) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -10,8 +10,8 @@ use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser};
|
||||||
use cssparser::{CowRcStr, SourceLocation};
|
use cssparser::{CowRcStr, SourceLocation};
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
use cssparser::UnicodeRange;
|
use cssparser::UnicodeRange;
|
||||||
use error_reporting::{ContextualParseError, ParseErrorReporter};
|
use error_reporting::ContextualParseError;
|
||||||
use parser::{Parse, ParserContext, ParserErrorContext};
|
use parser::{Parse, ParserContext};
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
use properties::longhands::font_language_override;
|
use properties::longhands::font_language_override;
|
||||||
use selectors::parser::SelectorParseErrorKind;
|
use selectors::parser::SelectorParseErrorKind;
|
||||||
|
@ -186,15 +186,11 @@ impl ToCss for FontStyle {
|
||||||
/// Parse the block inside a `@font-face` rule.
|
/// Parse the block inside a `@font-face` rule.
|
||||||
///
|
///
|
||||||
/// Note that the prelude parsing code lives in the `stylesheets` module.
|
/// Note that the prelude parsing code lives in the `stylesheets` module.
|
||||||
pub fn parse_font_face_block<R>(
|
pub fn parse_font_face_block(
|
||||||
context: &ParserContext,
|
context: &ParserContext,
|
||||||
error_context: &ParserErrorContext<R>,
|
|
||||||
input: &mut Parser,
|
input: &mut Parser,
|
||||||
location: SourceLocation,
|
location: SourceLocation,
|
||||||
) -> FontFaceRuleData
|
) -> FontFaceRuleData {
|
||||||
where
|
|
||||||
R: ParseErrorReporter,
|
|
||||||
{
|
|
||||||
let mut rule = FontFaceRuleData::empty(location);
|
let mut rule = FontFaceRuleData::empty(location);
|
||||||
{
|
{
|
||||||
let parser = FontFaceRuleParser {
|
let parser = FontFaceRuleParser {
|
||||||
|
@ -206,7 +202,7 @@ where
|
||||||
if let Err((error, slice)) = declaration {
|
if let Err((error, slice)) = declaration {
|
||||||
let location = error.location;
|
let location = error.location;
|
||||||
let error = ContextualParseError::UnsupportedFontFaceDescriptor(slice, error);
|
let error = ContextualParseError::UnsupportedFontFaceDescriptor(slice, error);
|
||||||
context.log_css_error(error_context, location, error)
|
context.log_css_error(location, error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,8 @@
|
||||||
use context::QuirksMode;
|
use context::QuirksMode;
|
||||||
use cssparser::{Delimiter, Parser};
|
use cssparser::{Delimiter, Parser};
|
||||||
use cssparser::{ParserInput, Token};
|
use cssparser::{ParserInput, Token};
|
||||||
use error_reporting::{ContextualParseError, ParseErrorReporter};
|
use error_reporting::ContextualParseError;
|
||||||
use parser::{ParserContext, ParserErrorContext};
|
use parser::ParserContext;
|
||||||
use super::{Device, MediaQuery, Qualifier};
|
use super::{Device, MediaQuery, Qualifier};
|
||||||
|
|
||||||
/// A type that encapsulates a media query list.
|
/// A type that encapsulates a media query list.
|
||||||
|
@ -30,14 +30,10 @@ impl MediaList {
|
||||||
/// "not all", see:
|
/// "not all", see:
|
||||||
///
|
///
|
||||||
/// <https://drafts.csswg.org/mediaqueries/#error-handling>
|
/// <https://drafts.csswg.org/mediaqueries/#error-handling>
|
||||||
pub fn parse<R>(
|
pub fn parse(
|
||||||
context: &ParserContext,
|
context: &ParserContext,
|
||||||
input: &mut Parser,
|
input: &mut Parser,
|
||||||
error_reporter: &R,
|
) -> Self {
|
||||||
) -> MediaList
|
|
||||||
where
|
|
||||||
R: ParseErrorReporter,
|
|
||||||
{
|
|
||||||
if input.is_exhausted() {
|
if input.is_exhausted() {
|
||||||
return Self::empty();
|
return Self::empty();
|
||||||
}
|
}
|
||||||
|
@ -54,8 +50,7 @@ impl MediaList {
|
||||||
let location = err.location;
|
let location = err.location;
|
||||||
let error =
|
let error =
|
||||||
ContextualParseError::InvalidMediaRule(input.slice_from(start_position), err);
|
ContextualParseError::InvalidMediaRule(input.slice_from(start_position), err);
|
||||||
let error_context = ParserErrorContext { error_reporter };
|
context.log_css_error(location, error);
|
||||||
context.log_css_error(&error_context, location, error);
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,12 +36,6 @@ pub fn assert_parsing_mode_match() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The context required to report a parse error.
|
|
||||||
pub struct ParserErrorContext<'a, R: 'a> {
|
|
||||||
/// An error reporter to report syntax errors.
|
|
||||||
pub error_reporter: &'a R,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The data that the parser needs from outside in order to parse a stylesheet.
|
/// The data that the parser needs from outside in order to parse a stylesheet.
|
||||||
pub struct ParserContext<'a> {
|
pub struct ParserContext<'a> {
|
||||||
/// The `Origin` of the stylesheet, whether it's a user, author or
|
/// The `Origin` of the stylesheet, whether it's a user, author or
|
||||||
|
@ -55,6 +49,8 @@ pub struct ParserContext<'a> {
|
||||||
pub parsing_mode: ParsingMode,
|
pub parsing_mode: ParsingMode,
|
||||||
/// The quirks mode of this stylesheet.
|
/// The quirks mode of this stylesheet.
|
||||||
pub quirks_mode: QuirksMode,
|
pub quirks_mode: QuirksMode,
|
||||||
|
/// The active error reporter, or none if error reporting is disabled.
|
||||||
|
error_reporter: Option<&'a ParseErrorReporter>,
|
||||||
/// The currently active namespaces.
|
/// The currently active namespaces.
|
||||||
pub namespaces: Option<&'a Namespaces>,
|
pub namespaces: Option<&'a Namespaces>,
|
||||||
}
|
}
|
||||||
|
@ -68,6 +64,7 @@ impl<'a> ParserContext<'a> {
|
||||||
rule_type: Option<CssRuleType>,
|
rule_type: Option<CssRuleType>,
|
||||||
parsing_mode: ParsingMode,
|
parsing_mode: ParsingMode,
|
||||||
quirks_mode: QuirksMode,
|
quirks_mode: QuirksMode,
|
||||||
|
error_reporter: Option<&'a ParseErrorReporter>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
ParserContext {
|
ParserContext {
|
||||||
stylesheet_origin,
|
stylesheet_origin,
|
||||||
|
@ -75,6 +72,7 @@ impl<'a> ParserContext<'a> {
|
||||||
rule_type,
|
rule_type,
|
||||||
parsing_mode,
|
parsing_mode,
|
||||||
quirks_mode,
|
quirks_mode,
|
||||||
|
error_reporter,
|
||||||
namespaces: None,
|
namespaces: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,6 +84,7 @@ impl<'a> ParserContext<'a> {
|
||||||
rule_type: Option<CssRuleType>,
|
rule_type: Option<CssRuleType>,
|
||||||
parsing_mode: ParsingMode,
|
parsing_mode: ParsingMode,
|
||||||
quirks_mode: QuirksMode,
|
quirks_mode: QuirksMode,
|
||||||
|
error_reporter: Option<&'a ParseErrorReporter>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self::new(
|
Self::new(
|
||||||
Origin::Author,
|
Origin::Author,
|
||||||
|
@ -93,6 +92,7 @@ impl<'a> ParserContext<'a> {
|
||||||
rule_type,
|
rule_type,
|
||||||
parsing_mode,
|
parsing_mode,
|
||||||
quirks_mode,
|
quirks_mode,
|
||||||
|
error_reporter,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,6 +110,7 @@ impl<'a> ParserContext<'a> {
|
||||||
parsing_mode: context.parsing_mode,
|
parsing_mode: context.parsing_mode,
|
||||||
quirks_mode: context.quirks_mode,
|
quirks_mode: context.quirks_mode,
|
||||||
namespaces: Some(namespaces),
|
namespaces: Some(namespaces),
|
||||||
|
error_reporter: context.error_reporter,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,21 +128,17 @@ impl<'a> ParserContext<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Record a CSS parse error with this context’s error reporting.
|
/// Record a CSS parse error with this context’s error reporting.
|
||||||
pub fn log_css_error<R>(
|
pub fn log_css_error(
|
||||||
&self,
|
&self,
|
||||||
context: &ParserErrorContext<R>,
|
|
||||||
location: SourceLocation,
|
location: SourceLocation,
|
||||||
error: ContextualParseError,
|
error: ContextualParseError,
|
||||||
) where
|
) {
|
||||||
R: ParseErrorReporter,
|
let error_reporter = match self.error_reporter {
|
||||||
{
|
Some(r) => r,
|
||||||
let location = SourceLocation {
|
None => return,
|
||||||
line: location.line,
|
|
||||||
column: location.column,
|
|
||||||
};
|
};
|
||||||
context
|
|
||||||
.error_reporter
|
error_reporter.report_error(self.url_data, location, error)
|
||||||
.report_error(self.url_data, location, error)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether chrome-only rules should be parsed.
|
/// Returns whether chrome-only rules should be parsed.
|
||||||
|
|
|
@ -11,7 +11,7 @@ use cssparser::{DeclarationListParser, parse_important, ParserInput, CowRcStr};
|
||||||
use cssparser::{Parser, AtRuleParser, DeclarationParser, Delimiter, ParseErrorKind};
|
use cssparser::{Parser, AtRuleParser, DeclarationParser, Delimiter, ParseErrorKind};
|
||||||
use custom_properties::CustomPropertiesBuilder;
|
use custom_properties::CustomPropertiesBuilder;
|
||||||
use error_reporting::{ParseErrorReporter, ContextualParseError};
|
use error_reporting::{ParseErrorReporter, ContextualParseError};
|
||||||
use parser::{ParserContext, ParserErrorContext};
|
use parser::ParserContext;
|
||||||
use properties::animated_properties::AnimationValue;
|
use properties::animated_properties::AnimationValue;
|
||||||
use shared_lock::Locked;
|
use shared_lock::Locked;
|
||||||
use smallbitvec::{self, SmallBitVec};
|
use smallbitvec::{self, SmallBitVec};
|
||||||
|
@ -1077,50 +1077,49 @@ where
|
||||||
|
|
||||||
/// A helper to parse the style attribute of an element, in order for this to be
|
/// A helper to parse the style attribute of an element, in order for this to be
|
||||||
/// shared between Servo and Gecko.
|
/// shared between Servo and Gecko.
|
||||||
pub fn parse_style_attribute<R>(
|
///
|
||||||
|
/// Inline because we call this cross-crate.
|
||||||
|
#[inline]
|
||||||
|
pub fn parse_style_attribute(
|
||||||
input: &str,
|
input: &str,
|
||||||
url_data: &UrlExtraData,
|
url_data: &UrlExtraData,
|
||||||
error_reporter: &R,
|
error_reporter: Option<&ParseErrorReporter>,
|
||||||
quirks_mode: QuirksMode,
|
quirks_mode: QuirksMode,
|
||||||
) -> PropertyDeclarationBlock
|
) -> PropertyDeclarationBlock {
|
||||||
where
|
|
||||||
R: ParseErrorReporter
|
|
||||||
{
|
|
||||||
let context = ParserContext::new(
|
let context = ParserContext::new(
|
||||||
Origin::Author,
|
Origin::Author,
|
||||||
url_data,
|
url_data,
|
||||||
Some(CssRuleType::Style),
|
Some(CssRuleType::Style),
|
||||||
ParsingMode::DEFAULT,
|
ParsingMode::DEFAULT,
|
||||||
quirks_mode,
|
quirks_mode,
|
||||||
|
error_reporter,
|
||||||
);
|
);
|
||||||
|
|
||||||
let error_context = ParserErrorContext { error_reporter: error_reporter };
|
|
||||||
let mut input = ParserInput::new(input);
|
let mut input = ParserInput::new(input);
|
||||||
parse_property_declaration_list(&context, &error_context, &mut Parser::new(&mut input))
|
parse_property_declaration_list(&context, &mut Parser::new(&mut input))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse a given property declaration. Can result in multiple
|
/// Parse a given property declaration. Can result in multiple
|
||||||
/// `PropertyDeclaration`s when expanding a shorthand, for example.
|
/// `PropertyDeclaration`s when expanding a shorthand, for example.
|
||||||
///
|
///
|
||||||
/// This does not attempt to parse !important at all.
|
/// This does not attempt to parse !important at all.
|
||||||
pub fn parse_one_declaration_into<R>(
|
#[inline]
|
||||||
|
pub fn parse_one_declaration_into(
|
||||||
declarations: &mut SourcePropertyDeclaration,
|
declarations: &mut SourcePropertyDeclaration,
|
||||||
id: PropertyId,
|
id: PropertyId,
|
||||||
input: &str,
|
input: &str,
|
||||||
url_data: &UrlExtraData,
|
url_data: &UrlExtraData,
|
||||||
error_reporter: &R,
|
error_reporter: Option<&ParseErrorReporter>,
|
||||||
parsing_mode: ParsingMode,
|
parsing_mode: ParsingMode,
|
||||||
quirks_mode: QuirksMode
|
quirks_mode: QuirksMode
|
||||||
) -> Result<(), ()>
|
) -> Result<(), ()> {
|
||||||
where
|
|
||||||
R: ParseErrorReporter
|
|
||||||
{
|
|
||||||
let context = ParserContext::new(
|
let context = ParserContext::new(
|
||||||
Origin::Author,
|
Origin::Author,
|
||||||
url_data,
|
url_data,
|
||||||
Some(CssRuleType::Style),
|
Some(CssRuleType::Style),
|
||||||
parsing_mode,
|
parsing_mode,
|
||||||
quirks_mode,
|
quirks_mode,
|
||||||
|
error_reporter,
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut input = ParserInput::new(input);
|
let mut input = ParserInput::new(input);
|
||||||
|
@ -1131,9 +1130,10 @@ where
|
||||||
}).map_err(|err| {
|
}).map_err(|err| {
|
||||||
let location = err.location;
|
let location = err.location;
|
||||||
let error = ContextualParseError::UnsupportedPropertyDeclaration(
|
let error = ContextualParseError::UnsupportedPropertyDeclaration(
|
||||||
parser.slice_from(start_position), err);
|
parser.slice_from(start_position),
|
||||||
let error_context = ParserErrorContext { error_reporter: error_reporter };
|
err,
|
||||||
context.log_css_error(&error_context, location, error);
|
);
|
||||||
|
context.log_css_error(location, error);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1193,14 +1193,10 @@ impl<'a, 'b, 'i> DeclarationParser<'i> for PropertyDeclarationParser<'a, 'b> {
|
||||||
|
|
||||||
/// Parse a list of property declarations and return a property declaration
|
/// Parse a list of property declarations and return a property declaration
|
||||||
/// block.
|
/// block.
|
||||||
pub fn parse_property_declaration_list<R>(
|
pub fn parse_property_declaration_list(
|
||||||
context: &ParserContext,
|
context: &ParserContext,
|
||||||
error_context: &ParserErrorContext<R>,
|
|
||||||
input: &mut Parser,
|
input: &mut Parser,
|
||||||
) -> PropertyDeclarationBlock
|
) -> PropertyDeclarationBlock {
|
||||||
where
|
|
||||||
R: ParseErrorReporter
|
|
||||||
{
|
|
||||||
let mut declarations = SourcePropertyDeclaration::new();
|
let mut declarations = SourcePropertyDeclaration::new();
|
||||||
let mut block = PropertyDeclarationBlock::new();
|
let mut block = PropertyDeclarationBlock::new();
|
||||||
let parser = PropertyDeclarationParser {
|
let parser = PropertyDeclarationParser {
|
||||||
|
@ -1228,7 +1224,7 @@ where
|
||||||
|
|
||||||
let location = error.location;
|
let location = error.location;
|
||||||
let error = ContextualParseError::UnsupportedPropertyDeclaration(slice, error);
|
let error = ContextualParseError::UnsupportedPropertyDeclaration(slice, error);
|
||||||
context.log_css_error(error_context, location, error);
|
context.log_css_error(location, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1442,6 +1442,7 @@ impl UnparsedValue {
|
||||||
None,
|
None,
|
||||||
ParsingMode::DEFAULT,
|
ParsingMode::DEFAULT,
|
||||||
quirks_mode,
|
quirks_mode,
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut input = ParserInput::new(&css);
|
let mut input = ParserInput::new(&css);
|
||||||
|
|
|
@ -10,12 +10,12 @@ use Atom;
|
||||||
use cssparser::{AtRuleParser, AtRuleType, BasicParseErrorKind, CowRcStr};
|
use cssparser::{AtRuleParser, AtRuleType, BasicParseErrorKind, CowRcStr};
|
||||||
use cssparser::{DeclarationListParser, DeclarationParser, Parser};
|
use cssparser::{DeclarationListParser, DeclarationParser, Parser};
|
||||||
use cssparser::{QualifiedRuleParser, RuleListParser, SourceLocation, Token};
|
use cssparser::{QualifiedRuleParser, RuleListParser, SourceLocation, Token};
|
||||||
use error_reporting::{ContextualParseError, ParseErrorReporter};
|
use error_reporting::ContextualParseError;
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
use gecko_bindings::bindings::Gecko_AppendFeatureValueHashEntry;
|
use gecko_bindings::bindings::Gecko_AppendFeatureValueHashEntry;
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
use gecko_bindings::structs::{self, gfxFontFeatureValueSet, nsTArray};
|
use gecko_bindings::structs::{self, gfxFontFeatureValueSet, nsTArray};
|
||||||
use parser::{Parse, ParserContext, ParserErrorContext};
|
use parser::{Parse, ParserContext};
|
||||||
use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard};
|
use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard};
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
use str::CssStringWriter;
|
use str::CssStringWriter;
|
||||||
|
@ -267,27 +267,24 @@ macro_rules! font_feature_values_blocks {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parses a `FontFeatureValuesRule`.
|
/// Parses a `FontFeatureValuesRule`.
|
||||||
pub fn parse<R>(context: &ParserContext,
|
pub fn parse(
|
||||||
error_context: &ParserErrorContext<R>,
|
context: &ParserContext,
|
||||||
input: &mut Parser,
|
input: &mut Parser,
|
||||||
family_names: Vec<FamilyName>,
|
family_names: Vec<FamilyName>,
|
||||||
location: SourceLocation)
|
location: SourceLocation,
|
||||||
-> FontFeatureValuesRule
|
) -> Self {
|
||||||
where R: ParseErrorReporter
|
|
||||||
{
|
|
||||||
let mut rule = FontFeatureValuesRule::new(family_names, location);
|
let mut rule = FontFeatureValuesRule::new(family_names, location);
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut iter = RuleListParser::new_for_nested_rule(input, FontFeatureValuesRuleParser {
|
let mut iter = RuleListParser::new_for_nested_rule(input, FontFeatureValuesRuleParser {
|
||||||
context: context,
|
context: context,
|
||||||
error_context: error_context,
|
|
||||||
rule: &mut rule,
|
rule: &mut rule,
|
||||||
});
|
});
|
||||||
while let Some(result) = iter.next() {
|
while let Some(result) = iter.next() {
|
||||||
if let Err((error, slice)) = result {
|
if let Err((error, slice)) = result {
|
||||||
let location = error.location;
|
let location = error.location;
|
||||||
let error = ContextualParseError::UnsupportedRule(slice, error);
|
let error = ContextualParseError::UnsupportedRule(slice, error);
|
||||||
context.log_css_error(error_context, location, error);
|
context.log_css_error(location, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -398,20 +395,19 @@ macro_rules! font_feature_values_blocks {
|
||||||
/// }
|
/// }
|
||||||
/// <feature-type> = @stylistic | @historical-forms | @styleset |
|
/// <feature-type> = @stylistic | @historical-forms | @styleset |
|
||||||
/// @character-variant | @swash | @ornaments | @annotation
|
/// @character-variant | @swash | @ornaments | @annotation
|
||||||
struct FontFeatureValuesRuleParser<'a, R: 'a> {
|
struct FontFeatureValuesRuleParser<'a> {
|
||||||
context: &'a ParserContext<'a>,
|
context: &'a ParserContext<'a>,
|
||||||
error_context: &'a ParserErrorContext<'a, R>,
|
|
||||||
rule: &'a mut FontFeatureValuesRule,
|
rule: &'a mut FontFeatureValuesRule,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Default methods reject all qualified rules.
|
/// Default methods reject all qualified rules.
|
||||||
impl<'a, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for FontFeatureValuesRuleParser<'a, R> {
|
impl<'a, 'i> QualifiedRuleParser<'i> for FontFeatureValuesRuleParser<'a> {
|
||||||
type Prelude = ();
|
type Prelude = ();
|
||||||
type QualifiedRule = ();
|
type QualifiedRule = ();
|
||||||
type Error = StyleParseErrorKind<'i>;
|
type Error = StyleParseErrorKind<'i>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'i, R: ParseErrorReporter> AtRuleParser<'i> for FontFeatureValuesRuleParser<'a, R> {
|
impl<'a, 'i> AtRuleParser<'i> for FontFeatureValuesRuleParser<'a> {
|
||||||
type PreludeNoBlock = ();
|
type PreludeNoBlock = ();
|
||||||
type PreludeBlock = BlockType;
|
type PreludeBlock = BlockType;
|
||||||
type AtRule = ();
|
type AtRule = ();
|
||||||
|
@ -450,7 +446,7 @@ macro_rules! font_feature_values_blocks {
|
||||||
let error = ContextualParseError::UnsupportedKeyframePropertyDeclaration(
|
let error = ContextualParseError::UnsupportedKeyframePropertyDeclaration(
|
||||||
slice, error
|
slice, error
|
||||||
);
|
);
|
||||||
self.context.log_css_error(self.error_context, location, error);
|
self.context.log_css_error(location, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
|
|
||||||
use cssparser::{AtRuleParser, CowRcStr, Parser, ParserInput, QualifiedRuleParser, RuleListParser};
|
use cssparser::{AtRuleParser, CowRcStr, Parser, ParserInput, QualifiedRuleParser, RuleListParser};
|
||||||
use cssparser::{parse_one_rule, DeclarationListParser, DeclarationParser, SourceLocation, Token};
|
use cssparser::{parse_one_rule, DeclarationListParser, DeclarationParser, SourceLocation, Token};
|
||||||
use error_reporting::{ContextualParseError, NullReporter, ParseErrorReporter};
|
use error_reporting::ContextualParseError;
|
||||||
use parser::{ParserContext, ParserErrorContext};
|
use parser::ParserContext;
|
||||||
use properties::{DeclarationSource, Importance, PropertyDeclaration};
|
use properties::{DeclarationSource, Importance, PropertyDeclaration};
|
||||||
use properties::{LonghandId, PropertyDeclarationBlock, PropertyId};
|
use properties::{LonghandId, PropertyDeclarationBlock, PropertyId};
|
||||||
use properties::{PropertyDeclarationId, SourcePropertyDeclaration};
|
use properties::{PropertyDeclarationId, SourcePropertyDeclaration};
|
||||||
|
@ -211,7 +211,6 @@ impl Keyframe {
|
||||||
lock: &SharedRwLock,
|
lock: &SharedRwLock,
|
||||||
) -> Result<Arc<Locked<Self>>, ParseError<'i>> {
|
) -> Result<Arc<Locked<Self>>, ParseError<'i>> {
|
||||||
let url_data = parent_stylesheet_contents.url_data.read();
|
let url_data = parent_stylesheet_contents.url_data.read();
|
||||||
let error_reporter = NullReporter;
|
|
||||||
let namespaces = parent_stylesheet_contents.namespaces.read();
|
let namespaces = parent_stylesheet_contents.namespaces.read();
|
||||||
let mut context = ParserContext::new(
|
let mut context = ParserContext::new(
|
||||||
parent_stylesheet_contents.origin,
|
parent_stylesheet_contents.origin,
|
||||||
|
@ -219,10 +218,8 @@ impl Keyframe {
|
||||||
Some(CssRuleType::Keyframe),
|
Some(CssRuleType::Keyframe),
|
||||||
ParsingMode::DEFAULT,
|
ParsingMode::DEFAULT,
|
||||||
parent_stylesheet_contents.quirks_mode,
|
parent_stylesheet_contents.quirks_mode,
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
let error_context = ParserErrorContext {
|
|
||||||
error_reporter: &error_reporter,
|
|
||||||
};
|
|
||||||
context.namespaces = Some(&*namespaces);
|
context.namespaces = Some(&*namespaces);
|
||||||
let mut input = ParserInput::new(css);
|
let mut input = ParserInput::new(css);
|
||||||
let mut input = Parser::new(&mut input);
|
let mut input = Parser::new(&mut input);
|
||||||
|
@ -230,7 +227,6 @@ impl Keyframe {
|
||||||
let mut declarations = SourcePropertyDeclaration::new();
|
let mut declarations = SourcePropertyDeclaration::new();
|
||||||
let mut rule_parser = KeyframeListParser {
|
let mut rule_parser = KeyframeListParser {
|
||||||
context: &context,
|
context: &context,
|
||||||
error_context: &error_context,
|
|
||||||
shared_lock: &lock,
|
shared_lock: &lock,
|
||||||
declarations: &mut declarations,
|
declarations: &mut declarations,
|
||||||
};
|
};
|
||||||
|
@ -477,23 +473,18 @@ impl KeyframesAnimation {
|
||||||
/// 40%, 60%, 100% {
|
/// 40%, 60%, 100% {
|
||||||
/// width: 100%;
|
/// width: 100%;
|
||||||
/// }
|
/// }
|
||||||
struct KeyframeListParser<'a, R: 'a> {
|
struct KeyframeListParser<'a> {
|
||||||
context: &'a ParserContext<'a>,
|
context: &'a ParserContext<'a>,
|
||||||
error_context: &'a ParserErrorContext<'a, R>,
|
|
||||||
shared_lock: &'a SharedRwLock,
|
shared_lock: &'a SharedRwLock,
|
||||||
declarations: &'a mut SourcePropertyDeclaration,
|
declarations: &'a mut SourcePropertyDeclaration,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parses a keyframe list from CSS input.
|
/// Parses a keyframe list from CSS input.
|
||||||
pub fn parse_keyframe_list<R>(
|
pub fn parse_keyframe_list(
|
||||||
context: &ParserContext,
|
context: &ParserContext,
|
||||||
error_context: &ParserErrorContext<R>,
|
|
||||||
input: &mut Parser,
|
input: &mut Parser,
|
||||||
shared_lock: &SharedRwLock,
|
shared_lock: &SharedRwLock,
|
||||||
) -> Vec<Arc<Locked<Keyframe>>>
|
) -> Vec<Arc<Locked<Keyframe>>> {
|
||||||
where
|
|
||||||
R: ParseErrorReporter,
|
|
||||||
{
|
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
context.namespaces.is_some(),
|
context.namespaces.is_some(),
|
||||||
"Parsing a keyframe list from a context without namespaces?"
|
"Parsing a keyframe list from a context without namespaces?"
|
||||||
|
@ -504,7 +495,6 @@ where
|
||||||
input,
|
input,
|
||||||
KeyframeListParser {
|
KeyframeListParser {
|
||||||
context: context,
|
context: context,
|
||||||
error_context: error_context,
|
|
||||||
shared_lock: shared_lock,
|
shared_lock: shared_lock,
|
||||||
declarations: &mut declarations,
|
declarations: &mut declarations,
|
||||||
},
|
},
|
||||||
|
@ -512,7 +502,7 @@ where
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'i, R> AtRuleParser<'i> for KeyframeListParser<'a, R> {
|
impl<'a, 'i> AtRuleParser<'i> for KeyframeListParser<'a> {
|
||||||
type PreludeNoBlock = ();
|
type PreludeNoBlock = ();
|
||||||
type PreludeBlock = ();
|
type PreludeBlock = ();
|
||||||
type AtRule = Arc<Locked<Keyframe>>;
|
type AtRule = Arc<Locked<Keyframe>>;
|
||||||
|
@ -525,7 +515,7 @@ struct KeyframeSelectorParserPrelude {
|
||||||
source_location: SourceLocation,
|
source_location: SourceLocation,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for KeyframeListParser<'a, R> {
|
impl<'a, 'i> QualifiedRuleParser<'i> for KeyframeListParser<'a> {
|
||||||
type Prelude = KeyframeSelectorParserPrelude;
|
type Prelude = KeyframeSelectorParserPrelude;
|
||||||
type QualifiedRule = Arc<Locked<Keyframe>>;
|
type QualifiedRule = Arc<Locked<Keyframe>>;
|
||||||
type Error = StyleParseErrorKind<'i>;
|
type Error = StyleParseErrorKind<'i>;
|
||||||
|
@ -547,8 +537,7 @@ impl<'a, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for KeyframeListPars
|
||||||
input.slice_from(start_position),
|
input.slice_from(start_position),
|
||||||
e.clone(),
|
e.clone(),
|
||||||
);
|
);
|
||||||
self.context
|
self.context.log_css_error(location, error);
|
||||||
.log_css_error(self.error_context, location, error);
|
|
||||||
Err(e)
|
Err(e)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -585,7 +574,7 @@ impl<'a, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for KeyframeListPars
|
||||||
let location = error.location;
|
let location = error.location;
|
||||||
let error =
|
let error =
|
||||||
ContextualParseError::UnsupportedKeyframePropertyDeclaration(slice, error);
|
ContextualParseError::UnsupportedKeyframePropertyDeclaration(slice, error);
|
||||||
context.log_css_error(self.error_context, location, error);
|
context.log_css_error(location, error);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
// `parse_important` is not called here, `!important` is not allowed in keyframe blocks.
|
// `parse_important` is not called here, `!important` is not allowed in keyframe blocks.
|
||||||
|
|
|
@ -24,10 +24,9 @@ pub mod supports_rule;
|
||||||
pub mod viewport_rule;
|
pub mod viewport_rule;
|
||||||
|
|
||||||
use cssparser::{parse_one_rule, Parser, ParserInput};
|
use cssparser::{parse_one_rule, Parser, ParserInput};
|
||||||
use error_reporting::NullReporter;
|
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
use malloc_size_of::{MallocSizeOfOps, MallocUnconditionalShallowSizeOf};
|
use malloc_size_of::{MallocSizeOfOps, MallocUnconditionalShallowSizeOf};
|
||||||
use parser::{ParserContext, ParserErrorContext};
|
use parser::ParserContext;
|
||||||
use servo_arc::Arc;
|
use servo_arc::Arc;
|
||||||
use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked};
|
use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked};
|
||||||
use shared_lock::{SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard};
|
use shared_lock::{SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard};
|
||||||
|
@ -228,13 +227,13 @@ impl CssRule {
|
||||||
loader: Option<&StylesheetLoader>,
|
loader: Option<&StylesheetLoader>,
|
||||||
) -> Result<Self, RulesMutateError> {
|
) -> Result<Self, RulesMutateError> {
|
||||||
let url_data = parent_stylesheet_contents.url_data.read();
|
let url_data = parent_stylesheet_contents.url_data.read();
|
||||||
let error_reporter = NullReporter;
|
|
||||||
let context = ParserContext::new(
|
let context = ParserContext::new(
|
||||||
parent_stylesheet_contents.origin,
|
parent_stylesheet_contents.origin,
|
||||||
&url_data,
|
&url_data,
|
||||||
None,
|
None,
|
||||||
ParsingMode::DEFAULT,
|
ParsingMode::DEFAULT,
|
||||||
parent_stylesheet_contents.quirks_mode,
|
parent_stylesheet_contents.quirks_mode,
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut input = ParserInput::new(css);
|
let mut input = ParserInput::new(css);
|
||||||
|
@ -246,9 +245,6 @@ impl CssRule {
|
||||||
let mut rule_parser = TopLevelRuleParser {
|
let mut rule_parser = TopLevelRuleParser {
|
||||||
stylesheet_origin: parent_stylesheet_contents.origin,
|
stylesheet_origin: parent_stylesheet_contents.origin,
|
||||||
context,
|
context,
|
||||||
error_context: ParserErrorContext {
|
|
||||||
error_reporter: &error_reporter,
|
|
||||||
},
|
|
||||||
shared_lock: &shared_lock,
|
shared_lock: &shared_lock,
|
||||||
loader,
|
loader,
|
||||||
state,
|
state,
|
||||||
|
|
|
@ -8,10 +8,10 @@ use {Namespace, Prefix};
|
||||||
use counter_style::{parse_counter_style_body, parse_counter_style_name_definition};
|
use counter_style::{parse_counter_style_body, parse_counter_style_name_definition};
|
||||||
use cssparser::{AtRuleParser, AtRuleType, Parser, QualifiedRuleParser, RuleListParser};
|
use cssparser::{AtRuleParser, AtRuleType, Parser, QualifiedRuleParser, RuleListParser};
|
||||||
use cssparser::{BasicParseError, BasicParseErrorKind, CowRcStr, SourceLocation};
|
use cssparser::{BasicParseError, BasicParseErrorKind, CowRcStr, SourceLocation};
|
||||||
use error_reporting::{ContextualParseError, ParseErrorReporter};
|
use error_reporting::ContextualParseError;
|
||||||
use font_face::parse_font_face_block;
|
use font_face::parse_font_face_block;
|
||||||
use media_queries::MediaList;
|
use media_queries::MediaList;
|
||||||
use parser::{Parse, ParserContext, ParserErrorContext};
|
use parser::{Parse, ParserContext};
|
||||||
use properties::parse_property_declaration_list;
|
use properties::parse_property_declaration_list;
|
||||||
use selector_parser::{SelectorImpl, SelectorParser};
|
use selector_parser::{SelectorImpl, SelectorParser};
|
||||||
use selectors::SelectorList;
|
use selectors::SelectorList;
|
||||||
|
@ -40,7 +40,7 @@ pub struct InsertRuleContext<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The parser for the top-level rules in a stylesheet.
|
/// The parser for the top-level rules in a stylesheet.
|
||||||
pub struct TopLevelRuleParser<'a, R: 'a> {
|
pub struct TopLevelRuleParser<'a> {
|
||||||
/// The origin of the stylesheet we're parsing.
|
/// The origin of the stylesheet we're parsing.
|
||||||
pub stylesheet_origin: Origin,
|
pub stylesheet_origin: Origin,
|
||||||
/// A reference to the lock we need to use to create rules.
|
/// A reference to the lock we need to use to create rules.
|
||||||
|
@ -52,8 +52,6 @@ pub struct TopLevelRuleParser<'a, R: 'a> {
|
||||||
/// This won't contain any namespaces, and only nested parsers created with
|
/// This won't contain any namespaces, and only nested parsers created with
|
||||||
/// `ParserContext::new_with_rule_type` will.
|
/// `ParserContext::new_with_rule_type` will.
|
||||||
pub context: ParserContext<'a>,
|
pub context: ParserContext<'a>,
|
||||||
/// The context required for reporting parse errors.
|
|
||||||
pub error_context: ParserErrorContext<'a, R>,
|
|
||||||
/// The current state of the parser.
|
/// The current state of the parser.
|
||||||
pub state: State,
|
pub state: State,
|
||||||
/// Whether we have tried to parse was invalid due to being in the wrong
|
/// Whether we have tried to parse was invalid due to being in the wrong
|
||||||
|
@ -68,13 +66,12 @@ pub struct TopLevelRuleParser<'a, R: 'a> {
|
||||||
pub insert_rule_context: Option<InsertRuleContext<'a>>,
|
pub insert_rule_context: Option<InsertRuleContext<'a>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'b, R> TopLevelRuleParser<'b, R> {
|
impl<'b> TopLevelRuleParser<'b> {
|
||||||
fn nested<'a: 'b>(&'a self) -> NestedRuleParser<'a, 'b, R> {
|
fn nested<'a: 'b>(&'a self) -> NestedRuleParser<'a, 'b> {
|
||||||
NestedRuleParser {
|
NestedRuleParser {
|
||||||
stylesheet_origin: self.stylesheet_origin,
|
stylesheet_origin: self.stylesheet_origin,
|
||||||
shared_lock: self.shared_lock,
|
shared_lock: self.shared_lock,
|
||||||
context: &self.context,
|
context: &self.context,
|
||||||
error_context: &self.error_context,
|
|
||||||
namespaces: &self.namespaces,
|
namespaces: &self.namespaces,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -176,7 +173,7 @@ pub enum AtRuleNonBlockPrelude {
|
||||||
Namespace(Option<Prefix>, Namespace, SourceLocation),
|
Namespace(Option<Prefix>, Namespace, SourceLocation),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'i, R: ParseErrorReporter> AtRuleParser<'i> for TopLevelRuleParser<'a, R> {
|
impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> {
|
||||||
type PreludeNoBlock = AtRuleNonBlockPrelude;
|
type PreludeNoBlock = AtRuleNonBlockPrelude;
|
||||||
type PreludeBlock = AtRuleBlockPrelude;
|
type PreludeBlock = AtRuleBlockPrelude;
|
||||||
type AtRule = CssRule;
|
type AtRule = CssRule;
|
||||||
|
@ -197,11 +194,7 @@ impl<'a, 'i, R: ParseErrorReporter> AtRuleParser<'i> for TopLevelRuleParser<'a,
|
||||||
let url_string = input.expect_url_or_string()?.as_ref().to_owned();
|
let url_string = input.expect_url_or_string()?.as_ref().to_owned();
|
||||||
let url = CssUrl::parse_from_string(url_string, &self.context);
|
let url = CssUrl::parse_from_string(url_string, &self.context);
|
||||||
|
|
||||||
let media = MediaList::parse(
|
let media = MediaList::parse(&self.context, input);
|
||||||
&self.context,
|
|
||||||
input,
|
|
||||||
self.error_context.error_reporter,
|
|
||||||
);
|
|
||||||
let media = Arc::new(self.shared_lock.wrap(media));
|
let media = Arc::new(self.shared_lock.wrap(media));
|
||||||
|
|
||||||
let prelude = AtRuleNonBlockPrelude::Import(url, media, location);
|
let prelude = AtRuleNonBlockPrelude::Import(url, media, location);
|
||||||
|
@ -296,7 +289,7 @@ pub struct QualifiedRuleParserPrelude {
|
||||||
source_location: SourceLocation,
|
source_location: SourceLocation,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for TopLevelRuleParser<'a, R> {
|
impl<'a, 'i> QualifiedRuleParser<'i> for TopLevelRuleParser<'a> {
|
||||||
type Prelude = QualifiedRuleParserPrelude;
|
type Prelude = QualifiedRuleParserPrelude;
|
||||||
type QualifiedRule = CssRule;
|
type QualifiedRule = CssRule;
|
||||||
type Error = StyleParseErrorKind<'i>;
|
type Error = StyleParseErrorKind<'i>;
|
||||||
|
@ -327,27 +320,29 @@ impl<'a, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for TopLevelRulePars
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)] // shallow, relatively cheap .clone
|
#[derive(Clone)] // shallow, relatively cheap .clone
|
||||||
struct NestedRuleParser<'a, 'b: 'a, R: 'b> {
|
struct NestedRuleParser<'a, 'b: 'a> {
|
||||||
stylesheet_origin: Origin,
|
stylesheet_origin: Origin,
|
||||||
shared_lock: &'a SharedRwLock,
|
shared_lock: &'a SharedRwLock,
|
||||||
context: &'a ParserContext<'b>,
|
context: &'a ParserContext<'b>,
|
||||||
error_context: &'a ParserErrorContext<'b, R>,
|
|
||||||
namespaces: &'a Namespaces,
|
namespaces: &'a Namespaces,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b, R: ParseErrorReporter> NestedRuleParser<'a, 'b, R> {
|
impl<'a, 'b> NestedRuleParser<'a, 'b> {
|
||||||
fn parse_nested_rules(
|
fn parse_nested_rules(
|
||||||
&mut self,
|
&mut self,
|
||||||
input: &mut Parser,
|
input: &mut Parser,
|
||||||
rule_type: CssRuleType,
|
rule_type: CssRuleType,
|
||||||
) -> Arc<Locked<CssRules>> {
|
) -> Arc<Locked<CssRules>> {
|
||||||
let context = ParserContext::new_with_rule_type(self.context, rule_type, self.namespaces);
|
let context = ParserContext::new_with_rule_type(
|
||||||
|
self.context,
|
||||||
|
rule_type,
|
||||||
|
self.namespaces,
|
||||||
|
);
|
||||||
|
|
||||||
let nested_parser = NestedRuleParser {
|
let nested_parser = NestedRuleParser {
|
||||||
stylesheet_origin: self.stylesheet_origin,
|
stylesheet_origin: self.stylesheet_origin,
|
||||||
shared_lock: self.shared_lock,
|
shared_lock: self.shared_lock,
|
||||||
context: &context,
|
context: &context,
|
||||||
error_context: &self.error_context,
|
|
||||||
namespaces: self.namespaces,
|
namespaces: self.namespaces,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -359,8 +354,7 @@ impl<'a, 'b, R: ParseErrorReporter> NestedRuleParser<'a, 'b, R> {
|
||||||
Err((error, slice)) => {
|
Err((error, slice)) => {
|
||||||
let location = error.location;
|
let location = error.location;
|
||||||
let error = ContextualParseError::InvalidRule(slice, error);
|
let error = ContextualParseError::InvalidRule(slice, error);
|
||||||
self.context
|
self.context.log_css_error(location, error);
|
||||||
.log_css_error(self.error_context, location, error);
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -368,7 +362,7 @@ impl<'a, 'b, R: ParseErrorReporter> NestedRuleParser<'a, 'b, R> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a, 'b, R> {
|
impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
|
||||||
type PreludeNoBlock = AtRuleNonBlockPrelude;
|
type PreludeNoBlock = AtRuleNonBlockPrelude;
|
||||||
type PreludeBlock = AtRuleBlockPrelude;
|
type PreludeBlock = AtRuleBlockPrelude;
|
||||||
type AtRule = CssRule;
|
type AtRule = CssRule;
|
||||||
|
@ -383,11 +377,7 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a
|
||||||
|
|
||||||
match_ignore_ascii_case! { &*name,
|
match_ignore_ascii_case! { &*name,
|
||||||
"media" => {
|
"media" => {
|
||||||
let media_queries = MediaList::parse(
|
let media_queries = MediaList::parse(self.context, input);
|
||||||
self.context,
|
|
||||||
input,
|
|
||||||
self.error_context.error_reporter,
|
|
||||||
);
|
|
||||||
let arc = Arc::new(self.shared_lock.wrap(media_queries));
|
let arc = Arc::new(self.shared_lock.wrap(media_queries));
|
||||||
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::Media(arc, location)))
|
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::Media(arc, location)))
|
||||||
},
|
},
|
||||||
|
@ -473,7 +463,7 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(CssRule::FontFace(Arc::new(self.shared_lock.wrap(
|
Ok(CssRule::FontFace(Arc::new(self.shared_lock.wrap(
|
||||||
parse_font_face_block(&context, self.error_context, input, location).into(),
|
parse_font_face_block(&context, input, location).into(),
|
||||||
))))
|
))))
|
||||||
},
|
},
|
||||||
AtRuleBlockPrelude::FontFeatureValues(family_names, location) => {
|
AtRuleBlockPrelude::FontFeatureValues(family_names, location) => {
|
||||||
|
@ -486,7 +476,6 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a
|
||||||
Ok(CssRule::FontFeatureValues(Arc::new(self.shared_lock.wrap(
|
Ok(CssRule::FontFeatureValues(Arc::new(self.shared_lock.wrap(
|
||||||
FontFeatureValuesRule::parse(
|
FontFeatureValuesRule::parse(
|
||||||
&context,
|
&context,
|
||||||
self.error_context,
|
|
||||||
input,
|
input,
|
||||||
family_names,
|
family_names,
|
||||||
location,
|
location,
|
||||||
|
@ -505,7 +494,6 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a
|
||||||
parse_counter_style_body(
|
parse_counter_style_body(
|
||||||
name,
|
name,
|
||||||
&context,
|
&context,
|
||||||
self.error_context,
|
|
||||||
input,
|
input,
|
||||||
location,
|
location,
|
||||||
)?.into(),
|
)?.into(),
|
||||||
|
@ -544,7 +532,7 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(CssRule::Viewport(Arc::new(self.shared_lock.wrap(
|
Ok(CssRule::Viewport(Arc::new(self.shared_lock.wrap(
|
||||||
ViewportRule::parse(&context, self.error_context, input)?,
|
ViewportRule::parse(&context, input)?,
|
||||||
))))
|
))))
|
||||||
},
|
},
|
||||||
AtRuleBlockPrelude::Keyframes(name, vendor_prefix, source_location) => {
|
AtRuleBlockPrelude::Keyframes(name, vendor_prefix, source_location) => {
|
||||||
|
@ -559,7 +547,6 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a
|
||||||
name,
|
name,
|
||||||
keyframes: parse_keyframe_list(
|
keyframes: parse_keyframe_list(
|
||||||
&context,
|
&context,
|
||||||
self.error_context,
|
|
||||||
input,
|
input,
|
||||||
self.shared_lock,
|
self.shared_lock,
|
||||||
),
|
),
|
||||||
|
@ -576,7 +563,7 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a
|
||||||
);
|
);
|
||||||
|
|
||||||
let declarations =
|
let declarations =
|
||||||
parse_property_declaration_list(&context, self.error_context, input);
|
parse_property_declaration_list(&context, input);
|
||||||
Ok(CssRule::Page(Arc::new(self.shared_lock.wrap(PageRule {
|
Ok(CssRule::Page(Arc::new(self.shared_lock.wrap(PageRule {
|
||||||
block: Arc::new(self.shared_lock.wrap(declarations)),
|
block: Arc::new(self.shared_lock.wrap(declarations)),
|
||||||
source_location,
|
source_location,
|
||||||
|
@ -598,7 +585,7 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for NestedRuleParser<'a, 'b, R> {
|
impl<'a, 'b, 'i> QualifiedRuleParser<'i> for NestedRuleParser<'a, 'b> {
|
||||||
type Prelude = QualifiedRuleParserPrelude;
|
type Prelude = QualifiedRuleParserPrelude;
|
||||||
type QualifiedRule = CssRule;
|
type QualifiedRule = CssRule;
|
||||||
type Error = StyleParseErrorKind<'i>;
|
type Error = StyleParseErrorKind<'i>;
|
||||||
|
@ -627,7 +614,7 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for NestedRulePa
|
||||||
let context =
|
let context =
|
||||||
ParserContext::new_with_rule_type(self.context, CssRuleType::Style, self.namespaces);
|
ParserContext::new_with_rule_type(self.context, CssRuleType::Style, self.namespaces);
|
||||||
|
|
||||||
let declarations = parse_property_declaration_list(&context, self.error_context, input);
|
let declarations = parse_property_declaration_list(&context, input);
|
||||||
Ok(CssRule::Style(Arc::new(self.shared_lock.wrap(StyleRule {
|
Ok(CssRule::Style(Arc::new(self.shared_lock.wrap(StyleRule {
|
||||||
selectors: prelude.selectors,
|
selectors: prelude.selectors,
|
||||||
block: Arc::new(self.shared_lock.wrap(declarations)),
|
block: Arc::new(self.shared_lock.wrap(declarations)),
|
||||||
|
|
|
@ -13,7 +13,7 @@ use invalidation::media_queries::{MediaListKey, ToMediaListKey};
|
||||||
use malloc_size_of::{MallocSizeOfOps, MallocUnconditionalShallowSizeOf};
|
use malloc_size_of::{MallocSizeOfOps, MallocUnconditionalShallowSizeOf};
|
||||||
use media_queries::{Device, MediaList};
|
use media_queries::{Device, MediaList};
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use parser::{ParserContext, ParserErrorContext};
|
use parser::ParserContext;
|
||||||
use servo_arc::Arc;
|
use servo_arc::Arc;
|
||||||
use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked, SharedRwLock, SharedRwLockReadGuard};
|
use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked, SharedRwLock, SharedRwLockReadGuard};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
@ -69,13 +69,13 @@ pub struct StylesheetContents {
|
||||||
impl StylesheetContents {
|
impl StylesheetContents {
|
||||||
/// Parse a given CSS string, with a given url-data, origin, and
|
/// Parse a given CSS string, with a given url-data, origin, and
|
||||||
/// quirks mode.
|
/// quirks mode.
|
||||||
pub fn from_str<R: ParseErrorReporter>(
|
pub fn from_str(
|
||||||
css: &str,
|
css: &str,
|
||||||
url_data: UrlExtraData,
|
url_data: UrlExtraData,
|
||||||
origin: Origin,
|
origin: Origin,
|
||||||
shared_lock: &SharedRwLock,
|
shared_lock: &SharedRwLock,
|
||||||
stylesheet_loader: Option<&StylesheetLoader>,
|
stylesheet_loader: Option<&StylesheetLoader>,
|
||||||
error_reporter: &R,
|
error_reporter: Option<&ParseErrorReporter>,
|
||||||
quirks_mode: QuirksMode,
|
quirks_mode: QuirksMode,
|
||||||
line_number_offset: u32,
|
line_number_offset: u32,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
@ -306,18 +306,16 @@ impl StylesheetInDocument for DocumentStyleSheet {
|
||||||
|
|
||||||
impl Stylesheet {
|
impl Stylesheet {
|
||||||
/// Updates an empty stylesheet from a given string of text.
|
/// Updates an empty stylesheet from a given string of text.
|
||||||
pub fn update_from_str<R>(
|
pub fn update_from_str(
|
||||||
existing: &Stylesheet,
|
existing: &Stylesheet,
|
||||||
css: &str,
|
css: &str,
|
||||||
url_data: UrlExtraData,
|
url_data: UrlExtraData,
|
||||||
stylesheet_loader: Option<&StylesheetLoader>,
|
stylesheet_loader: Option<&StylesheetLoader>,
|
||||||
error_reporter: &R,
|
error_reporter: Option<&ParseErrorReporter>,
|
||||||
line_number_offset: u32,
|
line_number_offset: u32,
|
||||||
) where
|
) {
|
||||||
R: ParseErrorReporter,
|
|
||||||
{
|
|
||||||
let namespaces = RwLock::new(Namespaces::default());
|
let namespaces = RwLock::new(Namespaces::default());
|
||||||
let (rules, source_map_url, source_url) = Stylesheet::parse_rules(
|
let (rules, source_map_url, source_url) = Self::parse_rules(
|
||||||
css,
|
css,
|
||||||
&url_data,
|
&url_data,
|
||||||
existing.contents.origin,
|
existing.contents.origin,
|
||||||
|
@ -342,14 +340,14 @@ impl Stylesheet {
|
||||||
*existing.contents.source_url.write() = source_url;
|
*existing.contents.source_url.write() = source_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_rules<R: ParseErrorReporter>(
|
fn parse_rules(
|
||||||
css: &str,
|
css: &str,
|
||||||
url_data: &UrlExtraData,
|
url_data: &UrlExtraData,
|
||||||
origin: Origin,
|
origin: Origin,
|
||||||
namespaces: &mut Namespaces,
|
namespaces: &mut Namespaces,
|
||||||
shared_lock: &SharedRwLock,
|
shared_lock: &SharedRwLock,
|
||||||
stylesheet_loader: Option<&StylesheetLoader>,
|
stylesheet_loader: Option<&StylesheetLoader>,
|
||||||
error_reporter: &R,
|
error_reporter: Option<&ParseErrorReporter>,
|
||||||
quirks_mode: QuirksMode,
|
quirks_mode: QuirksMode,
|
||||||
line_number_offset: u32,
|
line_number_offset: u32,
|
||||||
) -> (Vec<CssRule>, Option<String>, Option<String>) {
|
) -> (Vec<CssRule>, Option<String>, Option<String>) {
|
||||||
|
@ -357,16 +355,20 @@ impl Stylesheet {
|
||||||
let mut input = ParserInput::new_with_line_number_offset(css, line_number_offset);
|
let mut input = ParserInput::new_with_line_number_offset(css, line_number_offset);
|
||||||
let mut input = Parser::new(&mut input);
|
let mut input = Parser::new(&mut input);
|
||||||
|
|
||||||
let context = ParserContext::new(origin, url_data, None, ParsingMode::DEFAULT, quirks_mode);
|
let context = ParserContext::new(
|
||||||
|
origin,
|
||||||
let error_context = ParserErrorContext { error_reporter };
|
url_data,
|
||||||
|
None,
|
||||||
|
ParsingMode::DEFAULT,
|
||||||
|
quirks_mode,
|
||||||
|
error_reporter,
|
||||||
|
);
|
||||||
|
|
||||||
let rule_parser = TopLevelRuleParser {
|
let rule_parser = TopLevelRuleParser {
|
||||||
stylesheet_origin: origin,
|
stylesheet_origin: origin,
|
||||||
shared_lock,
|
shared_lock,
|
||||||
loader: stylesheet_loader,
|
loader: stylesheet_loader,
|
||||||
context,
|
context,
|
||||||
error_context,
|
|
||||||
state: State::Start,
|
state: State::Start,
|
||||||
dom_error: None,
|
dom_error: None,
|
||||||
insert_rule_context: None,
|
insert_rule_context: None,
|
||||||
|
@ -390,7 +392,6 @@ impl Stylesheet {
|
||||||
let location = error.location;
|
let location = error.location;
|
||||||
let error = ContextualParseError::InvalidRule(slice, error);
|
let error = ContextualParseError::InvalidRule(slice, error);
|
||||||
iter.parser.context.log_css_error(
|
iter.parser.context.log_css_error(
|
||||||
&iter.parser.error_context,
|
|
||||||
location,
|
location,
|
||||||
error,
|
error,
|
||||||
);
|
);
|
||||||
|
@ -409,17 +410,17 @@ impl Stylesheet {
|
||||||
///
|
///
|
||||||
/// Effectively creates a new stylesheet and forwards the hard work to
|
/// Effectively creates a new stylesheet and forwards the hard work to
|
||||||
/// `Stylesheet::update_from_str`.
|
/// `Stylesheet::update_from_str`.
|
||||||
pub fn from_str<R: ParseErrorReporter>(
|
pub fn from_str(
|
||||||
css: &str,
|
css: &str,
|
||||||
url_data: UrlExtraData,
|
url_data: UrlExtraData,
|
||||||
origin: Origin,
|
origin: Origin,
|
||||||
media: Arc<Locked<MediaList>>,
|
media: Arc<Locked<MediaList>>,
|
||||||
shared_lock: SharedRwLock,
|
shared_lock: SharedRwLock,
|
||||||
stylesheet_loader: Option<&StylesheetLoader>,
|
stylesheet_loader: Option<&StylesheetLoader>,
|
||||||
error_reporter: &R,
|
error_reporter: Option<&ParseErrorReporter>,
|
||||||
quirks_mode: QuirksMode,
|
quirks_mode: QuirksMode,
|
||||||
line_number_offset: u32,
|
line_number_offset: u32,
|
||||||
) -> Stylesheet {
|
) -> Self {
|
||||||
let contents = StylesheetContents::from_str(
|
let contents = StylesheetContents::from_str(
|
||||||
css,
|
css,
|
||||||
url_data,
|
url_data,
|
||||||
|
|
|
@ -11,11 +11,11 @@ use app_units::Au;
|
||||||
use context::QuirksMode;
|
use context::QuirksMode;
|
||||||
use cssparser::{parse_important, AtRuleParser, DeclarationListParser, DeclarationParser, Parser};
|
use cssparser::{parse_important, AtRuleParser, DeclarationListParser, DeclarationParser, Parser};
|
||||||
use cssparser::CowRcStr;
|
use cssparser::CowRcStr;
|
||||||
use error_reporting::{ContextualParseError, ParseErrorReporter};
|
use error_reporting::ContextualParseError;
|
||||||
use euclid::TypedSize2D;
|
use euclid::TypedSize2D;
|
||||||
use font_metrics::get_metrics_provider_for_product;
|
use font_metrics::get_metrics_provider_for_product;
|
||||||
use media_queries::Device;
|
use media_queries::Device;
|
||||||
use parser::{ParserContext, ParserErrorContext};
|
use parser::ParserContext;
|
||||||
use properties::StyleBuilder;
|
use properties::StyleBuilder;
|
||||||
use rule_cache::RuleCacheConditions;
|
use rule_cache::RuleCacheConditions;
|
||||||
use selectors::parser::SelectorParseErrorKind;
|
use selectors::parser::SelectorParseErrorKind;
|
||||||
|
@ -355,15 +355,13 @@ fn is_whitespace_separator_or_equals(c: &char) -> bool {
|
||||||
|
|
||||||
impl ViewportRule {
|
impl ViewportRule {
|
||||||
/// Parse a single @viewport rule.
|
/// Parse a single @viewport rule.
|
||||||
pub fn parse<'i, 't, R>(
|
///
|
||||||
|
/// TODO(emilio): This could use the `Parse` trait now.
|
||||||
|
pub fn parse<'i, 't>(
|
||||||
context: &ParserContext,
|
context: &ParserContext,
|
||||||
error_context: &ParserErrorContext<R>,
|
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<Self, ParseError<'i>>
|
) -> Result<Self, ParseError<'i>> {
|
||||||
where
|
let parser = ViewportRuleParser { context };
|
||||||
R: ParseErrorReporter,
|
|
||||||
{
|
|
||||||
let parser = ViewportRuleParser { context: context };
|
|
||||||
|
|
||||||
let mut cascade = Cascade::new();
|
let mut cascade = Cascade::new();
|
||||||
let mut parser = DeclarationListParser::new(input, parser);
|
let mut parser = DeclarationListParser::new(input, parser);
|
||||||
|
@ -380,7 +378,7 @@ impl ViewportRule {
|
||||||
slice,
|
slice,
|
||||||
error,
|
error,
|
||||||
);
|
);
|
||||||
context.log_css_error(error_context, location, error);
|
context.log_css_error(location, error);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue