[librsvg: 1/3] Remove the last traces of the ParseError enum with variants



commit c74f4351d976502058f46be4ae3a80c2ad9d85ad
Author: Federico Mena Quintero <federico gnome org>
Date:   Mon Jan 13 17:35:32 2020 -0600

    Remove the last traces of the ParseError enum with variants

 rsvg_internals/src/error.rs      | 17 ----------------
 rsvg_internals/src/properties.rs | 42 +++++++++++++++++++---------------------
 2 files changed, 20 insertions(+), 39 deletions(-)
---
diff --git a/rsvg_internals/src/error.rs b/rsvg_internals/src/error.rs
index 9fdf0bd0..ba7f38fb 100644
--- a/rsvg_internals/src/error.rs
+++ b/rsvg_internals/src/error.rs
@@ -20,23 +20,6 @@ use crate::node::RsvgNode;
 /// purpose.
 pub type CssParseError<'i> = cssparser::ParseError<'i, ValueErrorKind>;
 
-pub enum ParseError<'i> {
-    P(CssParseError<'i>),
-    V(ValueErrorKind),
-}
-
-impl<'i> From<CssParseError<'i>> for ParseError<'i> {
-    fn from(p: CssParseError<'i>) -> ParseError {
-        ParseError::P(p)
-    }
-}
-
-impl<'i> From<ValueErrorKind> for ParseError<'i> {
-    fn from(v: ValueErrorKind) -> ParseError<'i> {
-        ParseError::V(v)
-    }
-}
-
 /// A simple error which refers to an attribute's value
 #[derive(Debug, Clone, PartialEq)]
 pub enum ValueErrorKind {
diff --git a/rsvg_internals/src/properties.rs b/rsvg_internals/src/properties.rs
index fcd75445..6b04d654 100644
--- a/rsvg_internals/src/properties.rs
+++ b/rsvg_internals/src/properties.rs
@@ -227,7 +227,7 @@ pub struct ComputedValues {
 }
 
 #[cfg_attr(rustfmt, rustfmt_skip)]
-pub fn parse_property<'i>(prop_name: &QualName, input: &mut Parser<'i, '_>, accept_shorthands: bool) -> 
Result<ParsedProperty, ParseError<'i>> {
+pub fn parse_property<'i>(prop_name: &QualName, input: &mut Parser<'i, '_>, accept_shorthands: bool) -> 
Result<ParsedProperty, CssParseError<'i>> {
     // please keep these sorted
     match prop_name.expanded() {
         expanded_name!("", "baseline-shift") =>
@@ -300,7 +300,8 @@ pub fn parse_property<'i>(prop_name: &QualName, input: &mut Parser<'i, '_>, acce
             if accept_shorthands {
                 Ok(ParsedProperty::Marker(parse_input(input)?))
             } else {
-                Err(ValueErrorKind::UnknownProperty)?
+                let loc = input.current_source_location();
+                Err(loc.new_custom_error(ValueErrorKind::UnknownProperty))
             }
         }
 
@@ -373,7 +374,10 @@ pub fn parse_property<'i>(prop_name: &QualName, input: &mut Parser<'i, '_>, acce
         expanded_name!("", "writing-mode") =>
             Ok(ParsedProperty::WritingMode(parse_input(input)?)),
 
-        _ => Err(ValueErrorKind::UnknownProperty)?
+        _ => {
+            let loc = input.current_source_location();
+            Err(loc.new_custom_error(ValueErrorKind::UnknownProperty))
+        }
     }
 }
 
@@ -536,25 +540,19 @@ impl SpecifiedValues {
         match parse_property(&attr, &mut parser, false) {
             Ok(prop) => self.set_parsed_property(&prop),
 
-            // not a presentation attribute
-            Err(ParseError::V(ValueErrorKind::UnknownProperty)) => (),
+            // not a presentation attribute; just ignore it
+            Err(CssParseError {
+                kind: ParseErrorKind::Custom(ValueErrorKind::UnknownProperty),
+                ..
+            }) => (),
 
             // https://www.w3.org/TR/CSS2/syndata.html#unsupported-values
             // For all the following cases, ignore illegal values; don't set the whole node to
             // be in error in that case.
-            Err(ParseError::V(v)) => {
-                rsvg_log!(
-                    "(ignoring invalid presentation attribute {:?}\n    value=\"{}\"\n    {})",
-                    attr.expanded(),
-                    value,
-                    v
-                );
-            }
-
-            Err(ParseError::P(CssParseError {
+            Err(CssParseError {
                 kind: ParseErrorKind::Basic(BasicParseErrorKind::UnexpectedToken(ref t)),
                 ..
-            })) => {
+            }) => {
                 let mut tok = String::new();
 
                 t.to_css(&mut tok).unwrap(); // FIXME: what do we do with a fmt::Error?
@@ -567,10 +565,10 @@ impl SpecifiedValues {
                 );
             }
 
-            Err(ParseError::P(CssParseError {
+            Err(CssParseError {
                 kind: ParseErrorKind::Basic(BasicParseErrorKind::EndOfInput),
                 ..
-            })) => {
+            }) => {
                 rsvg_log!(
                     "(ignoring invalid presentation attribute {:?}\n    value=\"{}\"\n    \
                      unexpected end of input)",
@@ -579,10 +577,10 @@ impl SpecifiedValues {
                 );
             }
 
-            Err(ParseError::P(CssParseError {
+            Err(CssParseError {
                 kind: ParseErrorKind::Basic(_),
                 ..
-            })) => {
+            }) => {
                 rsvg_log!(
                     "(ignoring invalid presentation attribute {:?}\n    value=\"{}\"\n    \
                      unexpected error)",
@@ -591,10 +589,10 @@ impl SpecifiedValues {
                 );
             }
 
-            Err(ParseError::P(CssParseError {
+            Err(CssParseError {
                 kind: ParseErrorKind::Custom(ref v),
                 ..
-            })) => {
+            }) => {
                 rsvg_log!(
                     "(ignoring invalid presentation attribute {:?}\n    value=\"{}\"\n    {})",
                     attr.expanded(),


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]