diff --git a/examples/src/starter-project/src/lib.pax b/examples/src/starter-project/src/lib.pax index 75901dee5..c3190e6fa 100644 --- a/examples/src/starter-project/src/lib.pax +++ b/examples/src/starter-project/src/lib.pax @@ -1,3 +1,208 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @settings { @pre_render: handle_pre_render #text { diff --git a/pax-lang/src/deserializer/helpers.rs b/pax-lang/src/deserializer/helpers.rs index 0a2a072a0..72ba323ac 100644 --- a/pax-lang/src/deserializer/helpers.rs +++ b/pax-lang/src/deserializer/helpers.rs @@ -173,27 +173,25 @@ impl<'de> VariantAccess<'de> for PaxEnum<'de> { T: DeserializeSeed<'de>, { let ast = self.args.unwrap(); - eprintln!("AST: {:?}: {:?}", ast.to_string(), ast.as_str()); - seed.deserialize(PaxDeserializer::from(ast)) - } - - fn tuple_variant(self, _len: usize, visitor: V) -> Result - where - V: Visitor<'de>, - { if self.is_pax_value && self.variant == "Enum" { - let mut enum_pairs = self.args.unwrap().into_inner(); + let mut enum_pairs = ast.into_inner(); while enum_pairs.len() > 3 { enum_pairs.next(); } if enum_pairs.len() == 2 { let name = enum_pairs.next().unwrap().as_str(); let variant = enum_pairs.next().unwrap().as_str(); - return visitor.visit_seq(UnitVariant::new(name, variant)); + return seed.deserialize(UnitVariant::new(name, variant)); } - return visitor.visit_seq(PaxSeq::new(enum_pairs)); + return seed.deserialize(PaxSeq::new(enum_pairs)); } + seed.deserialize(PaxDeserializer::from(ast)) + } + fn tuple_variant(self, _len: usize, visitor: V) -> Result + where + V: Visitor<'de>, + { if let Some(args) = self.args { visitor.visit_seq(PaxSeq::new(args.into_inner())) } else { @@ -216,6 +214,23 @@ pub struct PaxSeq<'de> { index: usize, } +impl<'de> Deserializer<'de> for PaxSeq<'de> { + type Error = Error; + + fn deserialize_any(self, visitor: V) -> std::result::Result + where + V: Visitor<'de>, + { + visitor.visit_seq(self) + } + + forward_to_deserialize_any! { + bool i8 i16 i32 i64 i128 u8 u16 u32 u64 u128 f32 f64 char str string + bytes byte_buf option unit unit_struct newtype_struct seq tuple identifier + tuple_struct map struct enum ignored_any + } +} + impl<'de> PaxSeq<'de> { pub fn new(elements: Pairs<'de, Rule>) -> Self { PaxSeq { elements, index: 0 } @@ -447,6 +462,23 @@ impl<'de> UnitVariant<'de> { } } +impl<'de> Deserializer<'de> for UnitVariant<'de> { + type Error = Error; + + forward_to_deserialize_any! { + bool i8 i16 i32 i64 i128 u8 u16 u32 u64 u128 f32 f64 char str string + bytes byte_buf option unit unit_struct newtype_struct seq tuple identifier + tuple_struct map struct enum ignored_any + } + + fn deserialize_any(self, visitor: V) -> std::result::Result + where + V: Visitor<'de>, + { + visitor.visit_seq(self) + } +} + impl<'de> SeqAccess<'de> for UnitVariant<'de> { type Error = Error;