From 2af15de5b72c79f6a6270b9a2a92ba181d33fdb9 Mon Sep 17 00:00:00 2001 From: Chris Hennick Date: Fri, 27 Oct 2023 15:34:08 -0700 Subject: [PATCH] Fix a bug parsing files with ! operator --- src/parser/intrinsics/mod.rs | 10 +++++++--- src/parser/resource/mod.rs | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/parser/intrinsics/mod.rs b/src/parser/intrinsics/mod.rs index 0d500f80..5d5fbfe9 100644 --- a/src/parser/intrinsics/mod.rs +++ b/src/parser/intrinsics/mod.rs @@ -68,7 +68,7 @@ static INTRINSIC_FUNCTION_TAGS: &[&str] = &[ ]; impl IntrinsicFunction { - pub(super) fn from_enum<'de, A: serde::de::EnumAccess<'de>>(data: A) -> Result { + pub(super) fn from_enum<'de, A: serde::de::EnumAccess<'de>>(data: A) -> Result { let (tag, data): (String, _) = data.variant()?; Ok(match tag.as_str() { @@ -124,8 +124,12 @@ impl IntrinsicFunction { Self::Sub { string, replaces } } "Ref" => Self::Ref(data.newtype_variant()?), - unknown => return Err(A::Error::unknown_variant(unknown, INTRINSIC_FUNCTION_TAGS)), - }) + "!" => return Ok(data.newtype_variant()?), + unknown => { + eprintln!("Failed to parse ({}, {})", tag, data.newtype_variant::()?); + return Err(A::Error::unknown_variant(unknown, INTRINSIC_FUNCTION_TAGS)) + }, + }.into()) } pub(super) fn from_singleton_map<'de, A: serde::de::MapAccess<'de>>( diff --git a/src/parser/resource/mod.rs b/src/parser/resource/mod.rs index 2f512b79..c6587508 100644 --- a/src/parser/resource/mod.rs +++ b/src/parser/resource/mod.rs @@ -52,7 +52,7 @@ impl<'de> serde::de::Deserialize<'de> for ResourceValue { self, data: A, ) -> Result { - IntrinsicFunction::from_enum(data).map(Into::into) + IntrinsicFunction::from_enum(data) } #[inline]