diff --git a/src/atrule.rs b/src/atrule.rs index 72a4f43..006a9b1 100644 --- a/src/atrule.rs +++ b/src/atrule.rs @@ -121,7 +121,7 @@ impl AtRule { devour_whitespace_or_comment(toks); if let Some(tok) = toks.next() { match tok.kind { - TokenKind::Keyword(Keyword::From) => {} + TokenKind::Keyword(Keyword::From(..)) => {} _ => return Err("Expected \"from\".".into()), } } else { @@ -132,11 +132,11 @@ impl AtRule { let mut through = 0; while let Some(tok) = toks.next() { match tok.kind { - TokenKind::Keyword(Keyword::Through) => { + TokenKind::Keyword(Keyword::Through(..)) => { through = 1; break; } - TokenKind::Keyword(Keyword::To) => break, + TokenKind::Keyword(Keyword::To(..)) => break, _ => from_toks.push(tok), } } diff --git a/src/common.rs b/src/common.rs index 4239711..9132e43 100644 --- a/src/common.rs +++ b/src/common.rs @@ -213,16 +213,16 @@ impl Display for Op { } } -#[derive(Copy, Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Debug, Eq, PartialEq)] pub enum Keyword { Important, True, False, Null, Default, - From, - To, - Through, + From(String), + To(String), + Through(String), // Infinity, // NaN, // Auto, @@ -244,9 +244,9 @@ impl Display for Keyword { Self::Null => write!(f, "null"), Self::Default => write!(f, "!default"), // todo!(maintain casing for keywords) - Self::From => write!(f, "from"), - Self::To => write!(f, "to"), - Self::Through => write!(f, "through"), + Self::From(s) => write!(f, "{}", s), + Self::To(s) => write!(f, "{}", s), + Self::Through(s) => write!(f, "{}", s), // Self::Infinity => write!(f, "Infinity"), // Self::NaN => write!(f, "NaN"), // Self::Auto => write!(f, "auto"), @@ -269,9 +269,9 @@ impl Into<&'static str> for Keyword { Self::False => "false", Self::Null => "null", Self::Default => "!default", - Self::From => "from", - Self::To => "to", - Self::Through => "through", + Self::From(_) => "from", + Self::To(_) => "to", + Self::Through(_) => "through", // Self::Infinity => "Infinity", // Self::NaN => "NaN", // Self::Auto => "auto", @@ -296,9 +296,9 @@ impl TryFrom<&str> for Keyword { "false" => Ok(Self::False), "null" => Ok(Self::Null), "default" => Ok(Self::Default), - "from" => Ok(Self::From), - "to" => Ok(Self::To), - "through" => Ok(Self::Through), + "from" => Ok(Self::From(kw.to_owned())), + "to" => Ok(Self::To(kw.to_owned())), + "through" => Ok(Self::Through(kw.to_owned())), // "infinity" => Ok(Self::Infinity), // "nan" => Ok(Self::NaN), // "auto" => Ok(Self::Auto), diff --git a/src/value/parse.rs b/src/value/parse.rs index ea56084..0f7e104 100644 --- a/src/value/parse.rs +++ b/src/value/parse.rs @@ -314,6 +314,9 @@ impl Value { TokenKind::Keyword(Keyword::True) => Ok(Value::True), TokenKind::Keyword(Keyword::False) => Ok(Value::False), TokenKind::Keyword(Keyword::Null) => Ok(Value::Null), + TokenKind::Keyword(Keyword::From(s)) => Ok(Value::Ident(s, QuoteKind::None)), + TokenKind::Keyword(Keyword::Through(s)) => Ok(Value::Ident(s, QuoteKind::None)), + TokenKind::Keyword(Keyword::To(s)) => Ok(Value::Ident(s, QuoteKind::None)), TokenKind::Unknown(c) => Ok(Value::Ident(c.to_string(), QuoteKind::None)), _ => Err("Unexpected token in value parsing".into()), } diff --git a/tests/values.rs b/tests/values.rs index 8a0f0bd..c991ae7 100644 --- a/tests/values.rs +++ b/tests/values.rs @@ -29,6 +29,9 @@ test!(preserves_keyword_and, "a {\n color: and;\n}\n"); test!(preserves_keyword_or, "a {\n color: or;\n}\n"); test!(preserves_keyword_unset, "a {\n color: unset;\n}\n"); test!(preserves_keyword_nan, "a {\n color: NaN;\n}\n"); +test!(preserves_keyword_from, "a {\n color: FRoM;\n}\n"); +test!(preserves_keyword_to, "a {\n color: To;\n}\n"); +test!(preserves_keyword_through, "a {\n color: ThRouGh;\n}\n"); test!( preserves_quotes, "a {\n color: \"'foo' \\\"bar\\\"\";\n}\n"