[librsvg: 15/17] DeclParser: Basic implentation of cssparser::DeclarationParser



commit d06abc5fb6c989dbaff7e59ce60b04492e6a7b3b
Author: Federico Mena Quintero <federico gnome org>
Date:   Thu May 2 20:15:05 2019 -0500

    DeclParser: Basic implentation of cssparser::DeclarationParser

 rsvg_internals/src/properties.rs | 37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)
---
diff --git a/rsvg_internals/src/properties.rs b/rsvg_internals/src/properties.rs
index 1e418376..fed01997 100644
--- a/rsvg_internals/src/properties.rs
+++ b/rsvg_internals/src/properties.rs
@@ -1,4 +1,4 @@
-use cssparser::{self, Parser, ParserInput, Token};
+use cssparser::{self, parse_important, AtRuleParser, CowRcStr, DeclarationParser, Parser, ParserInput, 
Token};
 use std::collections::HashSet;
 use std::str::FromStr;
 
@@ -674,6 +674,41 @@ impl SpecifiedValues {
     }
 }
 
+struct DeclParser;
+
+impl<'i> DeclarationParser<'i> for DeclParser {
+    type Declaration = Declaration;
+    type Error = ValueErrorKind;
+
+    fn parse_value<'t>(
+        &mut self,
+        name: CowRcStr<'i>,
+        input: &mut Parser<'i, 't>,
+    ) -> Result<Declaration, cssparser::ParseError<'i, ValueErrorKind>> {
+        if let Ok(attribute) = Attribute::from_str(name.as_ref()) {
+            let property = parse_attribute_value_into_parsed_property(attribute, input, true)
+                .map_err(|e| input.new_custom_error(e))?;
+
+            let important = input.try_parse(parse_important).is_ok();
+
+            Ok(Declaration {
+                attribute,
+                property,
+                important,
+            })
+        } else {
+            Err(input.new_custom_error(ValueErrorKind::UnknownProperty))
+        }
+    }
+}
+
+impl<'i> AtRuleParser<'i> for DeclParser {
+    type PreludeNoBlock = ();
+    type PreludeBlock = ();
+    type AtRule = ();
+    type Error = ();
+}
+
 // Parses the value for the type `T` of the property out of the Parser, including `inherit` values.
 pub fn parse_input<T>(input: &mut Parser) -> Result<SpecifiedValue<T>, <T as Parse>::Err>
 where


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