diff --git a/src/css-parsing-tests/one_rule.json b/src/css-parsing-tests/one_rule.json index b7be5fa0..677a67a0 100644 --- a/src/css-parsing-tests/one_rule.json +++ b/src/css-parsing-tests/one_rule.json @@ -7,13 +7,17 @@ "@foo", ["at-rule", "foo", [], null], "@foo bar; \t/* comment */", ["at-rule", "foo", [" ", ["ident", "bar"]], null], -" /**/ @foo bar{[(4", ["at-rule", "foo", +" /**/ @foo-with-block bar{[(4", ["at-rule", "foo-with-block", [" ", ["ident", "bar"]], [["[]", ["()", ["number", "4", 4, "integer"]]]] ], -"@foo { bar", ["at-rule", "foo", [" "], [" ", ["ident", "bar"]]], -"@foo [ bar", ["at-rule", "foo", [" ", ["[]", " ", ["ident", "bar"]]], null], +"@foo-with-block { bar", ["at-rule", "foo-with-block", [" "], [ + " ", ["ident", "bar"]] +], +"@foo [ bar", ["at-rule", "foo", + [" ", ["[]", " ", ["ident", "bar"]]], null +], " /**/ div > p { color: #aaa; } /**/ ", ["qualified rule", [["ident", "div"], " ", ">", " ", ["ident", "p"], " "], diff --git a/src/css-parsing-tests/rule_list.json b/src/css-parsing-tests/rule_list.json index 875978e6..7e50364c 100644 --- a/src/css-parsing-tests/rule_list.json +++ b/src/css-parsing-tests/rule_list.json @@ -7,18 +7,20 @@ "@foo", [["at-rule", "foo", [], null]], "@charset; @foo", [ - ["at-rule", "charset", [], null], + ["error", "invalid"], ["at-rule", "foo", [], null] ], "@foo bar; \t/* comment */", [["at-rule", "foo", [" ", ["ident", "bar"]], null]], -" /**/ @foo bar{[(4", [["at-rule", "foo", +" /**/ @foo-with-block bar{[(4", [["at-rule", "foo-with-block", [" ", ["ident", "bar"]], [["[]", ["()", ["number", "4", 4, "integer"]]]] ]], -"@foo { bar", [["at-rule", "foo", [" "], [" ", ["ident", "bar"]]]], +"@foo-with-block { bar", [["at-rule", "foo-with-block", [" "], [ + " ", ["ident", "bar"]]] +], "@foo [ bar", [["at-rule", "foo", [" ", ["[]", " ", ["ident", "bar"]]], null]], " /**/ div > p { color: #aaa; } /**/ ", [["qualified rule", diff --git a/src/css-parsing-tests/stylesheet.json b/src/css-parsing-tests/stylesheet.json index 574ad7ac..5624b27d 100644 --- a/src/css-parsing-tests/stylesheet.json +++ b/src/css-parsing-tests/stylesheet.json @@ -10,17 +10,19 @@ "@foo; @charset 4 {}", [ ["at-rule", "foo", [], null], - ["at-rule", "charset", [" ", ["number", "4", 4, "integer"], " "], []] + ["error", "invalid"] ], "@foo bar; \t/* comment */", [["at-rule", "foo", [" ", ["ident", "bar"]], null]], -" /**/ @foo bar{[(4", [["at-rule", "foo", +" /**/ @foo-with-block bar{[(4", [["at-rule", "foo-with-block", [" ", ["ident", "bar"]], [["[]", ["()", ["number", "4", 4, "integer"]]]] ]], -"@foo { bar", [["at-rule", "foo", [" "], [" ", ["ident", "bar"]]]], +"@foo-with-block { bar", [["at-rule", "foo-with-block", [" "], [ + " ", ["ident", "bar"]]] +], "@foo [ bar", [["at-rule", "foo", [" ", ["[]", " ", ["ident", "bar"]]], null]], " /**/ div > p { color: #aaa; } /**/ ", [["qualified rule", diff --git a/src/rules_and_declarations.rs b/src/rules_and_declarations.rs index 4e8ef438..1cd96164 100644 --- a/src/rules_and_declarations.rs +++ b/src/rules_and_declarations.rs @@ -23,24 +23,17 @@ pub fn parse_important<'i, 't>(input: &mut Parser<'i, 't>) -> Result<(), BasicPa /// The return value for `AtRuleParser::parse_prelude`. /// Indicates whether the at-rule is expected to have a `{ /* ... */ }` block /// or end with a `;` semicolon. -pub enum AtRuleType
{ +pub enum AtRuleType
{
/// The at-rule is expected to end with a `;` semicolon. Example: `@import`.
///
- /// The value is the finished representation of an at-rule
- /// as returned by `RuleListParser::next` or `DeclarationListParser::next`.
- WithoutBlock(R),
+ /// The value is the representation of all data of the rule which would be
+ /// handled in rule_without_block.
+ WithoutBlock(P),
/// The at-rule is expected to have a a `{ /* ... */ }` block. Example: `@media`
///
/// The value is the representation of the "prelude" part of the rule.
- WithBlock(P),
-
- /// The at-rule may either have a block or end with a semicolon.
- ///
- /// This is mostly for testing. As of this writing no real CSS at-rule behaves like this.
- ///
- /// The value is the representation of the "prelude" part of the rule.
- OptionalBlock(P),
+ WithBlock(PB),
}
/// A trait to provide various parsing of declaration values.
@@ -85,8 +78,11 @@ pub trait DeclarationParser<'i> {
/// so that `impl AtRuleParser<(), ()> for ... {}` can be used
/// for using `DeclarationListParser` to parse a declartions list with only qualified rules.
pub trait AtRuleParser<'i> {
- /// The intermediate representation of an at-rule prelude.
- type Prelude;
+ /// The intermediate representation of prelude of an at-rule without block;
+ type PreludeNoBlock;
+
+ /// The intermediate representation of prelude of an at-rule with block;
+ type PreludeBlock;
/// The finished representation of an at-rule.
type AtRule;
@@ -112,36 +108,39 @@ pub trait AtRuleParser<'i> {
/// that ends wherever the prelude should end.
/// (Before the next semicolon, the next `{`, or the end of the current block.)
fn parse_prelude<'t>(&mut self, name: CowRcStr<'i>, input: &mut Parser<'i, 't>)
- -> Result