@@ -23,17 +23,17 @@ pub fn parse_important<'i, 't>(input: &mut Parser<'i, 't>) -> Result<(), BasicPa
23
23
/// The return value for `AtRuleParser::parse_prelude`.
24
24
/// Indicates whether the at-rule is expected to have a `{ /* ... */ }` block
25
25
/// or end with a `;` semicolon.
26
- pub enum AtRuleType < P , R > {
26
+ pub enum AtRuleType < P , PB > {
27
27
/// The at-rule is expected to end with a `;` semicolon. Example: `@import`.
28
28
///
29
- /// The value is the finished representation of an at- rule
30
- /// as returned by `RuleListParser::next` or `DeclarationListParser::next` .
31
- WithoutBlock ( R ) ,
29
+ /// The value is the representation of all data of the rule which would be
30
+ /// handled in rule_without_block .
31
+ WithoutBlock ( P ) ,
32
32
33
33
/// The at-rule is expected to have a a `{ /* ... */ }` block. Example: `@media`
34
34
///
35
35
/// The value is the representation of the "prelude" part of the rule.
36
- WithBlock ( P ) ,
36
+ WithBlock ( PB ) ,
37
37
}
38
38
39
39
/// A trait to provide various parsing of declaration values.
@@ -78,8 +78,11 @@ pub trait DeclarationParser<'i> {
78
78
/// so that `impl AtRuleParser<(), ()> for ... {}` can be used
79
79
/// for using `DeclarationListParser` to parse a declartions list with only qualified rules.
80
80
pub trait AtRuleParser < ' i > {
81
- /// The intermediate representation of an at-rule prelude.
82
- type Prelude ;
81
+ /// The intermediate representation of prelude of an at-rule without block;
82
+ type PreludeNoBlock ;
83
+
84
+ /// The intermediate representation of prelude of an at-rule with block;
85
+ type PreludeBlock ;
83
86
84
87
/// The finished representation of an at-rule.
85
88
type AtRule ;
@@ -105,12 +108,25 @@ pub trait AtRuleParser<'i> {
105
108
/// that ends wherever the prelude should end.
106
109
/// (Before the next semicolon, the next `{`, or the end of the current block.)
107
110
fn parse_prelude < ' t > ( & mut self , name : CowRcStr < ' i > , input : & mut Parser < ' i , ' t > )
108
- -> Result < AtRuleType < Self :: Prelude , Self :: AtRule > , ParseError < ' i , Self :: Error > > {
111
+ -> Result < AtRuleType < Self :: PreludeNoBlock , Self :: PreludeBlock > ,
112
+ ParseError < ' i , Self :: Error > > {
109
113
let _ = name;
110
114
let _ = input;
111
115
Err ( ParseError :: Basic ( BasicParseError :: AtRuleInvalid ( name) ) )
112
116
}
113
117
118
+ /// End an at-rule which doesn't have block. Return the finished
119
+ /// representation of the at-rule.
120
+ ///
121
+ /// This is only called when `parse_prelude` returned `WithoutBlock`, and
122
+ /// either the `;` semicolon indeed follows the prelude, or parser is at
123
+ /// the end of the input.
124
+ fn rule_without_block ( & mut self , prelude : Self :: PreludeNoBlock ) -> Self :: AtRule {
125
+ let _ = prelude;
126
+ panic ! ( "The `AtRuleParser::rule_without_block` method must be overriden \
127
+ if `AtRuleParser::parse_prelude` ever returns `AtRuleType::WithoutBlock`.")
128
+ }
129
+
114
130
/// Parse the content of a `{ /* ... */ }` block for the body of the at-rule.
115
131
///
116
132
/// Return the finished representation of the at-rule
@@ -119,7 +135,7 @@ pub trait AtRuleParser<'i> {
119
135
///
120
136
/// This is only called when `parse_prelude` returned `WithBlock`, and a block
121
137
/// was indeed found following the prelude.
122
- fn parse_block < ' t > ( & mut self , prelude : Self :: Prelude , input : & mut Parser < ' i , ' t > )
138
+ fn parse_block < ' t > ( & mut self , prelude : Self :: PreludeBlock , input : & mut Parser < ' i , ' t > )
123
139
-> Result < Self :: AtRule , ParseError < ' i , Self :: Error > > {
124
140
let _ = prelude;
125
141
let _ = input;
@@ -443,9 +459,9 @@ fn parse_at_rule<'i: 't, 't, P, E>(start: &ParserState, name: CowRcStr<'i>,
443
459
parser. parse_prelude ( name, input)
444
460
} ) ;
445
461
match result {
446
- Ok ( AtRuleType :: WithoutBlock ( rule ) ) => {
462
+ Ok ( AtRuleType :: WithoutBlock ( prelude ) ) => {
447
463
match input. next ( ) {
448
- Ok ( & Token :: Semicolon ) | Err ( _) => Ok ( rule ) ,
464
+ Ok ( & Token :: Semicolon ) | Err ( _) => Ok ( parser . rule_without_block ( prelude ) ) ,
449
465
Ok ( & Token :: CurlyBracketBlock ) => Err ( PreciseParseError {
450
466
error : ParseError :: Basic ( BasicParseError :: UnexpectedToken ( Token :: CurlyBracketBlock ) ) ,
451
467
slice : input. slice_from ( start. position ( ) ) ,
0 commit comments