Truncate keywords (some of them probably shouldn't be keywords)

This commit is contained in:
ConnorSkees 2020-01-26 12:34:04 -05:00
parent 7e5214d629
commit 8756adaaaf
2 changed files with 43 additions and 40 deletions

View File

@ -215,38 +215,38 @@ impl Display for Op {
#[derive(Copy, Clone, Debug, Eq, PartialEq)] #[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum Keyword { pub enum Keyword {
Important, Important,
Infinity,
NaN,
Auto,
Inherit,
Initial,
Unset,
True, True,
False, False,
Not,
And,
Or,
Null, Null,
In, // Infinity,
// NaN,
// Auto,
// Inherit,
// Initial,
// Unset,
// Not,
// And,
// Or,
// In,
} }
impl Display for Keyword { impl Display for Keyword {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
Self::Important => write!(f, "!important"), Self::Important => write!(f, "!important"),
Self::Infinity => write!(f, "Infinity"),
Self::NaN => write!(f, "NaN"),
Self::Auto => write!(f, "auto"),
Self::Inherit => write!(f, "inherit"),
Self::Initial => write!(f, "initial"),
Self::Unset => write!(f, "unset"),
Self::True => write!(f, "true"), Self::True => write!(f, "true"),
Self::False => write!(f, "false"), Self::False => write!(f, "false"),
Self::Not => write!(f, "not"),
Self::And => write!(f, "and"),
Self::Or => write!(f, "or"),
Self::Null => write!(f, "null"), Self::Null => write!(f, "null"),
Self::In => write!(f, "in"), // Self::Infinity => write!(f, "Infinity"),
// Self::NaN => write!(f, "NaN"),
// Self::Auto => write!(f, "auto"),
// Self::Inherit => write!(f, "inherit"),
// Self::Initial => write!(f, "initial"),
// Self::Unset => write!(f, "unset"),
// Self::Not => write!(f, "not"),
// Self::And => write!(f, "and"),
// Self::Or => write!(f, "or"),
// Self::In => write!(f, "in"),
} }
} }
} }
@ -255,19 +255,19 @@ impl Into<&'static str> for Keyword {
fn into(self) -> &'static str { fn into(self) -> &'static str {
match self { match self {
Self::Important => "!important", Self::Important => "!important",
Self::Infinity => "Infinity",
Self::NaN => "NaN",
Self::Auto => "auto",
Self::Inherit => "inherit",
Self::Initial => "initial",
Self::Unset => "unset",
Self::True => "true", Self::True => "true",
Self::False => "false", Self::False => "false",
Self::Not => "not",
Self::And => "and",
Self::Or => "or",
Self::Null => "null", Self::Null => "null",
Self::In => "in", // Self::Infinity => "Infinity",
// Self::NaN => "NaN",
// Self::Auto => "auto",
// Self::Inherit => "inherit",
// Self::Initial => "initial",
// Self::Unset => "unset",
// Self::Not => "not",
// Self::And => "and",
// Self::Or => "or",
// Self::In => "in",
} }
} }
} }
@ -279,19 +279,19 @@ impl TryFrom<&str> for Keyword {
// todo: case insensitive? // todo: case insensitive?
match kw { match kw {
"important" => Ok(Self::Important), "important" => Ok(Self::Important),
"infinity" => Ok(Self::Infinity),
"nan" => Ok(Self::NaN),
"auto" => Ok(Self::Auto),
"inherit" => Ok(Self::Inherit),
"initial" => Ok(Self::Initial),
"unset" => Ok(Self::Unset),
"true" => Ok(Self::True), "true" => Ok(Self::True),
"false" => Ok(Self::False), "false" => Ok(Self::False),
"not" => Ok(Self::Not),
"and" => Ok(Self::And),
"or" => Ok(Self::Or),
"null" => Ok(Self::Null), "null" => Ok(Self::Null),
"in" => Ok(Self::In), // "infinity" => Ok(Self::Infinity),
// "nan" => Ok(Self::NaN),
// "auto" => Ok(Self::Auto),
// "inherit" => Ok(Self::Inherit),
// "initial" => Ok(Self::Initial),
// "unset" => Ok(Self::Unset),
// "not" => Ok(Self::Not),
// "and" => Ok(Self::And),
// "or" => Ok(Self::Or),
// "in" => Ok(Self::In),
_ => Err("invalid keyword"), _ => Err("invalid keyword"),
} }
} }

View File

@ -653,6 +653,9 @@ mod test_values {
test!(comma_list_number, "a {\n color: 1, 2, 3;\n}\n"); test!(comma_list_number, "a {\n color: 1, 2, 3;\n}\n");
test!(space_list_number, "a {\n color: 1 2 3;\n}\n"); test!(space_list_number, "a {\n color: 1 2 3;\n}\n");
test!(comma_space_list_number, "a {\n color: 1 1, 2 2, 3 3;\n}\n"); test!(comma_space_list_number, "a {\n color: 1 1, 2 2, 3 3;\n}\n");
test!(preserves_keyword_true, "a {\n color: true;\n}\n");
test!(preserves_keyword_false, "a {\n color: false;\n}\n");
test!(preserves_keyword_null, "a {\n color: null;\n}\n");
test!( test!(
whitespace_space_list_number, whitespace_space_list_number,
"a {\n color: 1 2 3 ;\n}\n", "a {\n color: 1 2 3 ;\n}\n",