@@ -23,24 +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 ) ,
37
-
38
- /// The at-rule may either have a block or end with a semicolon.
39
- ///
40
- /// This is mostly for testing. As of this writing no real CSS at-rule behaves like this.
41
- ///
42
- /// The value is the representation of the "prelude" part of the rule.
43
- OptionalBlock ( P ) ,
36
+ WithBlock ( PB ) ,
44
37
}
45
38
46
39
/// A trait to provide various parsing of declaration values.
@@ -85,8 +78,11 @@ pub trait DeclarationParser<'i> {
85
78
/// so that `impl AtRuleParser<(), ()> for ... {}` can be used
86
79
/// for using `DeclarationListParser` to parse a declartions list with only qualified rules.
87
80
pub trait AtRuleParser < ' i > {
88
- /// The intermediate representation of an at-rule prelude.
89
- 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 ;
90
86
91
87
/// The finished representation of an at-rule.
92
88
type AtRule ;
@@ -112,36 +108,39 @@ pub trait AtRuleParser<'i> {
112
108
/// that ends wherever the prelude should end.
113
109
/// (Before the next semicolon, the next `{`, or the end of the current block.)
114
110
fn parse_prelude < ' t > ( & mut self , name : CowRcStr < ' i > , input : & mut Parser < ' i , ' t > )
115
- -> Result < AtRuleType < Self :: Prelude , Self :: AtRule > , ParseError < ' i , Self :: Error > > {
111
+ -> Result < AtRuleType < Self :: PreludeNoBlock , Self :: PreludeBlock > ,
112
+ ParseError < ' i , Self :: Error > > {
116
113
let _ = name;
117
114
let _ = input;
118
115
Err ( ParseError :: Basic ( BasicParseError :: AtRuleInvalid ( name) ) )
119
116
}
120
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
+
121
130
/// Parse the content of a `{ /* ... */ }` block for the body of the at-rule.
122
131
///
123
132
/// Return the finished representation of the at-rule
124
133
/// as returned by `RuleListParser::next` or `DeclarationListParser::next`,
125
134
/// or `Err(())` to ignore the entire at-rule as invalid.
126
135
///
127
- /// This is only called when `parse_prelude` returned `WithBlock` or `OptionalBlock`,
128
- /// and a block was indeed found following the prelude.
129
- fn parse_block < ' t > ( & mut self , prelude : Self :: Prelude , input : & mut Parser < ' i , ' t > )
136
+ /// This is only called when `parse_prelude` returned `WithBlock`, and a block
137
+ /// was indeed found following the prelude.
138
+ fn parse_block < ' t > ( & mut self , prelude : Self :: PreludeBlock , input : & mut Parser < ' i , ' t > )
130
139
-> Result < Self :: AtRule , ParseError < ' i , Self :: Error > > {
131
140
let _ = prelude;
132
141
let _ = input;
133
142
Err ( ParseError :: Basic ( BasicParseError :: AtRuleBodyInvalid ) )
134
143
}
135
-
136
- /// An `OptionalBlock` prelude was followed by `;`.
137
- ///
138
- /// Convert the prelude into the finished representation of the at-rule
139
- /// as returned by `RuleListParser::next` or `DeclarationListParser::next`.
140
- fn rule_without_block ( & mut self , prelude : Self :: Prelude ) -> Self :: AtRule {
141
- let _ = prelude;
142
- panic ! ( "The `AtRuleParser::rule_without_block` method must be overriden \
143
- if `AtRuleParser::parse_prelude` ever returns `AtRuleType::OptionalBlock`.")
144
- }
145
144
}
146
145
147
146
/// A trait to provide various parsing of qualified rules.
@@ -460,9 +459,9 @@ fn parse_at_rule<'i: 't, 't, P, E>(start: &ParserState, name: CowRcStr<'i>,
460
459
parser. parse_prelude ( name, input)
461
460
} ) ;
462
461
match result {
463
- Ok ( AtRuleType :: WithoutBlock ( rule ) ) => {
462
+ Ok ( AtRuleType :: WithoutBlock ( prelude ) ) => {
464
463
match input. next ( ) {
465
- Ok ( & Token :: Semicolon ) | Err ( _) => Ok ( rule ) ,
464
+ Ok ( & Token :: Semicolon ) | Err ( _) => Ok ( parser . rule_without_block ( prelude ) ) ,
466
465
Ok ( & Token :: CurlyBracketBlock ) => Err ( PreciseParseError {
467
466
error : ParseError :: Basic ( BasicParseError :: UnexpectedToken ( Token :: CurlyBracketBlock ) ) ,
468
467
slice : input. slice_from ( start. position ( ) ) ,
@@ -495,21 +494,6 @@ fn parse_at_rule<'i: 't, 't, P, E>(start: &ParserState, name: CowRcStr<'i>,
495
494
Ok ( _) => unreachable ! ( )
496
495
}
497
496
}
498
- Ok ( AtRuleType :: OptionalBlock ( prelude) ) => {
499
- match input. next ( ) {
500
- Ok ( & Token :: Semicolon ) | Err ( _) => Ok ( parser. rule_without_block ( prelude) ) ,
501
- Ok ( & Token :: CurlyBracketBlock ) => {
502
- // FIXME: https://github.com/rust-lang/rust/issues/42508
503
- parse_nested_block :: < ' i , ' t , _ , _ , _ > ( input, move |input| parser. parse_block ( prelude, input) )
504
- . map_err ( |e| PreciseParseError {
505
- error : e,
506
- slice : input. slice_from ( start. position ( ) ) ,
507
- location : start. source_location ( ) ,
508
- } )
509
- }
510
- _ => unreachable ! ( )
511
- }
512
- }
513
497
Err ( error) => {
514
498
let end_position = input. position ( ) ;
515
499
match input. next ( ) {
0 commit comments