@@ -2,97 +2,111 @@ macro_rules! enum_property {
22 (
33 $( #[ $outer: meta] ) *
44 $vis: vis enum $name: ident {
5- $( $x: ident, ) +
5+ $(
6+ $( #[ $meta: meta] ) *
7+ $x: ident,
8+ ) +
69 }
710 ) => {
811 $( #[ $outer] ) *
912 #[ derive( Debug , Clone , Copy , PartialEq ) ]
1013 $vis enum $name {
1114 $(
15+ $( #[ $meta] ) *
1216 $x,
1317 ) +
1418 }
1519
1620 impl <' i> Parse <' i> for $name {
1721 fn parse<' t>( input: & mut Parser <' i, ' t>) -> Result <Self , ParseError <' i, ParserError <' i>>> {
22+ let location = input. current_source_location( ) ;
1823 let ident = input. expect_ident( ) ?;
1924 match & ident[ ..] {
2025 $(
2126 s if s. eq_ignore_ascii_case( stringify!( $x) ) => Ok ( $name:: $x) ,
2227 ) +
23- _ => return Err ( input. new_error( BasicParseErrorKind :: QualifiedRuleInvalid ) )
28+ _ => Err ( location. new_unexpected_token_error(
29+ cssparser:: Token :: Ident ( ident. clone( ) )
30+ ) )
2431 }
2532 }
26- }
2733
28- impl ToCss for $name {
29- fn to_css<W >( & self , dest: & mut Printer <W >) -> Result <( ) , PrinterError > where W : std:: fmt:: Write {
30- use $name:: * ;
31- match self {
34+ fn parse_string( input: & ' i str ) -> Result <Self , ParseError <' i, ParserError <' i>>> {
35+ match input {
3236 $(
33- $x => dest . write_str ( & stringify!( $x) . to_lowercase ( ) ) ,
37+ s if s . eq_ignore_ascii_case ( stringify!( $x) ) => Ok ( $name :: $x ) ,
3438 ) +
39+ _ => return Err ( ParseError {
40+ kind: ParseErrorKind :: Basic ( BasicParseErrorKind :: UnexpectedToken ( cssparser:: Token :: Ident ( input. into( ) ) ) ) ,
41+ location: cssparser:: SourceLocation { line: 0 , column: 1 }
42+ } )
3543 }
3644 }
3745 }
3846
39- impl $name {
40- # [ allow ( dead_code ) ]
41- pub fn from_str ( s : & str ) -> Option < Self > {
42- match s {
47+ impl ToCss for $name {
48+ fn to_css< W > ( & self , dest : & mut Printer < W > ) -> Result < ( ) , PrinterError > where W : std :: fmt :: Write {
49+ use $name :: * ;
50+ match self {
4351 $(
44- s if s . eq_ignore_ascii_case ( stringify!( $x) ) => Some ( $name :: $x ) ,
52+ $x => dest . write_str ( & stringify!( $x) . to_lowercase ( ) ) ,
4553 ) +
46- _ => None
4754 }
4855 }
4956 }
5057 } ;
5158 (
5259 $( #[ $outer: meta] ) *
5360 $vis: vis enum $name: ident {
54- $( $str: literal: $id: ident, ) +
61+ $(
62+ $( #[ $meta: meta] ) *
63+ $str: literal: $id: ident,
64+ ) +
5565 }
5666 ) => {
5767 $( #[ $outer] ) *
5868 #[ derive( Debug , Clone , Copy , PartialEq ) ]
5969 $vis enum $name {
6070 $(
71+ $( #[ $meta] ) *
6172 $id,
6273 ) +
6374 }
6475
6576 impl <' i> Parse <' i> for $name {
6677 fn parse<' t>( input: & mut Parser <' i, ' t>) -> Result <Self , ParseError <' i, ParserError <' i>>> {
78+ let location = input. current_source_location( ) ;
6779 let ident = input. expect_ident( ) ?;
6880 match & ident[ ..] {
6981 $(
7082 s if s. eq_ignore_ascii_case( $str) => Ok ( $name:: $id) ,
7183 ) +
72- _ => return Err ( input. new_error( BasicParseErrorKind :: QualifiedRuleInvalid ) )
84+ _ => Err ( location. new_unexpected_token_error(
85+ cssparser:: Token :: Ident ( ident. clone( ) )
86+ ) )
7387 }
7488 }
75- }
7689
77- impl ToCss for $name {
78- fn to_css<W >( & self , dest: & mut Printer <W >) -> Result <( ) , PrinterError > where W : std:: fmt:: Write {
79- use $name:: * ;
80- match self {
90+ fn parse_string( input: & ' i str ) -> Result <Self , ParseError <' i, ParserError <' i>>> {
91+ match input {
8192 $(
82- $id => dest . write_str ( $str ) ,
93+ s if s . eq_ignore_ascii_case ( $str ) => Ok ( $name :: $id ) ,
8394 ) +
95+ _ => return Err ( ParseError {
96+ kind: ParseErrorKind :: Basic ( BasicParseErrorKind :: UnexpectedToken ( cssparser:: Token :: Ident ( input. into( ) ) ) ) ,
97+ location: cssparser:: SourceLocation { line: 0 , column: 1 }
98+ } )
8499 }
85100 }
86101 }
87102
88- impl $name {
89- # [ allow ( dead_code ) ]
90- pub fn from_str ( s : & str ) -> Option < Self > {
91- match s {
103+ impl ToCss for $name {
104+ fn to_css< W > ( & self , dest : & mut Printer < W > ) -> Result < ( ) , PrinterError > where W : std :: fmt :: Write {
105+ use $name :: * ;
106+ match self {
92107 $(
93- s if s . eq_ignore_ascii_case ( $str ) => Some ( $name :: $id ) ,
108+ $id => dest . write_str ( $str ) ,
94109 ) +
95- _ => None
96110 }
97111 }
98112 }
0 commit comments