[librsvg: 26/51] parse_identifiers! - new macro for parsing symbol lists from attributes
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 26/51] parse_identifiers! - new macro for parsing symbol lists from attributes
- Date: Thu, 19 Dec 2019 01:50:12 +0000 (UTC)
commit 4f5212b369e41efe323fa79303994c0db95ee31c
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Dec 17 19:34:43 2019 -0600
parse_identifiers! - new macro for parsing symbol lists from attributes
rsvg_internals/src/lib.rs | 4 +++-
rsvg_internals/src/parsers.rs | 27 +++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 1 deletion(-)
---
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index 7b2bd688..e888009f 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -72,6 +72,9 @@ mod coord_units;
#[macro_use]
mod float_eq_cairo;
+#[macro_use]
+mod parsers;
+
#[macro_use]
mod property_macros;
@@ -105,7 +108,6 @@ mod mask;
mod node;
mod number_list;
mod paint_server;
-mod parsers;
mod path_builder;
mod path_parser;
mod pattern;
diff --git a/rsvg_internals/src/parsers.rs b/rsvg_internals/src/parsers.rs
index 3d5b4605..9a6bd17b 100644
--- a/rsvg_internals/src/parsers.rs
+++ b/rsvg_internals/src/parsers.rs
@@ -171,6 +171,33 @@ pub fn integer_optional_integer(s: &str) -> Result<(i32, i32), ValueErrorKind> {
}
}
+/// Parses a list of identifiers from a `cssparser::Parser`
+///
+/// # Example
+///
+/// ```ignore
+/// let my_boolean = parse_identifiers!(
+/// parser,
+/// "true" => true,
+/// "false" => false,
+/// )?;
+/// ```
+macro_rules! parse_identifiers {
+ ($parser:expr,
+ $($str:expr => $val:expr,)+) => {
+ {
+ let loc = $parser.current_source_location();
+ let token = $parser.next()?;
+
+ match token {
+ $(cssparser::Token::Ident(ref cow) if cow.eq_ignore_ascii_case($str) => Ok($val),)+
+
+ _ => Err(loc.new_unexpected_token_error(token.clone()))
+ }
+ }
+ };
+}
+
#[cfg(test)]
mod tests {
use super::*;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]