@@ -150,6 +150,7 @@ impl Color {
150150 /// FIXME(#2) Deprecated CSS2 System Colors are not supported yet.
151151 pub fn parse < ' i , ' t > ( input : & mut Parser < ' i , ' t > ) -> Result < Color , BasicParseError < ' i > > {
152152 // FIXME: remove clone() when lifetimes are non-lexical
153+ let location = input. current_source_location ( ) ;
153154 let token = input. next ( ) ?. clone ( ) ;
154155 match token {
155156 Token :: Hash ( ref value) | Token :: IDHash ( ref value) => {
@@ -158,12 +159,11 @@ impl Color {
158159 Token :: Ident ( ref value) => parse_color_keyword ( & * value) ,
159160 Token :: Function ( ref name) => {
160161 return input. parse_nested_block ( |arguments| {
161- parse_color_function ( & * name, arguments)
162- . map_err ( |e| ParseError :: Basic ( e) )
162+ parse_color_function ( & * name, arguments) . map_err ( |e| e. into ( ) )
163163 } ) . map_err ( ParseError :: < ( ) > :: basic) ;
164164 }
165165 _ => Err ( ( ) )
166- } . map_err ( |( ) | BasicParseError :: UnexpectedToken ( token) )
166+ } . map_err ( |( ) | location . new_basic_unexpected_token_error ( token) )
167167 }
168168
169169 /// Parse a color hash, without the leading '#' character.
@@ -424,7 +424,7 @@ fn parse_color_function<'i, 't>(name: &str, arguments: &mut Parser<'i, 't>) -> R
424424 let ( red, green, blue, uses_commas) = match_ignore_ascii_case ! { name,
425425 "rgb" | "rgba" => parse_rgb_components_rgb( arguments) ?,
426426 "hsl" | "hsla" => parse_rgb_components_hsl( arguments) ?,
427- _ => return Err ( BasicParseError :: UnexpectedToken ( Token :: Ident ( name. to_owned( ) . into( ) ) ) ) ,
427+ _ => return Err ( arguments . new_basic_unexpected_token_error ( Token :: Ident ( name. to_owned( ) . into( ) ) ) ) ,
428428 } ;
429429
430430 let alpha = if !arguments. is_exhausted ( ) {
@@ -433,6 +433,7 @@ fn parse_color_function<'i, 't>(name: &str, arguments: &mut Parser<'i, 't>) -> R
433433 } else {
434434 arguments. expect_delim ( '/' ) ?;
435435 } ;
436+ let location = arguments. current_source_location ( ) ;
436437 match * arguments. next ( ) ? {
437438 Token :: Number { value : v, .. } => {
438439 clamp_unit_f32 ( v)
@@ -441,7 +442,7 @@ fn parse_color_function<'i, 't>(name: &str, arguments: &mut Parser<'i, 't>) -> R
441442 clamp_unit_f32 ( v)
442443 }
443444 ref t => {
444- return Err ( BasicParseError :: UnexpectedToken ( t. clone ( ) ) )
445+ return Err ( location . new_basic_unexpected_token_error ( t. clone ( ) ) )
445446 }
446447 }
447448 } else {
@@ -462,6 +463,8 @@ fn parse_rgb_components_rgb<'i, 't>(arguments: &mut Parser<'i, 't>) -> Result<(u
462463
463464 // Either integers or percentages, but all the same type.
464465 // https://drafts.csswg.org/css-color/#rgb-functions
466+ // FIXME: remove .clone() when lifetimes are non-lexical.
467+ let location = arguments. current_source_location ( ) ;
465468 match arguments. next ( ) ?. clone ( ) {
466469 Token :: Number { value : v, .. } => {
467470 red = clamp_floor_256_f32 ( v) ;
@@ -471,7 +474,7 @@ fn parse_rgb_components_rgb<'i, 't>(arguments: &mut Parser<'i, 't>) -> Result<(u
471474 uses_commas = true ;
472475 arguments. expect_number ( ) ?
473476 }
474- t => return Err ( BasicParseError :: UnexpectedToken ( t) )
477+ t => return Err ( location . new_basic_unexpected_token_error ( t) )
475478 } ) ;
476479 if uses_commas {
477480 arguments. expect_comma ( ) ?;
@@ -486,14 +489,14 @@ fn parse_rgb_components_rgb<'i, 't>(arguments: &mut Parser<'i, 't>) -> Result<(u
486489 uses_commas = true ;
487490 arguments. expect_percentage ( ) ?
488491 }
489- t => return Err ( BasicParseError :: UnexpectedToken ( t) )
492+ t => return Err ( location . new_basic_unexpected_token_error ( t) )
490493 } ) ;
491494 if uses_commas {
492495 arguments. expect_comma ( ) ?;
493496 }
494497 blue = clamp_unit_f32 ( arguments. expect_percentage ( ) ?) ;
495498 }
496- t => return Err ( BasicParseError :: UnexpectedToken ( t) )
499+ t => return Err ( location . new_basic_unexpected_token_error ( t) )
497500 } ;
498501 return Ok ( ( red, green, blue, uses_commas) ) ;
499502}
@@ -503,6 +506,7 @@ fn parse_rgb_components_hsl<'i, 't>(arguments: &mut Parser<'i, 't>) -> Result<(u
503506 let mut uses_commas = false ;
504507 // Hue given as an angle
505508 // https://drafts.csswg.org/css-values/#angles
509+ let location = arguments. current_source_location ( ) ;
506510 let hue_degrees = match * arguments. next ( ) ? {
507511 Token :: Number { value : v, .. } => v,
508512 Token :: Dimension { value : v, ref unit, .. } => {
@@ -511,24 +515,25 @@ fn parse_rgb_components_hsl<'i, 't>(arguments: &mut Parser<'i, 't>) -> Result<(u
511515 "grad" => v * 360. / 400. ,
512516 "rad" => v * 360. / ( 2. * PI ) ,
513517 "turn" => v * 360. ,
514- _ => return Err ( BasicParseError :: UnexpectedToken ( Token :: Ident ( unit. clone( ) ) ) ) ,
518+ _ => return Err ( location . new_basic_unexpected_token_error ( Token :: Ident ( unit. clone( ) ) ) ) ,
515519 }
516520 }
517- ref t => return Err ( BasicParseError :: UnexpectedToken ( t. clone ( ) ) )
521+ ref t => return Err ( location . new_basic_unexpected_token_error ( t. clone ( ) ) )
518522 } ;
519523 // Subtract an integer before rounding, to avoid some rounding errors:
520524 let hue_normalized_degrees = hue_degrees - 360. * ( hue_degrees / 360. ) . floor ( ) ;
521525 let hue = hue_normalized_degrees / 360. ;
522526
523527 // Saturation and lightness are clamped to 0% ... 100%
524528 // https://drafts.csswg.org/css-color/#the-hsl-notation
529+ let location = arguments. current_source_location ( ) ;
525530 let saturation = match arguments. next ( ) ?. clone ( ) {
526531 Token :: Percentage { unit_value, .. } => unit_value,
527532 Token :: Comma => {
528533 uses_commas = true ;
529534 arguments. expect_percentage ( ) ?
530535 }
531- t => return Err ( BasicParseError :: UnexpectedToken ( t) )
536+ t => return Err ( location . new_basic_unexpected_token_error ( t) )
532537 } ;
533538 let saturation = saturation. max ( 0. ) . min ( 1. ) ;
534539
0 commit comments